You are here

public function SlickFormBase::form in Slick Carousel 8

Same name and namespace in other branches
  1. 8.2 slick_ui/src/Form/SlickFormBase.php \Drupal\slick_ui\Form\SlickFormBase::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

1 call to SlickFormBase::form()
SlickForm::form in slick_ui/src/Form/SlickForm.php
Gets the actual form array to be built.
1 method overrides SlickFormBase::form()
SlickForm::form in slick_ui/src/Form/SlickForm.php
Gets the actual form array to be built.

File

slick_ui/src/Form/SlickFormBase.php, line 75

Class

SlickFormBase
Provides base form for a slick instance configuration form.

Namespace

Drupal\slick_ui\Form

Code

public function form(array $form, FormStateInterface $form_state) {

  // Change page title for the duplicate operation.
  if ($this->operation == 'duplicate') {
    $form['#title'] = $this
      ->t('<em>Duplicate slick optionset</em>: @label', [
      '@label' => $this->entity
        ->label(),
    ]);
    $this->entity = $this->entity
      ->createDuplicate();
  }

  // Change page title for the edit operation.
  if ($this->operation == 'edit') {
    $form['#title'] = $this
      ->t('<em>Edit slick optionset</em>: @label', [
      '@label' => $this->entity
        ->label(),
    ]);
  }
  $slick = $this->entity;
  $path = drupal_get_path('module', 'slick');
  $tooltip = [
    'class' => [
      'is-tooltip',
    ],
  ];
  $readme = Url::fromUri('base:' . $path . '/README.md')
    ->toString();
  $admin_css = $this->manager
    ->configLoad('admin_css', 'blazy.settings');
  $form['#attributes']['class'][] = 'form--slick';
  $form['#attributes']['class'][] = 'form--blazy';
  $form['#attributes']['class'][] = 'form--optionset';
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#default_value' => $slick
      ->label(),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#description' => $this
      ->t("Label for the Slick optionset."),
    '#attributes' => $tooltip,
    '#prefix' => '<div class="form__header form__half form__half--first has-tooltip clearfix">',
  ];

  // Keep the legacy CTools ID, i.e.: name as ID.
  $form['name'] = [
    '#type' => 'machine_name',
    '#default_value' => $slick
      ->id(),
    '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    '#machine_name' => [
      'source' => [
        'label',
      ],
      'exists' => '\\Drupal\\slick\\Entity\\Slick::load',
    ],
    '#attributes' => $tooltip,
    '#disabled' => !$slick
      ->isNew(),
    '#suffix' => '</div>',
  ];
  $form['skin'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Skin'),
    '#options' => $this->admin
      ->getSkinsByGroupOptions(),
    '#empty_option' => $this
      ->t('- None -'),
    '#default_value' => $slick
      ->getSkin(),
    '#description' => $this
      ->t('Skins allow swappable layouts like next/prev links, split image and caption, etc. However a combination of skins and options may lead to unpredictable layouts, get yourself dirty. See main <a href="@url">README</a> for details on Skins. Only useful for custom work, and ignored/overridden by slick formatters or sub-modules.', [
      '@url' => $readme,
    ]),
    '#attributes' => $tooltip,
    '#prefix' => '<div class="form__header form__half form__half--last has-tooltip clearfix">',
  ];
  $form['group'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Group'),
    '#options' => [
      'main' => $this
        ->t('Main'),
      'overlay' => $this
        ->t('Overlay'),
      'thumbnail' => $this
        ->t('Thumbnail'),
    ],
    '#empty_option' => $this
      ->t('- None -'),
    '#default_value' => $slick
      ->getGroup(),
    '#description' => $this
      ->t('Group this optionset to avoid confusion for optionset selections. Leave empty to make it available for all.'),
    '#attributes' => $tooltip,
  ];
  $form['breakpoints'] = [
    '#title' => $this
      ->t('Breakpoints'),
    '#type' => 'textfield',
    '#default_value' => $form_state
      ->hasValue('breakpoints') ? $form_state
      ->getValue('breakpoints') : $slick
      ->getBreakpoints(),
    '#description' => $this
      ->t('The number of breakpoints added to Responsive display, max 9. This is not Breakpoint Width (480px, etc).'),
    '#ajax' => [
      'callback' => '::addBreakpoints',
      'wrapper' => 'edit-breakpoints-ajax-wrapper',
      'event' => 'change',
      'progress' => [
        'type' => 'fullscreen',
      ],
      'effect' => 'fade',
      'speed' => 'fast',
    ],
    '#attributes' => $tooltip,
    '#maxlength' => 1,
  ];
  $form['optimized'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Optimized'),
    '#default_value' => $slick
      ->optimized(),
    '#description' => $this
      ->t('Check to optimize the stored options. Anything similar to defaults will not be stored, except those required by sub-modules and theme_slick(). Like you hand-code/ cherry-pick the needed options, and are smart enough to not repeat defaults, and free up memory. The rest are taken care of by JS. Uncheck only if theme_slick() can not satisfy the needs, and more hand-coded preprocess is needed which is less likely in most cases.'),
    '#access' => $slick
      ->id() != 'default',
    '#attributes' => $tooltip,
    '#wrapper_attributes' => [
      'class' => [
        'form-item--tooltip-wide',
      ],
    ],
  ];
  if ($slick
    ->id() == 'default') {
    $form['breakpoints']['#suffix'] = '</div>';
  }
  else {
    $form['optimized']['#suffix'] = '</div>';
  }
  if ($admin_css) {
    $form['optimized']['#field_suffix'] = '&nbsp;';
    $form['optimized']['#title_display'] = 'before';
  }
  return parent::form($form, $form_state);
}