You are here

public function BlazyAdminBase::mediaSwitchForm in Blazy 8

Same name and namespace in other branches
  1. 8.2 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::mediaSwitchForm()
  2. 7 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::mediaSwitchForm()

Returns re-usable media switch form elements.

1 call to BlazyAdminBase::mediaSwitchForm()
BlazyAdminFormatter::buildSettingsForm in src/Form/BlazyAdminFormatter.php
Defines re-usable form elements.

File

src/Form/BlazyAdminBase.php, line 499

Class

BlazyAdminBase
A base for blazy admin integration to have re-usable methods in one place.

Namespace

Drupal\blazy\Form

Code

public function mediaSwitchForm(array &$form, $definition = []) {
  $settings = isset($definition['settings']) ? $definition['settings'] : [];
  $lightboxes = $this->blazyManager
    ->getLightboxes();
  $is_token = function_exists('token_theme');
  if (isset($settings['media_switch'])) {
    $form['media_switch'] = $this
      ->baseForm($definition)['media_switch'];
    $form['media_switch']['#prefix'] = '<h3 class="form__title form__title--media-switch">' . $this
      ->t('Media switcher') . '</h3>';
    if (empty($definition['no_ratio'])) {
      $form['ratio'] = $this
        ->baseForm($definition)['ratio'];
    }
  }
  if (!empty($definition['multimedia']) && empty($definition['no_iframe_lazy'])) {
    $form['iframe_lazy'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Lazy iframe'),
      '#description' => $this
        ->t('Check to make the video/audio iframes truly lazyloaded, and speed up loading time. Depends on JS enabled at client side. <a href=":more" target="_blank">Read more</a> to <a href=":url" target="_blank">decide</a>.', [
        ':more' => '//goo.gl/FQLFQ6',
        ':url' => '//goo.gl/f78pMl',
      ]),
      '#weight' => -96,
      '#states' => $this
        ->getState(static::STATE_IFRAME_ENABLED, $definition),
    ];
  }

  // Optional lightbox integration.
  if (!empty($lightboxes) && isset($settings['media_switch'])) {
    $form['box_style'] = $this
      ->baseForm($definition)['box_style'];
    if (!empty($definition['multimedia'])) {
      $form['box_media_style'] = $this
        ->baseForm($definition)['box_media_style'];
    }
    $box_captions = [
      'auto' => $this
        ->t('Automatic'),
      'alt' => $this
        ->t('Alt text'),
      'title' => $this
        ->t('Title text'),
      'alt_title' => $this
        ->t('Alt and Title'),
      'title_alt' => $this
        ->t('Title and Alt'),
      'entity_title' => $this
        ->t('Content title'),
      'custom' => $this
        ->t('Custom'),
    ];
    if (!empty($definition['box_captions'])) {
      $form['box_caption'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Lightbox caption'),
        '#options' => $box_captions,
        '#weight' => -99,
        '#states' => $this
          ->getState(static::STATE_LIGHTBOX_ENABLED, $definition),
        '#description' => $this
          ->t('Automatic will search for Alt text first, then Title text. Try selecting <strong>- None -</strong> first when changing if trouble with form states.'),
      ];
      $form['box_caption_custom'] = [
        '#title' => $this
          ->t('Lightbox custom caption'),
        '#type' => 'textfield',
        '#weight' => -99,
        '#states' => $this
          ->getState(static::STATE_LIGHTBOX_CUSTOM, $definition),
        '#description' => $this
          ->t('Multi-value rich text field will be mapped to each image by its delta.'),
      ];
      if ($is_token) {
        $types = isset($definition['entity_type']) ? [
          $definition['entity_type'],
        ] : [];
        $types = isset($definition['target_type']) ? array_merge($types, [
          $definition['target_type'],
        ]) : $types;
        $form['box_caption_custom']['#field_suffix'] = [
          '#theme' => 'token_tree_link',
          '#text' => $this
            ->t('Tokens'),
          '#token_types' => $types,
        ];
      }
    }
  }
  $this->blazyManager
    ->getModuleHandler()
    ->alter('blazy_media_switch_form_element', $form, $definition);
}