You are here

public function SlickForm::getFormElements in Slick Carousel 8

Same name and namespace in other branches
  1. 8.2 slick_ui/src/Form/SlickForm.php \Drupal\slick_ui\Form\SlickForm::getFormElements()
  2. 7.3 slick_ui/src/Form/SlickForm.php \Drupal\slick_ui\Form\SlickForm::getFormElements()

Defines available options for the main and responsive settings.

Return value

array All available Slick options.

See also

http://kenwheeler.github.io/slick

2 calls to SlickForm::getFormElements()
SlickForm::cleanFormElements in slick_ui/src/Form/SlickForm.php
Removes problematic options for the responsive Slick.
SlickForm::form in slick_ui/src/Form/SlickForm.php
Gets the actual form array to be built.

File

slick_ui/src/Form/SlickForm.php, line 301

Class

SlickForm
Extends base form for slick instance configuration form.

Namespace

Drupal\slick_ui\Form

Code

public function getFormElements() {
  if (!isset($this->formElements)) {
    $elements = [];
    $elements['mobileFirst'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Mobile first'),
      'description' => $this
        ->t('Responsive settings use mobile first calculation, or equivalent to min-width query.'),
    ];
    $elements['asNavFor'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('asNavFor target'),
      'description' => $this
        ->t('Leave empty if using sub-modules to have it auto-matched. Set the slider to be the navigation of other slider (Class or ID Name). Use selector identifier ("." or "#") accordingly. See HTML structure section at README.md for more info. Overriden by field formatter, or Views style.'),
    ];
    $elements['accessibility'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Accessibility'),
      'description' => $this
        ->t('Enables tabbing and arrow key navigation'),
    ];
    $elements['adaptiveHeight'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Adaptive height'),
      'description' => $this
        ->t('Enables adaptive height for SINGLE slide horizontal carousels. This is useless with variableWidth.'),
    ];
    $elements['autoplay'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Autoplay'),
      'description' => $this
        ->t('Enables autoplay'),
    ];
    $elements['autoplaySpeed'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Autoplay speed'),
      'description' => $this
        ->t('Autoplay speed in milliseconds'),
    ];
    $elements['pauseOnHover'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Pause on hover'),
      'description' => $this
        ->t('Pause autoplay on hover'),
    ];
    $elements['pauseOnDotsHover'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Pause on dots hover'),
      'description' => $this
        ->t('Pause autoplay when a dot is hovered.'),
    ];
    $elements['arrows'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Arrows'),
      'description' => $this
        ->t('Show prev/next arrows'),
    ];
    $elements['prevArrow'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Previous arrow'),
      'description' => $this
        ->t("Customize the previous arrow text, default to Previous."),
    ];
    $elements['nextArrow'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Next arrow'),
      'description' => $this
        ->t("Customize the next arrow text, default to Next."),
    ];
    $elements['downArrow'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Use arrow down'),
      'description' => $this
        ->t('Arrow down to scroll down into a certain page section. Be sure to provide its target selector.'),
    ];
    $elements['downArrowTarget'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Arrow down target'),
      'description' => $this
        ->t('Valid CSS selector to scroll to, e.g.: #main, or #content.'),
    ];
    $elements['downArrowOffset'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Arrow down offset'),
      'description' => $this
        ->t('Offset when scrolled down from the top.'),
      'field_suffix' => 'px',
    ];
    $elements['centerMode'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Center mode'),
      'description' => $this
        ->t('Enables centered view with partial prev/next slides. Use with odd numbered slidesToShow counts.'),
    ];
    $elements['centerPadding'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Center padding'),
      'description' => $this
        ->t('Side padding when in center mode (px or %). Be aware, too large padding at small breakpoint will screw the slide calculation with slidesToShow.'),
    ];
    $elements['dots'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Dots'),
      'description' => $this
        ->t('Show dot indicators.'),
    ];
    $elements['dotsClass'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Dot class'),
      'description' => $this
        ->t('Class for slide indicator dots container. Do not prefix with a dot (.). If you change this, edit its CSS accordingly.'),
    ];
    $elements['appendDots'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Append dots'),
      'description' => $this
        ->t('Change where the navigation dots are attached (Selector, htmlString). If you change this, be sure to provide its relevant markup. Try <strong>.slick__arrow</strong> to achieve this style: <br />&lt; o o o o o o o &gt;<br />Be sure to enable Arrows in such a case.'),
    ];
    $elements['draggable'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Draggable'),
      'description' => $this
        ->t('Enable mouse dragging.'),
    ];
    $elements['fade'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Fade'),
      'description' => $this
        ->t('Enable fade. Warning! This wants slidesToShow 1. Larger than 1, and Slick may be screwed up.'),
    ];
    $elements['focusOnSelect'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Focus on select'),
      'description' => $this
        ->t('Enable focus on selected element (click).'),
    ];
    $elements['infinite'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Infinite'),
      'description' => $this
        ->t('Infinite loop sliding.'),
    ];
    $elements['initialSlide'] = [
      'type' => 'number',
      'title' => $this
        ->t('Initial slide'),
      'description' => $this
        ->t('Slide to start on.'),
    ];
    $elements['lazyLoad'] = [
      'type' => 'select',
      'title' => $this
        ->t('Lazy load'),
      'options' => $this
        ->getLazyloadOptions(),
      'empty_option' => $this
        ->t('- None -'),
      'description' => $this
        ->t("Set lazy loading technique. Ondemand will load the image as soon as you slide to it. Progressive loads one image after the other when the page loads. Anticipated preloads images, and requires Slick 1.6.1+. To share images for Pinterest, leave empty, otherwise no way to read actual image src. It supports Blazy module to delay loading below-fold images until 100px before they are visible at viewport, and/or have a bonus lazyLoadAhead when the beforeChange event fired.", [
        '@url' => '//www.drupal.org/project/imageinfo_cache',
      ]),
    ];
    $elements['mouseWheel'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Enable mousewheel'),
      'description' => $this
        ->t('Be sure to download the <a href="@mousewheel" target="_blank">mousewheel</a> library, and it is available at <em>/libraries/mousewheel/jquery.mousewheel.min.js</em>.', [
        '@mousewheel' => '//github.com/brandonaaron/jquery-mousewheel',
      ]),
    ];
    $elements['randomize'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Randomize'),
      'description' => $this
        ->t('Randomize the slide display, useful to manipulate cached blocks.'),
    ];
    $responds = [
      'window',
      'slider',
      'min',
    ];
    $elements['respondTo'] = [
      'type' => 'select',
      'title' => $this
        ->t('Respond to'),
      'description' => $this
        ->t("Width that responsive object responds to. Can be 'window', 'slider' or 'min' (the smaller of the two)."),
      'options' => array_combine($responds, $responds),
    ];
    $elements['rtl'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('RTL'),
      'description' => $this
        ->t("Change the slider's direction to become right-to-left."),
    ];
    $elements['rows'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Rows'),
      'description' => $this
        ->t("Setting this to more than 1 initializes grid mode. Use slidesPerRow to set how many slides should be in each row."),
    ];
    $elements['slidesPerRow'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Slides per row'),
      'description' => $this
        ->t("With grid mode intialized via the rows option, this sets how many slides are in each grid row."),
    ];
    $elements['slide'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Slide element'),
      'description' => $this
        ->t("Element query to use as slide. Slick will use any direct children as slides, without having to specify which tag or selector to target."),
    ];
    $elements['slidesToShow'] = [
      'type' => 'number',
      'title' => $this
        ->t('Slides to show'),
      'description' => $this
        ->t('Number of slides to show at a time. If 1, it will behave like slideshow, more than 1 a carousel. Provide more if it is a thumbnail navigation with asNavFor. Only works with odd number slidesToShow counts when using centerMode (e.g.: 3, 5, 7, etc.). Not-compatible with variableWidth.'),
    ];
    $elements['slidesToScroll'] = [
      'type' => 'number',
      'title' => $this
        ->t('Slides to scroll'),
      'description' => $this
        ->t('Number of slides to scroll at a time, or steps at each scroll.'),
    ];
    $elements['speed'] = [
      'type' => 'number',
      'title' => $this
        ->t('Speed'),
      'description' => $this
        ->t('Slide/Fade animation speed in milliseconds.'),
      'field_suffix' => 'ms',
    ];
    $elements['swipe'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Swipe'),
      'description' => $this
        ->t('Enable swiping.'),
    ];
    $elements['swipeToSlide'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Swipe to slide'),
      'description' => $this
        ->t('Allow users to drag or swipe directly to a slide irrespective of slidesToScroll.'),
    ];
    $elements['edgeFriction'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('Edge friction'),
      'description' => $this
        ->t("Resistance when swiping edges of non-infinite carousels. If you don't want resistance, set it to 1."),
    ];
    $elements['touchMove'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Touch move'),
      'description' => $this
        ->t('Enable slide motion with touch.'),
    ];
    $elements['touchThreshold'] = [
      'type' => 'number',
      'title' => $this
        ->t('Touch threshold'),
      'description' => $this
        ->t('Swipe distance threshold.'),
    ];
    $elements['useCSS'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Use CSS'),
      'description' => $this
        ->t('Enable/disable CSS transitions.'),
    ];
    $elements['cssEase'] = [
      'type' => 'textfield',
      'title' => $this
        ->t('CSS ease'),
      'description' => $this
        ->t('CSS3 animation easing. <a href="@ceaser">Learn</a> <a href="@bezier">more</a>. Ignored if <strong>CSS ease override</strong> is provided.', [
        '@ceaser' => '//matthewlein.com/ceaser/',
        '@bezier' => '//cubic-bezier.com',
      ]),
    ];
    $elements['cssEaseBezier'] = [
      'type' => 'hidden',
    ];
    $elements['cssEaseOverride'] = [
      'title' => $this
        ->t('CSS ease override'),
      'type' => 'select',
      'options' => $this
        ->getCssEasingOptions(),
      'empty_option' => $this
        ->t('- None -'),
      'description' => $this
        ->t('If provided, this will override the CSS ease with the pre-defined CSS easings based on <a href="@ceaser">CSS Easing Animation Tool</a>. Leave it empty to use your own CSS ease.', [
        '@ceaser' => 'http://matthewlein.com/ceaser/',
      ]),
    ];
    $elements['useTransform'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Use CSS Transforms'),
      'description' => $this
        ->t('Enable/disable CSS transforms.'),
    ];
    $elements['easing'] = [
      'title' => $this
        ->t('jQuery easing'),
      'type' => 'select',
      'options' => $this
        ->getJsEasingOptions(),
      'empty_option' => $this
        ->t('- None -'),
      'description' => $this
        ->t('Add easing for jQuery animate as fallback. Use with <a href="@easing">easing</a> libraries or default easing methods. Optionally install <a href="@jqeasing">jqeasing module</a>. This will be ignored and replaced by CSS ease for supporting browsers, or effective if useCSS is disabled.', [
        '@jqeasing' => '//drupal.org/project/jqeasing',
        '@easing' => '//gsgd.co.uk/sandbox/jquery/easing/',
      ]),
    ];
    $elements['variableWidth'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Variable width'),
      'description' => $this
        ->t('Disables automatic slide width calculation. Best with uniform image heights, use scale height image effect. Useless with adaptiveHeight, and non-uniform image heights. Useless with slidesToShow > 1 if the container is smaller than the amount of visible slides. Troubled with lazyLoad ondemand.'),
    ];
    $elements['vertical'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Vertical'),
      'description' => $this
        ->t('Vertical slide direction. See <a href="@url" target="_blank">relevant issue</a>.', [
        '@url' => '//github.com/kenwheeler/slick/issues/1001',
      ]),
    ];
    $elements['verticalSwiping'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Vertical swiping'),
      'description' => $this
        ->t('Changes swipe direction to vertical.'),
    ];
    $elements['waitForAnimate'] = [
      'type' => 'checkbox',
      'title' => $this
        ->t('Wait for animate'),
      'description' => $this
        ->t('Ignores requests to advance the slide while animating.'),
    ];

    // Defines the default values if available.
    $defaults = Slick::defaultSettings();
    foreach ($elements as $name => $element) {
      $default = $element['type'] == 'checkbox' ? FALSE : '';
      $elements[$name]['default'] = isset($defaults[$name]) ? $defaults[$name] : $default;
    }
    foreach (Slick::getDependentOptions() as $parent => $items) {
      foreach ($items as $name) {
        if (isset($elements[$name])) {
          $states = [
            'visible' => [
              ':input[name*="options[settings][' . $parent . ']"]' => [
                'checked' => TRUE,
              ],
            ],
          ];
          if (!isset($elements[$name]['states'])) {
            $elements[$name]['states'] = $states;
          }
          else {
            $elements[$name]['states'] = array_merge($elements[$name]['states'], $states);
          }
        }
      }
    }
    $this->formElements = $elements;
  }
  return $this->formElements;
}