You are here

protected function Animation::animationElement in GridStack 8.2

Provides animation form elements.

1 call to Animation::animationElement()
Form::styleForm in src/Plugin/gridstack/stylizer/Form.php

File

src/Plugin/gridstack/stylizer/Animation.php, line 103

Class

Animation
Provides the animations.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function animationElement($optionset, FormStateInterface $form_state, array $settings, array $extras = []) {
  $element = [];
  $context = $settings['_scope'];
  $options = array_combine(static::animations(), static::animations());
  $selector = '.b-gs';
  $element = [
    '#type' => 'details',
    '#open' => FALSE,
    '#tree' => TRUE,
    '#title' => $this
      ->t('Animation'),
    '#attributes' => [
      'class' => [
        'form-wrapper--animations',
      ],
    ],
  ];
  $animations = $settings['animations'];
  $attributes = [
    'data-gs-animation-region' => $context,
    'data-gs-target-selector' => $selector,
  ];
  $element['animation'] = [
    '#type' => 'select',
    '#options' => $options,
    '#title' => $this
      ->t('Requires animate.css, blazy:2.1+.'),
    '#default_value' => isset($animations['animation']) ? $animations['animation'] : '',
    '#empty_option' => $this
      ->t('- None -'),
    '#attributes' => $attributes,
  ];
  $element['animation']['#attributes']['class'][] = 'form-select--gs form-select--gs-animation';
  foreach ([
    'duration',
    'delay',
    'iteration_count',
  ] as $key) {
    $title = str_replace('_', ' ', $key);
    $css = str_replace('_', '-', $key);
    $element[$key] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('@title', [
        '@title' => ucwords($title),
      ]),
      '#default_value' => isset($animations[$key]) ? $animations[$key] : '',
      '#description' => $this
        ->t('E.g.: 3s for 3 seconds.'),
      '#attributes' => $attributes,
    ];
    $element[$key]['#attributes']['class'][] = 'form-text--gs form-text--gs-' . $css;
    $element[$key]['#attributes']['data-gs-animation-key'] = $css;
    if ($key == 'iteration_count') {
      $element[$key]['#description'] = $this
        ->t('Any number, or <code>infinite</code> to loop.');
    }
  }
  return $element;
}