You are here

protected function Form::styleForm in GridStack 8.2

1 call to Form::styleForm()
Form::buildConfigurationForm in src/Plugin/gridstack/stylizer/Form.php

File

src/Plugin/gridstack/stylizer/Form.php, line 395

Class

Form
Provides the form elements.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function styleForm($optionset, FormStateInterface $form_state, array $settings, array $extras = []) {
  $element = [];
  $styles = $settings;
  $context = $settings['_scope'];
  foreach (GridStackDefault::styleSettings() as $key => $value) {
    $default = isset($settings['styles'][$key]) ? $settings['styles'][$key] : $value;
    if ($context == GridStackDefault::ROOT) {
      $name = [
        'settings',
        'styles',
        $key,
      ];
    }
    else {
      $name = [
        'regions',
        $context,
        'styles',
        $key,
      ];
    }
    $styles[$key] = $form_state
      ->getValue($name, $default);
  }
  $element['styles'] = [
    '#type' => 'details',
    '#tree' => TRUE,
    '#title' => $this
      ->t('Styles'),
  ];
  $exists = $this->manager
    ->getModuleHandler()
    ->moduleExists('media_library');
  if ($exists && !empty($settings['field_name'])) {
    $styles['field_name'] = $settings['field_name'];
    if ($options = $this
      ->getResponsiveImageOptions()) {
      $value = isset($styles['responsive_image_style']) ? $styles['responsive_image_style'] : '';
      $element['styles']['responsive_image_style'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Responsive Image'),
        '#options' => $options,
        '#empty_option' => $this
          ->t('- None -'),
        '#default_value' => $value,
        '#wrapper_attributes' => [
          'class' => [
            'form-item--resimage',
          ],
        ],
      ];
    }
    if (!empty($settings['access_media'])) {
      $this
        ->mediaElement($element['styles'], $optionset, $form_state, $styles, $extras);
    }
  }

  // Provides ranges and colors.
  $element['styles'] = array_merge($element['styles'], $this
    ->rangeElement($styles));
  $element['styles']['colors'] = [];
  $element['styles']['colors'] = array_merge($element['styles']['colors'], $this
    ->colorElement($optionset, $form_state, $styles, $extras));

  // Provides extras.
  $element['styles']['extras'] = [];
  $element['styles']['extras'] = array_merge($element['styles']['extras'], $this
    ->extrasElement($optionset, $form_state, $styles, $extras));

  // Provides extras.
  if (!$this
    ->config('animationless')) {
    $element['styles']['animations'] = [];
    $element['styles']['animations'] = array_merge($element['styles']['animations'], $this
      ->animationElement($optionset, $form_state, $styles, $extras));
  }
  return $element;
}