You are here

protected function Classes::classesElement in GridStack 8.2

1 call to Classes::classesElement()
Form::wrapperForm in src/Plugin/gridstack/stylizer/Form.php

File

src/Plugin/gridstack/stylizer/Classes.php, line 72

Class

Classes
Provides the classes styles.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function classesElement($optionset, FormStateInterface $form_state, array $settings, array $extras = []) {
  $context = $settings['_scope'];
  $container = !empty($settings['_container']);
  $element = [];
  $wrapper_classes = [];
  $wrapper_class_value = trim($settings['wrapper_classes']);
  if ($wrapper_class_value) {
    $wrapper_classes = array_filter(array_map('trim', explode(" ", $wrapper_class_value)));
  }
  if ($classes = $this->manager
    ->getMergedClasses(FALSE)) {

    // Saves headaches from problematic options.
    $problems = [
      'hidden',
      'visible',
      'visibility',
      'height',
    ];
    foreach ($classes as $key => $options) {

      // Hiding the entire container is likely out of questions, skip.
      if ($container && in_array($key, $problems)) {
        continue;
      }

      // JS-driven layouts have pre-defined fixed heights, skip.
      if (!$optionset
        ->isFramework() && strpos($key, 'height') !== FALSE) {
        continue;
      }
      $refined_options = $this
        ->getPresetOptions($options);
      $element[$key] = $this
        ->classElement($key, $options, $refined_options, $context, $wrapper_classes);
      $element[$key]['#attributes']['class'][] = $optionset
        ->isFramework() ? 'is-gs-css-driven' : 'is-gs-js-driven';
      if ($framework = $this->manager
        ->engineManager()
        ->framework()) {
        if (in_array($key, $framework
          ->previewOptions())) {
          $element[$key]['#is_preview'] = TRUE;
          $element[$key]['#attributes']['class'][] = 'form-wrapper--preview';
          if (in_array($key, [
            'rounded',
            'text_color',
          ])) {
            $element[$key]['#attributes']['class'][] = 'form-wrapper--bg';
          }
        }
      }
    }
  }
  return $element;
}