You are here

function _field_timer_county_formatter in Field Timer 7

Help function.

Build renderable array and load necessary files for County formatter.

1 call to _field_timer_county_formatter()
field_timer_field_formatter_view in ./field_timer.module
Implements hook_field_formatter_view().

File

includes/field_timer.inc, line 51
Contains some help functions for formatters and settings forms.

Code

function _field_timer_county_formatter($items, $settings, $entity_type, $entity, $instance) {
  $info = entity_get_info($entity_type);
  $id_key = 'id_' . $entity->{$info['entity keys']['id']};
  $field_name = $instance['field_name'];
  $js_settings = array();
  $elements = array();
  foreach ($items as $delta => $item) {
    $elements[$delta] = array(
      '#type' => 'markup',
      '#markup' => '<div id="county-' . $entity_type . '-' . $id_key . '-' . $instance['field_name'] . '-' . $delta . '" ' . 'style="background: ' . $settings['background'] . ';"></div>',
    );
    $js_settings[$entity_type][$id_key][$field_name][$delta]['timestamp'] = $item['timestamp'];
    $js_settings[$entity_type][$id_key][$field_name][$delta]['options'] = $settings;
    $js_settings[$entity_type][$id_key][$field_name][$delta]['plugin'] = 'county';
  }

  // Load library files.
  $library = libraries_load('county');
  $library_loaded = $library && !empty($library['loaded']);
  $js_name = 'county.js';
  $base_path = 'sites/all/libraries/county';
  if (!$library_loaded) {
    drupal_set_message(t("Can't load County library. Please download !url jQuery plugin and extract it to @path, so @js can be found at @full_path.", array(
      '!url' => l(t('County'), 'https://github.com/brilsergei/county', array(
        'absolute' => TRUE,
      )),
      '@path' => $base_path,
      '@js' => $js_name,
      '@full_path' => $base_path . '/js/' . $js_name,
    )), 'error');
    return array();
  }
  drupal_add_js(array(
    'field_timer' => $js_settings,
  ), 'setting');
  drupal_add_js(drupal_get_path('module', 'field_timer') . '/js/field_timer.js', 'file');
  return $elements;
}