- Patch #567092 by rcross, yched, bjaspan: merge hook_field_formatter_info() and hook_theme().

merge-requests/26/head
Dries Buytaert 2009-09-09 21:21:54 +00:00
parent a3f776f4d4
commit c33da192c1
7 changed files with 33 additions and 51 deletions

View File

@ -663,14 +663,25 @@ function hook_field_widget_error($element, $error) {
* of drupal_render() on the render structure built by field_attach_view(). * of drupal_render() on the render structure built by field_attach_view().
* *
* The name of the theme hook invoked when displaying the values is derived * The name of the theme hook invoked when displaying the values is derived
* from formatter type names, following the pattern: * from formatter type names, using the pattern field_formatter_FORMATTER_NAME.
* field_formatter_FORMATTER_NAME * field.module takes care of exposing the corresponding theme functions
* The module implementing the formatters needs to register those theme hooks * through hook_theme(). Specifically, field.module defines the theme
* using hook_theme(). * hook:
*
* @code
* 'field_formatter_FORMATTER_NAME' => array(
* 'arguments' => array('element' => NULL),
* )
* @code
*
* If a formatter requires a different theme hook definition,
* implement hook_theme_registry_alter().
* *
* @see hook_field_formatter_info(). * @see hook_field_formatter_info().
* @see hook_field_formatter_info_alter(). * @see hook_field_formatter_info_alter().
* @see theme_field_formatter_FORMATTER_NAME(). * @see theme_field_formatter_FORMATTER_NAME().
* @see hook_theme().
* @see hook_theme_registry_alter().
* *
* @return * @return
* An array describing the formatter types implemented by the module. * An array describing the formatter types implemented by the module.

View File

@ -153,8 +153,7 @@ function field_help($path, $arg) {
*/ */
function field_theme() { function field_theme() {
$path = drupal_get_path('module', 'field') . '/theme'; $path = drupal_get_path('module', 'field') . '/theme';
$items = array(
return array(
'field' => array( 'field' => array(
'template' => 'field', 'template' => 'field',
'arguments' => array('element' => NULL), 'arguments' => array('element' => NULL),
@ -164,6 +163,13 @@ function field_theme() {
'arguments' => array('element' => NULL), 'arguments' => array('element' => NULL),
), ),
); );
$field_formatters = field_info_formatter_types(NULL);
foreach ($field_formatters as $key => $field_formatter) {
$items["field_formatter_$key"] = array(
'arguments' => array('element' => NULL),
);
}
return $items;
} }
/** /**

View File

@ -6,20 +6,6 @@
* Defines list field types that can be used with the Options module. * Defines list field types that can be used with the Options module.
*/ */
/**
* Implement hook_theme().
*/
function list_theme() {
return array(
'field_formatter_list_default' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_list_key' => array(
'arguments' => array('element' => NULL),
),
);
}
/** /**
* Implement hook_field_info(). * Implement hook_field_info().
*/ */

View File

@ -12,12 +12,18 @@
function number_theme() { function number_theme() {
return array( return array(
'number' => array('arguments' => array('element' => NULL)), 'number' => array('arguments' => array('element' => NULL)),
'field_formatter_number_integer' => array('arguments' => array('element' => NULL), 'function' => 'theme_field_formatter_number'),
'field_formatter_number_decimal' => array('arguments' => array('element' => NULL), 'function' => 'theme_field_formatter_number'),
'field_formatter_number_unformatted' => array('arguments' => array('element' => NULL)),
); );
} }
/**
* Implement hook_theme_alter().
*/
function number_theme_registry_alter(&$theme_registry) {
// The number_integer and number_decimal formatters use the same function.
$theme_registry['field_formatter_number_integer']['function'] = 'theme_field_formatter_number';
$theme_registry['field_formatter_number_decimal']['function'] = 'theme_field_formatter_number';
}
/** /**
* Implement hook_field_info(). * Implement hook_field_info().
*/ */
@ -204,7 +210,7 @@ function number_field_is_empty($item, $field) {
*/ */
function number_field_formatter_info() { function number_field_formatter_info() {
return array( return array(
'number_integer' => array( 'number_default' => array(
'label' => t('default'), 'label' => t('default'),
'field types' => array('number_integer'), 'field types' => array('number_integer'),
'settings' => array( 'settings' => array(

View File

@ -17,18 +17,6 @@ function text_theme() {
'text_textfield' => array( 'text_textfield' => array(
'arguments' => array('element' => NULL), 'arguments' => array('element' => NULL),
), ),
'field_formatter_text_default' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_text_plain' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_text_trimmed' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_text_summary_or_trimmed' => array(
'arguments' => array('element' => NULL),
),
); );
} }

View File

@ -85,15 +85,6 @@ function file_theme() {
'file_upload_help' => array( 'file_upload_help' => array(
'arguments' => array('upload_validators' => NULL), 'arguments' => array('upload_validators' => NULL),
), ),
'field_formatter_file_default' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_file_table' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_file_url_plain' => array(
'arguments' => array('element' => NULL),
),
); );
} }

View File

@ -91,12 +91,6 @@ function taxonomy_theme() {
'taxonomy_overview_terms' => array( 'taxonomy_overview_terms' => array(
'arguments' => array('form' => array()), 'arguments' => array('form' => array()),
), ),
'field_formatter_taxonomy_term_link' => array(
'arguments' => array('element' => NULL),
),
'field_formatter_taxonomy_term_plain' => array(
'arguments' => array('element' => NULL),
),
'taxonomy_autocomplete' => array( 'taxonomy_autocomplete' => array(
'arguments' => array('element' => NULL), 'arguments' => array('element' => NULL),
), ),