Esempio n. 1
0
 /**
  * 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()]));
 }