You are here

protected function ElevateZoomPlusForm::attachSettingsForm in ElevateZoom Plus 7

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

Attach the settings form.

1 call to ElevateZoomPlusForm::attachSettingsForm()
ElevateZoomPlusForm::edit_form in modules/ui/src/Form/ElevateZoomPlusForm.php
Provide the actual editing form.

File

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

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
    ->config('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';
    }
    $form[$name]['#attributes']['data-blazy-form-item'] = drupal_strtolower(str_replace('_', '-', $name));
  }
  return $form;
}