You are here

function template_preprocess_flickity_entity_view in Flickity Carousel 8

Same name and namespace in other branches
  1. 8.2 modules/fields/theme/flickity_fields.theme.inc \template_preprocess_flickity_entity_view()
  2. 3.0.x modules/fields/theme/flickity_fields.theme.inc \template_preprocess_flickity_entity_view()

Implements template_preprocess_flickity_entity_view().

File

modules/fields/theme/flickity_fields.theme.inc, line 12
Contains flickity.theme.inc

Code

function template_preprocess_flickity_entity_view(array &$variables) {
  $elements = $variables['elements'];

  // Helpful $content variable for templates.
  foreach (Element::children($elements['#children']) as $key) {
    $variables['contents'][$key] = $elements['#children'][$key];
  }

  // Set Label and Display
  $variables['label_display'] = $elements['#label_display'];
  $variables['label_hidden'] = $elements['#label_display'] == 'hidden';
  $variables['label'] = $elements['#title'];

  // Load Flickity settings.
  $group = flickity_settings($variables['elements']['#settings']);
  $variables['attributes'] = array(
    'class' => array(
      $group['id'],
      'flickity',
    ),
  );

  // Attach Flickity library with settings.
  $variables['#attached'] = array(
    'drupalSettings' => array(
      'flickity' => array(
        $group['id'] => array(
          'settings' => $group['settings'],
        ),
      ),
    ),
    'library' => array(
      'flickity/local',
      'flickity/settings',
    ),
  );
}