You are here

public function FlickityGroupForm::form in Flickity Carousel 8

Same name and namespace in other branches
  1. 8.2 src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm::form()
  2. 3.0.x src/Form/FlickityGroupForm.php \Drupal\flickity\Form\FlickityGroupForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/FlickityGroupForm.php, line 22
Contains \Drupal\flickity\Form\FlickityGroupForm.

Class

FlickityGroupForm
Form controller for the group entity add/edit forms.

Namespace

Drupal\flickity\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $entity = $this->entity;
  $group = FlickityGroup::load('default_group');
  $settings = $group
    ->getSettings();
  if ($entity
    ->getSettings()) {
    $settings = $entity
      ->getSettings();
  }
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Group name'),
    '#default_value' => $entity
      ->label(),
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
    '#description' => $this
      ->t('The settings group identifier.'),
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $entity
      ->id(),
    '#required' => TRUE,
    '#disabled' => !$entity
      ->isNew(),
    '#size' => 30,
    '#maxlength' => 64,
    '#machine_name' => array(
      'exists' => [
        '\\Drupal\\flickity\\Entity\\FlickityGroup',
        'load',
      ],
    ),
  );

  // Setup
  $form['images_loaded'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('imagesLoaded'),
    '#default_value' => $settings['images_loaded'],
    '#description' => $this
      ->t('Unloaded images have no size, which can throw off cell positions. To fix this, the imagesLoaded option re-positions cells once their images have loaded.'),
  );
  $form['cell_selector'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Cell selector'),
    '#default_value' => $settings['cell_selector'],
    '#size' => 30,
    '#description' => $this
      ->t('Specify selector for cell elements. This is useful if you have other elements in your gallery elements that are not cells.'),
  );
  $form['initial_index'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Initial index'),
    '#default_value' => $settings['initial_index'],
    '#size' => 30,
    '#description' => $this
      ->t('Zero-based index of the initial selected cell.'),
  );
  $form['accessibility'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Accessibility'),
    '#default_value' => $settings['accessibility'],
    '#description' => $this
      ->t('Enable keyboard navigation. Users can tab to a Flickity gallery, and pressing left & right keys to change cells.'),
  );
  $form['set_gallery_size'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Set gallery size'),
    '#default_value' => $settings['set_gallery_size'],
    '#description' => $this
      ->t('Sets the height of the gallery to the height of the tallest cell.'),
  );
  $form['resize'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Resize'),
    '#default_value' => $settings['resize'],
    '#description' => $this
      ->t('Adjusts sizes and positions when window is resized.'),
  );

  // Cell position
  $form['cell_align'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Cell align'),
    '#default_value' => $settings['cell_align'],
    '#size' => 30,
    '#description' => $this
      ->t('Align cells within the gallery element.'),
  );
  $form['contain'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Contain'),
    '#default_value' => $settings['contain'],
    '#description' => $this
      ->t('Contains cells to gallery element to prevent excess scroll at beginning or end.'),
  );
  $form['percent_position'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Percent position'),
    '#default_value' => $settings['percent_position'],
    '#description' => $this
      ->t('Sets positioning in percent values, rather than pixel values.'),
  );
  $form['right_to_left'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Right to left'),
    '#default_value' => $settings['right_to_left'],
    '#description' => $this
      ->t('Enables right-to-left layout.'),
  );

  // Behavior
  $form['draggable'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Draggable'),
    '#default_value' => $settings['draggable'],
    '#description' => $this
      ->t('Enables dragging and flicking.'),
  );
  $form['free_scroll'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Free scroll'),
    '#default_value' => $settings['free_scroll'],
    '#description' => $this
      ->t('Enables content to be freely scrolled and flicked without aligning cells to an end position.'),
  );
  $form['wrap_around'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Wrap around'),
    '#default_value' => $settings['wrap_around'],
    '#description' => $this
      ->t('At the end of cells, wrap-around to the other end for infinite scrolling.'),
  );

  // @todo, provide additional field if #state is true.
  $form['lazy_load'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Lazy load'),
    '#default_value' => $settings['lazy_load'],
    '#description' => $this
      ->t('Loads cell images when a cell is selected.'),
  );

  // @todo, provide additional field if #state is true.
  $form['auto_play'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Auto play'),
    '#default_value' => $settings['auto_play'],
    '#description' => $this
      ->t('Auto-playing will pause when mouse is hovered over, and resume when mouse is hovered off. Auto-playing will stop when the gallery is clicked or a cell is selected.'),
  );

  // Extra
  $form['watch_css'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Watch CSS'),
    '#default_value' => $settings['watch_css'],
    '#description' => $this
      ->t('You can enable and disable Flickity with CSS. watchCSS option watches the content of :after of the gallery element. Flickity is enabled if :after content is flickity.'),
  );
  $form['as_nav_for'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('As nav for'),
    '#default_value' => $settings['as_nav_for'],
    '#size' => 30,
    '#description' => $this
      ->t('Use one Flickity gallery as navigation for another. This can be set a selector string'),
  );

  // Display
  $form['selected_attraction'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Selected attraction'),
    '#default_value' => $settings['selected_attraction'],
    '#size' => 30,
    '#description' => $this
      ->t('Attracts the position of the slider to the selected cell. Higher attraction makes the slider move faster.'),
  );
  $form['friction'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Friction'),
    '#default_value' => $settings['friction'],
    '#size' => 30,
    '#description' => $this
      ->t('Slows the movement of slider. Higher friction makes the slider feel stickier and less bouncy. Lower friction makes the slider feel looser and more wobbly.'),
  );
  $form['free_scroll_friction'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Free scroll friction'),
    '#default_value' => $settings['free_scroll_friction'],
    '#size' => 30,
    '#description' => $this
      ->t('Slows movement of slider when freeScroll: true. Higher friction makes the slider feel stickier. Lower friction makes the slider feel looser.'),
  );

  // UI
  $form['prev_next_buttons'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Previous next buttons'),
    '#default_value' => $settings['prev_next_buttons'],
    '#description' => $this
      ->t('Creates and enables previous & next buttons.'),
  );
  $form['page_dots'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Page dots'),
    '#default_value' => $settings['page_dots'],
    '#description' => $this
      ->t('Creates and enables page dots.'),
  );
  return parent::form($form, $form_state, $entity);
}