You are here

public function PatternLayout::buildConfigurationForm in UI Patterns 8

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides LayoutDefault::buildConfigurationForm

File

modules/ui_patterns_layouts/src/Plugin/Layout/PatternLayout.php, line 120

Class

PatternLayout
Class LayoutDefault.

Namespace

Drupal\ui_patterns_layouts\Plugin\Layout

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $configuration = $this
    ->getConfiguration();
  $form = [];
  $form['pattern'] = [
    '#group' => 'additional_settings',
    '#type' => 'details',
    '#title' => $this
      ->t('Pattern settings'),
    '#tree' => TRUE,
  ];
  $form['pattern']['field_templates'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Field templates'),
    '#options' => [
      'default' => $this
        ->t("Default"),
      'only_content' => $this
        ->t("Only content"),
    ],
    '#description' => implode('<br/>', [
      $this
        ->t("<b>Default</b>: use field templates to wrap field content."),
      $this
        ->t("<b>Only content</b>: only print field content, without field wrapping or label."),
    ]),
    '#default_value' => $configuration['pattern']['field_templates'],
  ];
  $pattern_id = $this
    ->getPluginDefinition()
    ->get('additional')['pattern'];
  $definition = $this->patternManager
    ->getDefinition($pattern_id);
  if ($definition
    ->hasVariants()) {
    $form['pattern']['variant'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Variant'),
      '#options' => $definition
        ->getVariantsAsOptions(),
      '#default_value' => $configuration['pattern']['variant'],
    ];
  }
  $this->moduleHandler
    ->alter('ui_patterns_layouts_display_settings_form', $form['pattern'], $definition, $configuration);
  return $form;
}