public function ConditionFormBase::submitForm in Block Visibility Groups 8
Form submission handler.
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 FormInterface::submitForm
File
- src/
Form/ ConditionFormBase.php, line 131
Class
- ConditionFormBase
- Provides a base form for editing and adding a condition.
Namespace
Drupal\block_visibility_groups\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Allow the condition to submit the form.
$condition_values = (new FormState())
->setValues($form_state
->getValue('condition'));
$this->condition
->submitConfigurationForm($form, $condition_values);
// Update the original form values.
$form_state
->setValue('condition', $condition_values
->getValues());
if ($this->condition instanceof ContextAwarePluginInterface) {
$this->condition
->setContextMapping($condition_values
->getValue('context_mapping', []));
}
// Set the submission message.
$this
->messenger()
->addMessage($this
->submitMessageText());
$configuration = $this->condition
->getConfiguration();
// If this condition is new, add it to the block_visibility_group.
if (!isset($configuration['uuid'])) {
$this->block_visibility_group
->addCondition($configuration);
}
// Save the block_visibility_group entity.
$this->block_visibility_group
->save();
$this
->setConditionRedirect($form_state);
}