public BlockForm::submitForm(array &$form, FormStateInterface $form_state)
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides EntityForm::submitForm
File
- core/modules/block/src/BlockForm.php, line 338
Class
- BlockForm
- Provides form for block instance forms.
Namespace
Drupal\block
Code
public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $entity = $this->entity; // The Block Entity form puts all block plugin form elements in the // settings form element, so just pass that to the block for submission. $sub_form_state = SubformState::createForSubform($form['settings'], $form, $form_state); // Call the plugin submit handler. $block = $entity->getPlugin(); $this->getPluginForm($block)->submitConfigurationForm($form, $sub_form_state); // If this block is context-aware, set the context mapping. if ($block instanceof ContextAwarePluginInterface && $block->getContextDefinitions()) { $context_mapping = $sub_form_state->getValue('context_mapping', []); $block->setContextMapping($context_mapping); } $this->submitVisibility($form, $form_state); // Save the settings of the plugin. $entity->save(); drupal_set_message($this->t('The block configuration has been saved.')); $form_state->setRedirect( 'block.admin_display_theme', array( 'theme' => $form_state->getValue('theme'), ), array('query' => array('block-placement' => Html::getClass($this->entity->id()))) ); }
Please login to continue.