Index: modules/field/field.default.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.default.inc,v retrieving revision 1.26 diff -u -p -r1.26 field.default.inc --- modules/field/field.default.inc 13 Dec 2009 12:41:08 -0000 1.26 +++ modules/field/field.default.inc 14 Dec 2009 22:40:25 -0000 @@ -150,7 +150,7 @@ function field_default_view($obj_type, $ if ($elements) { $info = array( - '#theme' => 'field', + '#theme' => array("field__{$field['field_name']}__$bundle", "field__$bundle", "field__{$field['field_name']}", 'field'), '#weight' => $display['weight'], '#title' => t($instance['label']), '#access' => field_access('view', $field, $obj_type, $object), Index: modules/field/field.module =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.module,v retrieving revision 1.54 diff -u -p -r1.54 field.module --- modules/field/field.module 13 Dec 2009 12:41:08 -0000 1.54 +++ modules/field/field.module 14 Dec 2009 22:40:25 -0000 @@ -180,9 +180,8 @@ function field_theme() { $path = drupal_get_path('module', 'field') . '/theme'; $items = array( 'field' => array( - 'template' => 'field', + 'pattern' => 'field__', 'render element' => 'element', - 'path' => $path, ), 'field_multiple_value_form' => array( 'render element' => 'element', @@ -680,17 +679,15 @@ function field_extract_bundle($obj_type, /** * Theme preprocess function for field.tpl.php. * - * @see field.tpl.php + * @see theme_field() */ function template_preprocess_field(&$variables) { $element = $variables['element']; - $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']); - $field = field_info_field($element['#field_name']); // @todo Convert to using drupal_html_class() after benchmarking the impact of // doing so. - $field_type_css = strtr($field['type'], '_', '-'); - $field_name_css = strtr($field['field_name'], '_', '-'); + $field_type_css = strtr($element['#field_type'], '_', '-'); + $field_name_css = strtr($element['#field_name'], '_', '-'); // Prepare an $items variable that the template can simply loop on. // Filter out non-children properties that might have been added if the @@ -698,51 +695,97 @@ function template_preprocess_field(&$var $items = array_intersect_key($element, array_flip(element_children($element))); $additions = array( - 'object' => $element['#object'], - 'field' => $field, - 'instance' => $instance, - 'build_mode' => $element['#build_mode'], 'items' => $items, - 'field_type' => $field['type'], - 'field_name' => $field['field_name'], 'field_type_css' => $field_type_css, 'field_name_css' => $field_name_css, 'label' => check_plain($element['#title']), 'label_display' => $element['#label_display'], 'label_hidden' => $element['#label_display'] == 'hidden', - 'field_language' => $element['#language'], - 'field_translatable' => $field['translatable'], 'classes_array' => array( + 'field', 'field-name-' . $field_name_css, 'field-type-' . $field_type_css, 'field-label-' . $element['#label_display'], ), - 'template_files' => array( - 'field', - 'field-' . $element['#field_name'], - 'field-' . $element['#bundle'], - 'field-' . $element['#field_name'] . '-' . $element['#bundle'], - ), + // By default, theme implementation is a function, so template_preprocess() + // isn't called, so these variables must be initialized here. + 'attributes_array' => array(), + 'title_attributes_array' => array(), + 'content_attributes_array' => array(), ); $variables = array_merge($variables, $additions); // Initialize attributes for each item. + $variables['item_attributes_array'] = array(); foreach ($variables['items'] as $delta => $item) { $variables['item_attributes_array'][$delta] = array(); } } +/** + * @} End of "defgroup field" + */ /** - * Theme process function for field.tpl.php. + * Return a themed field. + * + * A theme can override this implementation to override how all fields are + * themed. A theme can also implement an override function targeting specific + * fields. A theme can implement any or all of the following, depending on the + * specificity desired. For a given field, the first matching implementation is + * used. Uppercase letters signify a placeholder to be replaced with concrete + * names. An example follows in parentheses assuming a theme named "mytheme", + * and the field named "body", when used on the "page" content type. + * - THEMENAME_field__FIELDNAME__BUNDLE (e.g., mytheme_field__body__page) + * - THEMENAME_field__BUNDLE (e.g., mytheme_field__page) + * - THEMENAME_field__FIELDNAME (e.g., mytheme_field__body) + * - THEMENAME_field (e.g., mytheme_field) + * + * @param $variables + * An associative array containing: + * - element: The render array representing the field to be themed. + * - classes_array: An array of CSS classes to be added to the HTML element + * that contains all of the field markup. + * - attributes_array: An array of attributes (to be output using + * drupal_attributes()) to be added to the HTML element that contains all of + * the field markup. + * - title_attributes_array: An array of attributes (to be output using + * drupal_attributes()) to be added to the HTML element that contains the + * field label. + * - content_attributes_array: An array of attributes (to be output using + * drupal_attributes()) to be added to the HTML element that contains all of + * the field values. + * - item_attributes_array: An array with keys matching the keys used by + * $variables['items']. For each key, the value is an array of attributes + * (to be output using drupal_attributes()) to be added to the HTML element + * that contains the markup for the corresponding field value. + * - items: An array of field values. Use render() to output them. + * - label: The field label. + * - label_hidden: Whether the label display is set to 'hidden'. * - * @see field.tpl.php + * @return + * An HTML string containing the themed field. + * + * @ingroup themeable */ -function template_process_field(&$variables) { - // Flatten out attributes for each item. +function theme_field($variables) { + $attributes = $variables['attributes_array']; + $title_attributes = $variables['title_attributes_array']; + $content_attributes = $variables['content_attributes_array']; + $item_attributes = $variables['item_attributes_array']; + + $attributes['class'] = isset($variables['classes_array']) ? $variables['classes_array'] : array(); + $attributes['class'][] = 'clearfix'; + $output = '\n"; + if (!$variables['label_hidden']) { + $title_attributes['class'][] = 'field-label'; + $output .= '' . $variables['label'] . ": \n"; + } + $content_attributes['class'][] = 'field-items'; + $output .= '\n"; foreach ($variables['items'] as $delta => $item) { - $variables['item_attributes'][$delta] = drupal_attributes($variables['item_attributes_array'][$delta]); + $item_attributes[$delta]['class'][] = 'field-item'; + $item_attributes[$delta]['class'][] = $delta % 2 ? 'odd' : 'even'; + $output .= '' . render($item) . "\n"; } + $output .= ""; } -/** - * @} End of "defgroup field" - */ Index: modules/rdf/rdf.module =================================================================== RCS file: /cvs/drupal/drupal/modules/rdf/rdf.module,v retrieving revision 1.12 diff -u -p -r1.12 rdf.module --- modules/rdf/rdf.module 11 Dec 2009 16:49:40 -0000 1.12 +++ modules/rdf/rdf.module 14 Dec 2009 22:40:26 -0000 @@ -423,14 +423,12 @@ function rdf_preprocess_node(&$variables * Implements MODULE_preprocess_HOOK(). */ function rdf_preprocess_field(&$variables) { - $entity_type = $variables['element']['#object_type']; - $instance = $variables['instance']; - $mapping = rdf_mapping_load($entity_type, $instance['bundle']); - $field_name = $instance['field_name']; - $items = $variables['element']['#items']; + $element = $variables['element']; + $mapping = rdf_mapping_load($element['#object_type'], $element['#bundle']); + $field_name = $element['#field_name']; if (!empty($mapping) && !empty($mapping[$field_name])) { - foreach ($items as $delta => $item) { + foreach ($element['#items'] as $delta => $item) { $variables['item_attributes_array'][$delta] = rdf_rdfa_attributes($mapping[$field_name], $item); } }