You are here

flickity.module in Flickity Carousel 8

Same filename and directory in other branches
  1. 8.2 flickity.module
  2. 3.0.x flickity.module

File

flickity.module
View source
<?php

/**
 * @file
 * flickity.module
 */
use Drupal\flickity\Entity\FlickityGroup;

/**
 * Implements hook_theme().
 */
function flickity_theme() {
  return array(
    'flickity' => array(
      'function' => 'theme_flickity',
      'variables' => array(
        'items' => array(),
        'settings' => array(),
      ),
      'file' => 'theme/flickity.theme.inc',
    ),
    'flickity_item' => array(
      'variables' => array(
        'item' => array(),
        'attributes' => array(),
      ),
    ),
    'flickity_wrapper' => array(
      'variables' => array(
        'output' => array(),
        'attributes' => array(),
      ),
    ),
  );
}

/**
 * Returns Flickity settings group to initialize.
 *
 * @todo offer breakpoints as child setting groups.
 *
 * @param $id
 */
function flickity_settings($id) {
  $config = flickity_load($id);
  $settings = $config
    ->getSettings();
  $group = array(
    'id' => $config
      ->id(),
    'label' => $config
      ->label(),
    'settings' => array(
      'imagesLoaded' => $settings['images_loaded'],
      'cellSelector' => $settings['cell_selector'],
      'initialIndex' => $settings['initial_index'],
      'accessibility' => (bool) $settings['accessibility'],
      'setGallerySize' => (bool) $settings['set_gallery_size'],
      'resize' => (bool) $settings['resize'],
      'cellAlign' => $settings['cell_align'],
      'contain' => (bool) $settings['contain'],
      'percentPosition' => (bool) $settings['percent_position'],
      'rightToLeft' => (bool) $settings['right_to_left'],
      'draggable' => (bool) $settings['draggable'],
      'freeScroll' => (bool) $settings['free_scroll'],
      'wrapAround' => (bool) $settings['wrap_around'],
      'lazyLoad' => $settings['lazy_load'],
      'autoPlay' => $settings['auto_play'],
      'watchCSS' => (bool) $settings['watch_css'],
      'asNavFor' => $settings['as_nav_for'],
      'selectedAttraction' => $settings['selected_attraction'],
      'friction' => $settings['friction'],
      'freeScrollFriction' => $settings['free_scroll_friction'],
      'preNextButtons' => (bool) $settings['prev_next_buttons'],
      'pageDots' => (bool) $settings['page_dots'],
    ),
  );

  // Allow alter on group settings.
  \Drupal::moduleHandler()
    ->alter('settings', $group);
  return $group;
}

/**
 * Returns Flickity settings group by id.
 *
 * @param $id
 * @return \Drupal\Core\Entity\EntityInterface|static
 */
function flickity_load($id) {
  return FlickityGroup::load($id);
}

/**
 * Returns multiple Flickity settings groups.
 *
 * @return \Drupal\Core\Entity\EntityInterface|static
 */
function flickity_load_multiple($ids = NULL) {
  return FlickityGroup::loadMultiple($ids);
}

/**
 * Returns a list of all available settings groups.
 */
function flickity_settings_list() {
  $options = array();
  foreach (flickity_load_multiple() as $group) {
    $options[$group
      ->id()] = $group
      ->label();
  }
  return $options;
}

/**
 * Implements hook_form_alter().
 */
function flickity_form_flickity_group_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  if ($form['id']['#default_value'] == 'default_group') {
    hide($form['actions']['delete']);
  }
}

Functions

Namesort descending Description
flickity_form_flickity_group_form_alter Implements hook_form_alter().
flickity_load Returns Flickity settings group by id.
flickity_load_multiple Returns multiple Flickity settings groups.
flickity_settings Returns Flickity settings group to initialize.
flickity_settings_list Returns a list of all available settings groups.
flickity_theme Implements hook_theme().