### Eclipse Workspace Patch 1.0 #P drupal_test_7 Index: modules/taxonomy/taxonomy.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v retrieving revision 1.30 diff -u -r1.30 taxonomy.pages.inc --- modules/taxonomy/taxonomy.pages.inc 28 Jun 2009 13:37:29 -0000 1.30 +++ modules/taxonomy/taxonomy.pages.inc 7 Jul 2009 15:14:38 -0000 @@ -54,6 +54,8 @@ // confusion. if (count($tids) == 1) { $term = taxonomy_term_load($tids[0]); + $objects = array($term->tid => $term); + field_attach_formatter_load('taxonomy_term', $objects, 'full'); $build += field_attach_view('taxonomy_term', $term); if (!empty($term->description)) { $build['term_description'] = array( 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 7 Jul 2009 15:14:37 -0000 @@ -475,6 +475,13 @@ } /** + * Allow formatters to act on fieldable objects prior to rendering. + */ +function field_attach_formatter_load($obj_type, $objects, $build_mode) { + _field_invoke_multiple_default('formatter_load', $obj_type, $objects, $build_mode); +} + +/** * Load all fields for a previous version of each of a set of * objects of a single object type. * 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 7 Jul 2009 15:14:37 -0000 @@ -58,6 +58,36 @@ } /** + * Find the correct formatter to use when preparing objects for rendering + * and allow it to load additional properties into the objects. + */ +function field_default_formatter_load($obj_type, $objects, $field, $instances, $items, $build_mode) { + // Since formatters need to be applied per bundle, build an array of + // formatters and objects to pass to hook_field_formatter_load(). + $formatters = 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. + $display = _field_get_formatter($display, $field); + + $formatter_type = $display['type']; + $formatter_info = field_info_formatter_types($formatter_type); + $formatters[$formatter_type]['module'] = $formatter_info['module']; + $formatters[$formatter_type]['objects'][$id] = $objects[$id]; + } + + foreach ($formatters as $formatter_type => $info) { + // Invoke hook_field_formatter_load(). + $function = $info['module'] . '_field_formatter_load'; + if (drupal_function_exists($function)) { + // TODO arguments: field, instance, formatter settings ? ... + $function($formatter['objects'], $formatter_type); + } + } +} + +/** * 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 7 Jul 2009 15:14:36 -0000 @@ -294,6 +294,22 @@ } /** + * 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. + * Information should be added as properties of the loaded objects. + * + * @param $object + * An array of the objects to be displayed, keyed by object ID. + * @param $formatter + * The formatter array for this instance. + */ +function hook_field_formatter_load($objects, $formatter) { +} + +/** * Define custom validate behavior for this module's field types. * * @param $obj_type 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 7 Jul 2009 15:14:38 -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 7 Jul 2009 15:14:40 -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; } /**