Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
3 Sep 2009 at 09:12 UTC
Updated:
23 Sep 2009 at 21:30 UTC
Jump to comment: Most recent file
While writing my Color Picker sample field module, I found myself wondering what value hook_field_formatter_info() provides that could not also be provided by additional data in hook_theme().
/**
* Implement hook_field_formatter_info().
*/
function colorpicker_field_formatter_info() {
return array(
'colorpicker_helloworld' => array(
'label' => t('"Hello, World" in color'),
'field types' => array('colorpicker_rgb'),
),
);
}
/**
* Implement hook_theme().
*/
function colorpicker_theme() {
return array(
'field_formatter_colorpicker_helloworld' => array(
'arguments' => array('element' => NULL),
),
);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | field-formatter-hook-theme-567092-10.patch | 7.75 KB | bjaspan |
| #6 | field_formatter_hook_theme-567092-6.patch | 6.58 KB | yched |
| #5 | field_formatter_theming-1.patch | 5.57 KB | rcross |
| #3 | field_formatter_theming.patch | 1.28 KB | rcross |
Comments
Comment #1
yched commentedThe list of formatter settings doesn't really belong in hook_theme(), I guess ?
I'd tend to think the other way around :
given hook_field_formatter_info(), field.module should be able to take care of exposing the corresponding hook_theme() information in field_theme(), saving the need for field type modules to do it themselves.
Comment #2
rcross commentedi'm on it!
Comment #3
rcross commentedHere is a start. I hope this works.
Comment #5
rcross commentedafter a few discussions, this should improve things but seems to have a small error on my dev machine that i can't pinpoint.
Comment #6
yched commentedUpdated patch just adds a few comments. Other than that, RTBC.
Comment #7
bjaspan commentedI'm fine with the approach of having hook_field_formatter_info() generate hook_theme() results instead of the other way around, so long as we do not have to specify the same info twice.
Question: I'm not a hook_theme guru. Is there any possible Field API formatter that might want to generate its own hook_theme output instead of what Field API provides for it? If so, then we should probably add an optional #tag that hook_field_formatter_info() can return for any given formatter to say "don't export hook_theme() for this one, I'll take care of it." A DEFAULT/CUSTOM behavior switch like we already have for other things, basically.
Comment #8
bjaspan commentedCNR until the question in #7 is answered.
Comment #9
yched commentedbjaspan: number.module has this use case of needing to alter the 'default' theme info (2 formatters use the same theme function), and the patch does this using hook_theme_registry_alter().
That stays inline with the existing tools and hooks around the theme registry, I'm not sure we need to add a new way to specify theme informations, specific to formatters.
Comment #10
bjaspan commentedI added some PHPdoc I thought was important; no code changes.
Comment #11
dries commentedReviewed. Looks good, so committed.