You are here

public function PatternDisplayFormTrait::buildPatternDisplayForm in UI Patterns 8

Build pattern display form.

Parameters

array $form: Form array.

string $tag: Source field tag.

array $context: Plugin context.

array $configuration: Default configuration coming form the host form.

3 calls to PatternDisplayFormTrait::buildPatternDisplayForm()
Pattern::alterForm in modules/ui_patterns_ds/src/Plugin/DsFieldTemplate/Pattern.php
Pattern::buildOptionsForm in modules/ui_patterns_views/src/Plugin/views/row/Pattern.php
Provide a form for setting options.
PatternFormatter::settingsForm in modules/ui_patterns_field_group/src/Plugin/field_group/FieldGroupFormatter/PatternFormatter.php

File

src/Form/PatternDisplayFormTrait.php, line 32

Class

PatternDisplayFormTrait
Trait PatternDisplayFormTrait.

Namespace

Drupal\ui_patterns\Form

Code

public function buildPatternDisplayForm(array &$form, $tag, array $context, array $configuration) {
  $form['pattern'] = [
    '#type' => 'select',
    '#empty_value' => '_none',
    '#title' => $this
      ->t('Pattern'),
    '#options' => $this->patternsManager
      ->getPatternsOptions(),
    '#default_value' => isset($configuration['pattern']) ? $configuration['pattern'] : NULL,
    '#required' => TRUE,
    '#attributes' => [
      'id' => 'patterns-select',
    ],
  ];
  $form['variants'] = [
    '#type' => 'container',
  ];

  /** @var \Drupal\ui_patterns\Definition\PatternDefinition $definition */
  foreach ($this->patternsManager
    ->getDefinitions() as $pattern_id => $definition) {
    if ($definition
      ->hasVariants()) {
      $form['variants'][$pattern_id] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Variant'),
        '#options' => $definition
          ->getVariantsAsOptions(),
        '#default_value' => isset($configuration['pattern_variant']) ? $configuration['pattern_variant'] : NULL,
        '#weight' => 0,
        '#states' => [
          'visible' => [
            'select[id="patterns-select"]' => [
              'value' => $pattern_id,
            ],
          ],
        ],
      ];
    }
    $form['pattern_mapping'][$pattern_id] = [
      '#type' => 'container',
      '#weight' => 1,
      '#states' => [
        'visible' => [
          'select[id="patterns-select"]' => [
            'value' => $pattern_id,
          ],
        ],
      ],
      'settings' => $this
        ->getMappingForm($pattern_id, $tag, $context, $configuration),
    ];
  }
  $this->moduleHandler
    ->alter('ui_patterns_display_settings_form', $form, $configuration);
}