You are here

public function SlickAdmin::openingForm in Slick Carousel 8.2

Same name and namespace in other branches
  1. 8 src/Form/SlickAdmin.php \Drupal\slick\Form\SlickAdmin::openingForm()
  2. 7.3 src/Form/SlickAdmin.php \Drupal\slick\Form\SlickAdmin::openingForm()

Returns the opening form elements.

1 call to SlickAdmin::openingForm()
SlickAdmin::buildSettingsForm in src/Form/SlickAdmin.php
Returns the main form elements.

File

src/Form/SlickAdmin.php, line 120

Class

SlickAdmin
Provides resusable admin functions, or form elements.

Namespace

Drupal\slick\Form

Code

public function openingForm(array &$form, &$definition = []) {
  $path = drupal_get_path('module', 'slick');
  $is_slick_ui = $this
    ->manager()
    ->getModuleHandler()
    ->moduleExists('slick_ui');
  $is_help = $this
    ->manager()
    ->getModuleHandler()
    ->moduleExists('help');
  $route_name = [
    'name' => 'slick_ui',
  ];
  $readme = $is_slick_ui && $is_help ? Url::fromRoute('help.page', $route_name)
    ->toString() : Url::fromUri('base:' . $path . '/docs/README.md')
    ->toString();
  $readme_field = $is_slick_ui && $is_help ? Url::fromRoute('help.page', $route_name)
    ->toString() : Url::fromUri('base:' . $path . '/docs/FORMATTER.md')
    ->toString();
  $arrows = $this
    ->getSkinsByGroupOptions('arrows');
  $dots = $this
    ->getSkinsByGroupOptions('dots');
  $this->blazyAdmin
    ->openingForm($form, $definition);
  if (isset($form['optionset'])) {
    $form['optionset']['#title'] = $this
      ->t('Optionset main');
    if ($is_slick_ui) {
      $route_name = 'entity.slick.collection';
      $form['optionset']['#description'] = $this
        ->t('Manage optionsets at <a href=":url" target="_blank">the optionset admin page</a>.', [
        ':url' => Url::fromRoute($route_name)
          ->toString(),
      ]);
    }
  }
  if (!empty($definition['nav']) || !empty($definition['thumbnails'])) {
    $form['optionset_thumbnail'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Optionset thumbnail'),
      '#options' => $this
        ->getOptionsetsByGroupOptions('thumbnail'),
      '#description' => $this
        ->t('If provided, asNavFor aka thumbnail navigation applies. Leave empty to not use thumbnail navigation.'),
      '#weight' => -108,
    ];
    $form['skin_thumbnail'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Skin thumbnail'),
      '#options' => $this
        ->getSkinsByGroupOptions('thumbnail'),
      '#description' => $this
        ->t('Thumbnail navigation skin. See main <a href="@url" target="_blank">README</a> for details on Skins. Leave empty to not use thumbnail navigation.', [
        '@url' => $readme,
      ]),
      '#weight' => -106,
    ];
  }
  if (count($arrows) > 0 && empty($definition['no_arrows'])) {
    $form['skin_arrows'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Skin arrows'),
      '#options' => $arrows,
      '#enforced' => TRUE,
      '#description' => $this
        ->t('Check out slick.api.php to add your own skins.'),
      '#weight' => -105,
    ];
  }
  if (count($dots) > 0 && empty($definition['no_dots'])) {
    $form['skin_dots'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Skin dots'),
      '#options' => $dots,
      '#enforced' => TRUE,
      '#description' => $this
        ->t('Check out slick.api.php to add your own skins.'),
      '#weight' => -105,
    ];
  }
  if (empty($definition['_views'])) {
    $form['use_theme_field'] = [
      '#title' => $this
        ->t('Use field template'),
      '#type' => 'checkbox',
      '#description' => $this
        ->t('Wrap Slick field output into regular field markup (field.html.twig). Vanilla output otherwise.'),
      '#weight' => -106,
    ];
  }
  if (!empty($definition['thumb_positions'])) {
    $form['thumbnail_position'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Thumbnail position'),
      '#options' => [
        'left' => $this
          ->t('Left'),
        'right' => $this
          ->t('Right'),
        'top' => $this
          ->t('Top'),
        'over-left' => $this
          ->t('Overlay left'),
        'over-right' => $this
          ->t('Overlay right'),
        'over-top' => $this
          ->t('Overlay top'),
      ],
      '#description' => $this
        ->t('By default thumbnail is positioned at bottom. Hence to change the position of thumbnail. Only reasonable with 1 visible main stage at a time. Except any TOP, the rest requires Vertical option enabled for Optionset thumbnail, and a custom CSS height to selector <strong>.slick--thumbnail</strong> to avoid overflowing tall thumbnails, or adjust <strong>slidesToShow</strong> to fit the height. Further theming is required as usual. Overlay is absolutely positioned over the stage rather than sharing the space. See skin <strong>X VTabs</strong> for vertical thumbnail sample.'),
      '#states' => [
        'visible' => [
          'select[name*="[optionset_thumbnail]"]' => [
            '!value' => '',
          ],
        ],
      ],
      '#weight' => -99,
    ];
  }
  if (!empty($definition['thumb_captions'])) {
    $form['thumbnail_caption'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Thumbnail caption'),
      '#options' => $definition['thumb_captions'],
      '#description' => $this
        ->t('Thumbnail caption maybe just title/ plain text. If Thumbnail image style is not provided, the thumbnail pagers will be just text like regular tabs.'),
      '#states' => [
        'visible' => [
          'select[name*="[optionset_thumbnail]"]' => [
            '!value' => '',
          ],
        ],
      ],
      '#weight' => 2,
    ];
  }
  if (isset($form['skin'])) {
    $form['skin']['#title'] = $this
      ->t('Skin main');
    $form['skin']['#description'] = $this
      ->t('Skins allow various layouts with just CSS. Some options below depend on a skin. However a combination of skins and options may lead to unpredictable layouts, get yourself dirty. E.g.: Skin Split requires any split layout option. Failing to choose the expected layout makes it useless. See <a href=":url" target="_blank">SKINS section at README</a> for details on Skins. Leave empty to DIY. Skins are permanently cached. Clear cache if new skins do not appear. Check out slick.api.php to add your own skins.', [
      ':url' => $readme,
    ]);
  }
  if (isset($form['layout'])) {
    $form['layout']['#description'] = $this
      ->t('Requires a skin. The builtin layouts affects the entire slides uniformly. Split half requires any skin Split. See <a href="@url" target="_blank">README</a> under "Slide layout" for more info. Leave empty to DIY.', [
      '@url' => $readme_field,
    ]);
  }
  $weight = -99;
  foreach (Element::children($form) as $key) {
    if (!isset($form[$key]['#weight'])) {
      $form[$key]['#weight'] = ++$weight;
    }
  }
}