You are here

protected function ElevateZoomPlusForm::attachSettingsForm in ElevateZoom Plus 8

Same name and namespace in other branches
  1. 7 modules/ui/src/Form/ElevateZoomPlusForm.php \Drupal\elevatezoomplus_ui\Form\ElevateZoomPlusForm::attachSettingsForm()

Attach the settings form.

1 call to ElevateZoomPlusForm::attachSettingsForm()
ElevateZoomPlusForm::form in modules/ui/src/Form/ElevateZoomPlusForm.php
Gets the actual form array to be built.

File

modules/ui/src/Form/ElevateZoomPlusForm.php, line 248

Class

ElevateZoomPlusForm
Extends base form for elevatezoomplus instance configuration form.

Namespace

Drupal\elevatezoomplus_ui\Form

Code

protected function attachSettingsForm($settings = [], $excludes = []) {
  $admin_css = $this->manager
    ->configLoad('admin_css', 'blazy.settings');
  $form = [];
  foreach ($this
    ->getFormElements() as $name => $element) {
    if ($excludes && in_array($name, $excludes)) {
      continue;
    }
    $element['default'] = isset($element['default']) ? $element['default'] : '';
    $form[$name] = [
      '#title' => isset($element['title']) ? $element['title'] : '',
      '#default_value' => isset($settings[$name]) ? $settings[$name] : $element['default'],
    ];
    if (isset($element['type'])) {
      $form[$name]['#type'] = $element['type'];
      if ($element['type'] != 'hidden') {
        $form[$name]['#attributes']['class'][] = 'is-tooltip';
      }
      else {

        // Ensures hidden element doesn't screw up the states.
        unset($element['states']);
      }
      if ($element['type'] == 'textfield') {
        $form[$name]['#size'] = 20;
        $form[$name]['#maxlength'] = 255;
      }
    }
    $items = [
      'access',
      'description',
      'field_suffix',
      'options',
      'empty_option',
      'states',
    ];
    foreach ($items as $key) {
      if (isset($element[$key])) {
        $form[$name]['#' . $key] = $element[$key];
      }
    }
    if (is_int($element['default'])) {
      $form[$name]['#maxlength'] = 60;
      $form[$name]['#attributes']['class'][] = 'form-text--int';
    }
    if ($admin_css && is_bool($element['default'])) {
      $form[$name]['#field_suffix'] = ' ';
      $form[$name]['#title_display'] = 'before';
    }
  }
  return $form;
}