Created
December 5, 2011 17:56
-
-
Save katbailey/1434569 to your computer and use it in GitHub Desktop.
field formatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_field_formatter_info(). | |
*/ | |
function mymodule_field_formatter_info() { | |
return array( | |
'default_image_formatter' => array( | |
'label' => t('Image with default'), | |
'field types' => array('imagefield'), // check that this is the field type name | |
'settings' => array('default_path' => ''), | |
), | |
); | |
} | |
/** | |
* Implements hook_field_formatter_settings_form(). | |
*/ | |
function mymodule_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { | |
$display = $instance['display'][$view_mode]; | |
$settings = $display['settings']; | |
$element = array(); | |
if ($display['type'] == 'default_image_formatter') { | |
$default_path = (isset($settings['default_path']) ? $settings['default_path'] : ''); | |
$element['default_path'] = array( | |
'#type' => 'textfield', | |
'#default_value' => $default_path, | |
'#title' => t('Default path'), | |
); | |
} | |
return $element; | |
} | |
/** | |
* Implements hook_field_formatter_settings_summary(). | |
*/ | |
function my_module_field_formatter_settings_summary($field, $instance, $view_mode) { | |
$display = $instance['display'][$view_mode]; | |
$settings = $display['settings']; | |
$summary = ''; | |
if ($display['type'] == 'default_image_formatter') { | |
$summary = t('If the field contains no val'); | |
} | |
return $summary; | |
} | |
/** | |
* Implements hook_field_formatter_prepare_view(). | |
*/ | |
function my_module_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) { | |
foreach ($entities as $id => $entity) { | |
if (!count($items[$id])) { | |
// This means the field has no value for this particular entity - so add | |
// one using the default path | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment