You are here

function jquery_colorpicker_field_formatter_view in Jquery Colorpicker 7

Implements hook_field_formatter_view().

File

./jquery_colorpicker.module, line 243
JQuery Colorpicker primary module file.

Code

function jquery_colorpicker_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $css_attachment_cache =& drupal_static(__FUNCTION__ . '_css');
  if (!isset($css_attachment_cache)) {
    $css_attachment_cache = array();
  }
  $element = array();
  foreach ($items as $delta => $item) {
    switch ($display['type']) {
      case 'jquery_colorpicker_color_display':
        list($id, , ) = entity_extract_ids($entity_type, $entity);
        $element[$delta] = array(
          '#theme' => 'jquery_colorpicker_color_display',
          '#entity_id' => $id,
          '#instance_id' => $instance['id'],
          '#entity_delta' => $delta,
          '#item' => $item['jquery_colorpicker'],
          '#attached' => array(
            'css' => array(
              array(
                'type' => 'inline',
                'data' => '.jquery_colorpicker_color_display_' . $instance['id'] . '_' . $delta . '_' . $item['jquery_colorpicker'] . '{background-color:#' . $item['jquery_colorpicker'] . ';}',
              ),
            ),
          ),
        );
        break;
      case 'jquery_colorpicker_text_display':
        $element[$delta] = array(
          '#theme' => 'jquery_colorpicker_text_display',
          '#item' => $item['jquery_colorpicker'],
        );
        break;
      case 'jquery_colorpicker_raw_hex_display':
        $element[$delta]['#markup'] = $item['jquery_colorpicker'];
        break;
    }
  }
  return $element;
}