function itoggle_field_field_formatter_view in iToggle 7
Same name and namespace in other branches
- 7.2 modules/field/itoggle_field.module \itoggle_field_field_formatter_view()
Implements hook_field_formatter_view().
File
- modules/
field/ itoggle_field.module, line 41 - iToggle Field module.
Code
function itoggle_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$elements = array();
// @TODO figure out if there is a better place to add the scripts
itoggle_include_itoggle();
itoggle_include_settings();
drupal_add_js(drupal_get_path('module', 'itoggle') . '/js/itoggle.js');
$info = itoggle_get_entity_info();
$id = $info[$entity_type]['entity keys']['id'];
$id = $entity->{$id};
$checked = isset($items[0]['value']) && $items[0]['value'] == 1;
if (!count($items)) {
$items[] = 'itoggle';
}
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#markup' => theme('itoggle', array(
'type' => $entity_type,
'id' => $id,
'property' => $field['field_name'],
'checked' => $checked,
'scope' => 'field',
)),
);
}
return $elements;
}