You are here

public function PanelsBlockConfigureFormBase::buildForm in Panels 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/PanelsBlockConfigureFormBase.php \Drupal\panels\Form\PanelsBlockConfigureFormBase::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 PanelsBlockConfigureFormBase::buildForm()
PanelsAddBlockForm::buildForm in src/Form/PanelsAddBlockForm.php
Form constructor.
1 method overrides PanelsBlockConfigureFormBase::buildForm()
PanelsAddBlockForm::buildForm in src/Form/PanelsAddBlockForm.php
Form constructor.

File

src/Form/PanelsBlockConfigureFormBase.php, line 113

Class

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

Namespace

Drupal\panels\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) {
  $this->tempstore_id = $tempstore_id;
  $cached_values = $this
    ->getCachedValues($this->tempstore, $tempstore_id, $machine_name);
  $this->variantPlugin = $cached_values['plugin'];
  $contexts = $this->variantPlugin
    ->getPattern()
    ->getDefaultContexts($this->tempstore, $this
    ->getTempstoreId(), $machine_name);
  $this->variantPlugin
    ->setContexts($contexts);
  $form_state
    ->setTemporaryValue('gathered_contexts', $contexts);
  $this->block = $this
    ->prepareBlock($block_id);
  $form_state
    ->set('machine_name', $machine_name);
  $form_state
    ->set('block_id', $this->block
    ->getConfiguration()['uuid']);

  // Some Block Plugins rely on the block_theme value to load theme settings.
  // @see \Drupal\system\Plugin\Block\SystemBrandingBlock::blockForm().
  $form_state
    ->set('block_theme', $this
    ->config('system.theme')
    ->get('default'));
  $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->variantPlugin
      ->getRegionNames(),
    '#default_value' => $this->variantPlugin
      ->getRegionAssignment($this->block
      ->getConfiguration()['uuid']),
    '#required' => TRUE,
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->submitText(),
    '#button_type' => 'primary',
  ];
  return $form;
}