summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-02-03 17:30:13 +0000
committerDries Buytaert <dries@buytaert.net>2009-02-03 17:30:13 +0000
commit607e9626d5af265b18e8319b156bb0fda3445cd4 (patch)
treeece98d14e826d14a711c9b572e3f43a428b9a365 /modules/node
parentd4867346f578906751f8ea0bd799c3fc1bfcbf48 (diff)
downloadbrdo-607e9626d5af265b18e8319b156bb0fda3445cd4.tar.gz
brdo-607e9626d5af265b18e8319b156bb0fda3445cd4.tar.bz2
- Patch #361683by Barry, Yves, Karen, Moshe Weitzman, David Strauss, floriant, chx, David Rothstein: initial field API patch. More work to be done, but ... oh my!
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.module68
-rw-r--r--modules/node/node.pages.inc13
-rw-r--r--modules/node/node.tpl.php1
3 files changed, 79 insertions, 3 deletions
diff --git a/modules/node/node.module b/modules/node/node.module
index afea14b39..e25e86bc9 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -152,6 +152,49 @@ function node_cron() {
}
/**
+ * Implementation of hook_fieldable_info().
+ */
+function node_fieldable_info() {
+ $return = array(
+ 'node' => array(
+ 'name' => t('Node'),
+ 'id key' => 'nid',
+ 'revision key' => 'vid',
+ 'bundle key' => 'type',
+ // Node.module handles its own caching.
+ // 'cacheable' => FALSE,
+ // Bundles must provide human readable name so
+ // we can create help and error messages about them.
+ 'bundles' => node_get_types('names'),
+ ),
+ );
+ return $return;
+}
+
+
+/**
+ * Implementation of hook_field_build_modes().
+ */
+function node_field_build_modes($obj_type) {
+ $modes = array();
+ if ($obj_type == 'node') {
+ $modes = array(
+ 'teaser' => t('Teaser'),
+ 'full' => t('Full node'),
+ NODE_BUILD_RSS => t('RSS'),
+ NODE_BUILD_PRINT => t('Print'),
+ );
+ if (module_exists('search')) {
+ $modes += array(
+ NODE_BUILD_SEARCH_INDEX => t('Search Index'),
+ NODE_BUILD_SEARCH_RESULT => t('Search Result'),
+ );
+ }
+ }
+ return $modes;
+}
+
+/**
* Gather a listing of links to nodes.
*
* @param $result
@@ -537,6 +580,9 @@ function node_type_save($info) {
if ($is_existing) {
db_update('node_type')->fields($fields)->condition('type', $existing_type)->execute();
+ if (!empty($type->old_type) && $type->old_type != $type->type) {
+ field_attach_rename_bundle($type->old_type, $type->type);
+ }
module_invoke_all('node_type', 'update', $type);
return SAVED_UPDATED;
}
@@ -544,6 +590,8 @@ function node_type_save($info) {
$fields['orig_type'] = (string) $type->orig_type;
db_insert('node_type')->fields($fields)->execute();
+ field_attach_create_bundle($type->type);
+
module_invoke_all('node_type', 'insert', $type);
return SAVED_NEW;
}
@@ -861,6 +909,14 @@ function node_load_multiple($nids = array(), $conditions = array(), $reset = FAL
}
}
+ // Attach fields.
+ if ($vid) {
+ field_attach_load_revision('node', $queried_nodes);
+ }
+ else {
+ field_attach_load('node', $queried_nodes);
+ }
+
// Call hook_nodeapi_load(), pass the node types so modules can return early
// if not acting on types in the array.
foreach (module_implements('nodeapi_load') as $module) {
@@ -941,6 +997,9 @@ function node_validate($node, $form = array()) {
}
}
+ // Validate fields
+ field_attach_validate('node', $node, $form);
+
// Do node-type-specific validation checks.
node_invoke($node, 'validate', $form);
node_invoke_nodeapi($node, 'validate', $form);
@@ -993,6 +1052,7 @@ function node_submit($node) {
* Save a node object into the database.
*/
function node_save(&$node) {
+ field_attach_presave('node', $node);
// Let modules modify the node before it is saved to the database.
node_invoke_nodeapi($node, 'presave');
global $user;
@@ -1068,6 +1128,11 @@ function node_save(&$node) {
// node_invoke($node, 'insert') or
// node_invoke($node, 'update').
node_invoke($node, $op);
+
+ // Save fields.
+ $function = "field_attach_$op";
+ $function('node', $node);
+
node_invoke_nodeapi($node, $op);
// Update the node access table for this node.
@@ -1205,6 +1270,9 @@ function node_build_content($node, $teaser = FALSE) {
$node = node_prepare($node, $teaser);
}
+ // Build fields content.
+ $node->content += field_attach_view('node', $node, $teaser);
+
// Allow modules to make their own additions to the node.
node_invoke_nodeapi($node, 'view', $teaser);
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index a6e5d34bf..87106deed 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -257,7 +257,11 @@ function node_form(&$form_state, $node) {
);
}
$form['#validate'][] = 'node_form_validate';
- $form['#theme'] = array($node->type . '_node_form', 'node_form');
+ $form['#theme'] = array($node->type . '_node_form', 'node_form');
+
+ $form['#builder_function'] = 'node_form_submit_build_node';
+ field_attach_form('node', $node, $form, $form_state);
+
return $form;
}
@@ -464,8 +468,11 @@ function node_form_submit_build_node($form, &$form_state) {
// Unset any button-level handlers, execute all the form-level submit
// functions to process the form values into an updated node.
unset($form_state['submit_handlers']);
- form_execute_handlers('submit', $form, $form_state);
- $node = node_submit($form_state['values']);
+ form_execute_handlers('submit', $form, $form_state);
+ $node = node_submit($form_state['values']);
+
+ field_attach_submit('node', $node, $form, $form_state);
+
$form_state['node'] = (array)$node;
$form_state['rebuild'] = TRUE;
return $node;
diff --git a/modules/node/node.tpl.php b/modules/node/node.tpl.php
index 241f71407..3e950f11d 100644
--- a/modules/node/node.tpl.php
+++ b/modules/node/node.tpl.php
@@ -20,6 +20,7 @@
* - $terms: the themed list of taxonomy term links output from theme_links().
* - $submitted: themed submission information output from
* theme_node_submitted().
+ * TODO D7 : document $FIELD_NAME_rendered variables.
*
* Other variables:
* - $node: Full node object. Contains data that may not be safe.