### Eclipse Workspace Patch 1.0 #P drupal_test_7 Index: modules/field/field.info.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.info.inc,v retrieving revision 1.7 diff -u -r1.7 field.info.inc --- modules/field/field.info.inc 30 Jun 2009 03:12:03 -0000 1.7 +++ modules/field/field.info.inc 8 Jul 2009 23:21:08 -0000 @@ -30,6 +30,7 @@ $field_type = field_info_field_types($field['type']); $display['type'] = $field_type['default_formatter']; $formatter_type = field_info_formatter_types($display['type']); + $display['module'] = $formatter_type['module']; } $function = $formatter_type['module'] . '_field_formatter_settings'; if (drupal_function_exists($function)) { Index: modules/field/field.attach.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.attach.inc,v retrieving revision 1.29 diff -u -r1.29 field.attach.inc --- modules/field/field.attach.inc 7 Jul 2009 09:28:07 -0000 1.29 +++ modules/field/field.attach.inc 8 Jul 2009 23:21:08 -0000 @@ -858,6 +858,13 @@ } /** + * Allow formatters to act on fieldable objects prior to rendering. + */ +function field_attach_prepare_view($obj_type, $objects, $build_mode) { + _field_invoke_multiple_default('prepare_view', $obj_type, $objects, $build_mode); +} + +/** * Generate and return a structured content array tree suitable for * drupal_render() for all of the fields on an object. The format of * each field's rendered content depends on the display formatter and Index: modules/field/field.default.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.default.inc,v retrieving revision 1.9 diff -u -r1.9 field.default.inc --- modules/field/field.default.inc 24 Jun 2009 18:16:38 -0000 1.9 +++ modules/field/field.default.inc 8 Jul 2009 23:21:08 -0000 @@ -58,6 +58,35 @@ } /** + * Invoke hook_field_formatter_prepare_view() on the relavant formatters. + */ +function field_default_prepare_view($obj_type, $objects, $field, $instances, &$items, $build_mode) { + // Group objects, instances and items by formatter module. + $modules = array(); + foreach ($instances as $id => $instance) { + // Determine the right formatter to use for the build mode. + $display = isset($instance['display'][$build_mode]) ? $instance['display'][$build_mode] : $instance['display']['full']; + // Back up to the default formatter if needed. + $instance['display'][$build_mode] = _field_get_formatter($display, $field);; + + $module = $instance['display'][$build_mode]['module']; + $modules[] = $module; + $grouped_objects[$module][$id] = $objects[$id]; + $grouped_instances[$module][$id] = $instance; + // hook_field_formatter_prepare_view() alters $items by reference. + $grouped_items[$module][$id] = &$items[$id]; + } + + foreach ($modules as $module) { + // Invoke hook_field_formatter_prepare_view(). + $function = $module . '_field_formatter_prepare_view'; + if (drupal_function_exists($function)) { + $function($obj_type, $grouped_objects[$module], $field, $grouped_instances[$module], $grouped_items[$module], $build_mode); + } + } +} + +/** * The 'view' operation constructs the $object in a way that you can use * drupal_render() to display the formatted output for an individual field. * i.e. print drupal_render($object->content['field_foo']); Index: modules/field/field.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.api.php,v retrieving revision 1.17 diff -u -r1.17 field.api.php --- modules/field/field.api.php 30 Jun 2009 03:12:03 -0000 1.17 +++ modules/field/field.api.php 8 Jul 2009 23:21:08 -0000 @@ -516,6 +516,30 @@ } /** + * Allow formatters to load information for multiple objects. + * + * This should be used when a formatter needs to load additional information + * from the database in order to render a field, for example a reference field + * which displays properties of the referenced objects such as name or type. + * + * @param $obj_type + * The type of $object. + * @param $objects + * Array of objects being displayed, keyed by object id. + * @param $field + * The field structure for the operation. + * @param $instances + * Array of instance structures for $field for each object, keyed by object id. + * @param $items + * Array of field values for the objects, keyed by object id. + * @return + * Changes or additions to field values are done by altering the $items + * parameter by reference. + */ +function hook_field_formatter_prepare_view($obj_type, $objects, $field, $instances, &$items, $build_mode) { +} + +/** * @} End of "ingroup field_type" */ Index: modules/taxonomy/taxonomy.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v retrieving revision 1.31 diff -u -r1.31 taxonomy.pages.inc --- modules/taxonomy/taxonomy.pages.inc 8 Jul 2009 07:18:08 -0000 1.31 +++ modules/taxonomy/taxonomy.pages.inc 8 Jul 2009 23:21:10 -0000 @@ -30,6 +30,7 @@ drupal_add_feed(url('taxonomy/term/' . $term->tid . '/feed'), 'RSS - ' . $term->name); drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css'); + field_attach_formatter_load('taxonomy_term', array($term->tid => $term), 'full'); $build = array(); $build += field_attach_view('taxonomy_term', $term); if (!empty($term->description)) { @@ -109,8 +110,8 @@ ->condition('t.vid', $vid) // Select rows that either match by term or synonym name. ->condition(db_or() - ->where("LOWER(t.name) LIKE :last_string", array(':last_string' => '%' . $tag_last . '%')) - ->where("LOWER(ts.name) LIKE :last_string", array(':last_string' => '%' . $tag_last . '%')) + ->where("LOWER(t.name) LIKE :last_string", array(':last_string' => '%' . $tag_last . '%')) + ->where("LOWER(ts.name) LIKE :last_string", array(':last_string' => '%' . $tag_last . '%')) ) ->range(0, 10) ->execute() Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1080 diff -u -r1.1080 node.module --- modules/node/node.module 7 Jul 2009 13:51:58 -0000 1.1080 +++ modules/node/node.module 8 Jul 2009 23:21:10 -0000 @@ -1182,7 +1182,7 @@ node_tag_new($node->nid); // For markup consistency with other pages, use node_build_multiple() rather than node_build(). - return node_build_multiple(array($node), 'full'); + return node_build_multiple(array($node->nid => $node), 'full'); } /** @@ -1951,6 +1951,7 @@ * An array in the format expected by drupal_render(). */ function node_build_multiple($nodes, $build_mode = 'teaser', $weight = 0) { + field_attach_formatter_load('node', $nodes, $build_mode); $build = array(); foreach ($nodes as $node) { $build['nodes'][$node->nid] = node_build($node, $build_mode); Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1008 diff -u -r1.1008 user.module --- modules/user/user.module 5 Jul 2009 18:07:04 -0000 1.1008 +++ modules/user/user.module 8 Jul 2009 23:21:11 -0000 @@ -1990,7 +1990,9 @@ * @return * A structured array containing the individual elements of the profile. */ -function user_build_content(&$account) { +function user_build_content($account) { + $accounts = array($account->uid, $account); + field_attach_formatter_load('user', $accounts, 'full'); $edit = NULL; $account->content = array(); @@ -2002,8 +2004,6 @@ // Allow modules to modify the fully-built profile. drupal_alter('profile', $account); - - return $account->content; } /**