You are here

public function ElevateZoomPlusManager::formElementAlter in ElevateZoom Plus 7

Same name and namespace in other branches
  1. 8 src/ElevateZoomPlusManager.php \Drupal\elevatezoomplus\ElevateZoomPlusManager::formElementAlter()

Implements hook_blazy_form_element_alter().

File

src/ElevateZoomPlusManager.php, line 93

Class

ElevateZoomPlusManager
Provides ElevateZoom Plus library methods mainly for hooks.

Namespace

Drupal\elevatezoomplus

Code

public function formElementAlter(array &$form, array $definition = []) {
  $field_type = isset($definition['field_type']) ? $definition['field_type'] : '';
  $settings = $definition['settings'];
  $applicable = $field_type && in_array($field_type, [
    'file',
    'image',
  ]);

  // Exclude from blazy text formatters, or blazy views grid.
  if (empty($definition['no_image_style']) && !isset($settings['grouping'])) {
    $optionsets = ElevateZoomPlus::loadMultiple();
    $elevatezoomplus = [
      '#type' => 'select',
      '#title' => t('ElevateZoom Plus'),
      '#options' => $this->manager
        ->getOptionsetOptions($optionsets),
      '#empty_option' => t('- None -'),
      '#default_value' => isset($settings['elevatezoomplus']) ? $settings['elevatezoomplus'] : '',
      '#description' => t('Choose an optionset.'),
      '#weight' => -98.98999999999999,
      '#enforce' => FALSE,
    ];

    // Hooks into Blazy UI to support Blazy Filter.
    if (isset($settings['admin_css'])) {
      $form['extras']['#access'] = TRUE;
      $form['extras']['elevatezoomplus'] = $elevatezoomplus;
      $form['extras']['elevatezoomplus']['#default_value'] = isset($settings['extras']['elevatezoomplus']) ? $settings['extras']['elevatezoomplus'] : '';
      $form['extras']['elevatezoomplus']['#description'] .= ' ' . t('Blazy Filter only. Warning! Not working nicely. This needs extra image styles which are lacking with inline images.');
    }
    else {
      if ($applicable) {
        $form['elevatezoomplus'] = $elevatezoomplus;
        $form['elevatezoomplus']['#description'] .= ' ' . t('Requires any lightbox (<b>not: Image to iFrame, Image linked to content, Image rendered</b>) for <b>Media switcher</b> if using Slick Carousel with asNavFor. If not, be sure to choose only <b>Image to Elevatezoomplus</b>.');
        if ($this->manager
          ->config('admin_css', TRUE, 'blazy.settings')) {
          $form['closing']['#attached']['library'][] = [
            'elevatezoomplus',
            'admin',
          ];
        }
      }
    }
  }
}