You are here

function double_field_field_formatter_view in Double Field 7

Same name and namespace in other branches
  1. 7.2 double_field.module \double_field_field_formatter_view()

Implements hook_field_formatter_view().

File

./double_field.module, line 301
Defines double text field type.

Code

function double_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $settings = $display['settings'];
  $element = array();
  if ($display['type'] == 'double_field_fieldset') {
    foreach ($items as $delta => $item) {
      $element[$delta] = array(
        '#title' => check_plain($settings['first']['prefix'] . $item['first'] . $settings['first']['suffix']),
        '#value' => check_plain($settings['second']['prefix'] . $item['second'] . $settings['second']['suffix']),
        '#theme' => 'fieldset',
        '#collapsible' => $settings['collapsible'],
        '#collapsed' => $settings['collapsed'],
      );

      // theme_fieldset() doesn't handle '#collapsible', '#collapsed' arguments as claimed
      // see http://drupal.org/node/1099132
      if ($settings['collapsible']) {
        $element[$delta]['#attached'] = array(
          'js' => array(
            'misc/form.js',
            'misc/collapse.js',
          ),
        );
        $element[$delta]['#attributes'] = array(
          'class' => $settings['collapsed'] ? array(
            'collapsible',
            'collapsed',
          ) : array(
            'collapsible',
          ),
        );
      }
    }
  }
  else {
    foreach ($items as $delta => $item) {
      $element[$delta] = array(
        '#display' => $display,
        '#item' => $item,
        '#theme' => 'double_field',
      );
    }
  }
  return $element;
}