You are here

function addtocalendar_preprocess_field in Add To Calendar Button (AddEvent.com) 7.2

Same name and namespace in other branches
  1. 8 addtocalendar.module \addtocalendar_preprocess_field()
  2. 8.2 addtocalendar.module \addtocalendar_preprocess_field()
  3. 8.3 addtocalendar.module \addtocalendar_preprocess_field()
  4. 7 addtocalendar.module \addtocalendar_preprocess_field()

Implements hook_preprocess_field().

File

./addtocalendar.module, line 71
Contains module code.

Code

function addtocalendar_preprocess_field(&$variables) {

  // Provide an extra variable to the field template when the field uses
  // a formatter of type 'foo_formatter'.
  if ($variables['element']['#formatter'] == 'date_default') {
    $entity_type = $variables['element']['#entity_type'];
    $field_name = $variables['element']['#field_name'];
    $bundle = $variables['element']['#bundle'];
    $view_mode = $variables['element']['#view_mode'];
    $entity = $variables['element']['#object'];
    $formatter_settings = field_formatter_settings_get_instance_display_settings($entity_type, $field_name, $bundle, $view_mode);

    // Make the setting available in the field template.
    $variables['addtocalendar_settings'] = $formatter_settings['addtocalendar_settings'];
    if (!empty($variables['addtocalendar_settings'])) {
      $build['addtocalendar'] = array();
      $settings = $variables['addtocalendar_settings'];
      $settings['atc_date_start'] = array(
        'field' => $field_name,
        'tokenized' => date('Y-m-d H:i:s', time()),
      );
      module_load_include('inc', 'addtocalendar', 'includes/addtocalendar');
      $build = addtocalendar_preprocess_setting_fields($entity_type, $entity, $settings, $formatter_settings);
      $variables['items'][0]['#markup'] .= render($build['addtocalendar']);
      $variables['#attached']['library'][] = drupal_add_css('//addtocalendar.com/atc/1.5/atc-base.css', 'external');
    }
  }
}