/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $settings = (new FormState())->setValues($form_state->getValue('settings')); // Call the plugin submit handler. $this->block->submitConfigurationForm($form, $settings); // Update the original form values. $form_state->setValue('settings', $settings->getValues()); if ($this->block instanceof ContextAwarePluginInterface) { $this->block->setContextMapping($form_state->getValue('context_mapping', [])); } $this->getVariantPlugin()->updateBlock($this->block->getConfiguration()['uuid'], ['region' => $form_state->getValue('region')]); $this->pageVariant->save(); $form_state->setRedirectUrl($this->pageVariant->toUrl('edit-form')); }
/** * Form submission handler. * * @param array $form * An associative array containing the structure of the form. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ public function submitForm(array &$form, FormStateInterface $form_state) { // Create a new form state for the block configuration form. $settings = (new FormState())->setValues($form_state->getValue('settings')); // Call the plugin submit handler. $this->block->submitConfigurationForm($form, $settings); // Update the original form values. $form_state->setValue('settings', $settings->getValues()); // Add available contexts if this is a context aware block. if ($this->block instanceof ContextAwarePluginInterface) { $this->block->setContextMapping($form_state->getValue(['settings', 'context_mapping'], [])); } $this->persistBlock($this->block); $form_state->setRedirectUrl($this->getRedirectUrl()); }
/** * Form submission handler. * * @param array $form * An associative array containing the structure of the form. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ public function submitForm(array &$form, FormStateInterface $form_state) { $settings = (new FormState())->setValues($form_state->getValue('settings')); // Call the plugin submit handler. $this->block->submitConfigurationForm($form, $settings); // Update the original form values. $form_state->setValue('settings', $settings->getValues()); // Add available contexts if this is a context aware block. if ($this->block instanceof ContextAwarePluginInterface) { $this->block->setContextMapping($form_state->getValue(['settings', 'context_mapping'], [])); } $link = $form_state->get('link'); $region = $form_state->get('region'); $configuration = array_merge($this->block->getConfiguration(), ['link' => $link, 'region' => $region]); if ($this->megaMenu->hasBlock($link, $configuration['id'])) { $this->megaMenu->updateBlock($link, $configuration['id'], $configuration); } else { $this->megaMenu->addBlock($link, $configuration['id'], $configuration); } $this->megaMenu->save(); $form_state->setRedirectUrl(Url::fromRoute('entity.mega_menu.edit_form', ['mega_menu' => $this->megaMenu->id()])); }
/** * Executes the block plugin's submit handlers. * * @param \Drupal\Core\Block\BlockPluginInterface $block_instance * The block instance. * @param array $form * The full form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The full form state. */ protected function submitBlock(BlockPluginInterface $block_instance, array $form, FormStateInterface $form_state) { $block_form_state = (new FormState())->setValues($form_state->getValue('settings')); $block_instance->submitConfigurationForm($form['flipper']['front']['settings'], $block_form_state); if ($block_instance instanceof ContextAwarePluginInterface) { $block_instance->setContextMapping($block_form_state->getValue('context_mapping', [])); } // Update the original form values. $form_state->setValue('settings', $block_form_state->getValues()); }