public function ThemeSwitcherRuleForm::submitForm in Theme Switcher Rules 8
The settings conditions context mappings is now the plugin responsibility so we can avoid doing it here. From 8.2 the class ConditionPluginBase do the job on submitConfigurationForm().
Overrides EntityForm::submitForm
File
- src/
Form/ ThemeSwitcherRuleForm.php, line 206
Class
- ThemeSwitcherRuleForm
- Form handler for the ThemeSwitcherRule add and edit forms.
Namespace
Drupal\theme_switcher\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
/** @var \Drupal\theme_switcher\Entity\ThemeSwitcherRule $entity */
$entity = $this->entity;
foreach ($form_state
->getValue('visibility') as $condition_id => $values) {
// Allow the condition to submit the form.
$condition = $form_state
->get([
'conditions',
$condition_id,
]);
$subform = SubformState::createForSubform($form['visibility'][$condition_id], $form, $form_state);
$condition
->submitConfigurationForm($form['visibility'][$condition_id], $subform);
// Update the visibility conditions on the block.
$entity
->getVisibilityConditions()
->addInstanceId($condition_id, $condition
->getConfiguration());
}
// Save the settings of the plugin.
$status = $entity
->save();
$message = $this
->t("The Theme Switcher Rule '%label' has been %op.", [
'%label' => $entity
->label(),
'%op' => $status == SAVED_NEW ? 'created' : 'updated',
]);
$this->messenger
->addStatus($message);
$this->logger
->notice($message);
$form_state
->setRedirect('theme_switcher.admin');
}