public function BlockFormBase::buildForm in Context 8.0
Same name and namespace in other branches
- 8.4 src/Reaction/Blocks/Form/BlockFormBase.php \Drupal\context\Reaction\Blocks\Form\BlockFormBase::buildForm()
- 8 src/Reaction/Blocks/Form/BlockFormBase.php \Drupal\context\Reaction\Blocks\Form\BlockFormBase::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.
ContextInterface $context: The context the reaction belongs to.
string|null $reaction_id: The ID of the blocks reaction the block should be added to.
string|null $block_id: The ID of the block to show a configuration form for.
Return value
array
Overrides FormInterface::buildForm
File
- src/
Reaction/ Blocks/ Form/ BlockFormBase.php, line 163
Class
Namespace
Drupal\context\Reaction\Blocks\FormCode
public function buildForm(array $form, FormStateInterface $form_state, ContextInterface $context = NULL, $reaction_id = NULL, $block_id = NULL) {
$this->context = $context;
$this->reaction = $this->context
->getReaction($reaction_id);
$this->block = $this
->prepareBlock($block_id);
// If a theme was defined in the query use this theme for the block
// otherwise use the default theme.
$theme = $this
->getRequest()->query
->get('theme', $this->themeHandler
->getDefault());
// Some blocks require contexts, set a temporary value with gathered
// contextual values.
$form_state
->setTemporaryValue('gathered_contexts', $this->contextRepository
->getAvailableContexts());
$configuration = $this->block
->getConfiguration();
$form['#tree'] = TRUE;
$form['settings'] = $this->block
->buildConfigurationForm([], $form_state);
$form['settings']['id'] = [
'#type' => 'value',
'#value' => $this->block
->getPluginId(),
];
$form['region'] = [
'#type' => 'select',
'#title' => $this
->t('Region'),
'#description' => $this
->t('Select the region where this block should be displayed.'),
'#options' => $this
->getThemeRegionOptions($theme),
'#default_value' => isset($configuration['region']) ? $configuration['region'] : '',
];
$form['unique'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Unique'),
'#description' => $this
->t('Check if the block should be uniquely placed, this means that the block can not be overridden by other blocks of the same type in the selected region.'),
'#default_value' => isset($configuration['unique']) ? $configuration['unique'] : FALSE,
];
$form['theme'] = [
'#type' => 'value',
'#value' => $theme,
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->getSubmitValue(),
'#button_type' => 'primary',
'#ajax' => [
'callback' => '::submitFormAjax',
],
];
return $form;
}