You are here

public function VariantPluginConfigureBlockFormBase::buildForm in Page Manager 8

Same name and namespace in other branches
  1. 8.4 page_manager_ui/src/Form/VariantPluginConfigureBlockFormBase.php \Drupal\page_manager_ui\Form\VariantPluginConfigureBlockFormBase::buildForm()

Form constructor.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

1 call to VariantPluginConfigureBlockFormBase::buildForm()
VariantPluginAddBlockForm::buildForm in page_manager_ui/src/Form/VariantPluginAddBlockForm.php
Form constructor.
1 method overrides VariantPluginConfigureBlockFormBase::buildForm()
VariantPluginAddBlockForm::buildForm in page_manager_ui/src/Form/VariantPluginAddBlockForm.php
Form constructor.

File

page_manager_ui/src/Form/VariantPluginConfigureBlockFormBase.php, line 107
Contains \Drupal\page_manager_ui\Form\VariantPluginConfigureBlockFormBase.

Class

VariantPluginConfigureBlockFormBase
Provides a base form for configuring a block as part of a variant.

Namespace

Drupal\page_manager_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $block_display = NULL, $block_id = NULL) {
  $cached_values = $this->tempstore
    ->get('page_manager.block_display')
    ->get($block_display);

  /** @var \Drupal\page_manager\Plugin\DisplayVariant\PageBlockDisplayVariant $variant_plugin */
  $this->variantPlugin = $cached_values['plugin'];

  // Rehydrate the contexts on this end.
  $contexts = [];

  /**
   * @var string $context_name
   * @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition
   */
  foreach ($cached_values['contexts'] as $context_name => $context_definition) {
    $contexts[$context_name] = new Context($context_definition);
  }
  $this->variantPlugin
    ->setContexts($contexts);
  $this->block = $this
    ->prepareBlock($block_id);
  $form_state
    ->set('variant_id', $this
    ->getVariantPlugin()
    ->id());
  $form_state
    ->set('block_id', $this->block
    ->getConfiguration()['uuid']);
  $form['#tree'] = TRUE;
  $form['settings'] = $this->block
    ->buildConfigurationForm([], $form_state);
  $form['settings']['id'] = [
    '#type' => 'value',
    '#value' => $this->block
      ->getPluginId(),
  ];
  $form['region'] = [
    '#title' => $this
      ->t('Region'),
    '#type' => 'select',
    '#options' => $this
      ->getVariantPlugin()
      ->getRegionNames(),
    '#default_value' => $this
      ->getVariantPlugin()
      ->getRegionAssignment($this->block
      ->getConfiguration()['uuid']),
    '#required' => TRUE,
  ];
  if ($this->block instanceof ContextAwarePluginInterface) {
    $form['context_mapping'] = $this
      ->addContextAssignmentElement($this->block, $this
      ->getVariantPlugin()
      ->getContexts());
  }
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->submitText(),
    '#button_type' => 'primary',
  ];
  return $form;
}