/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->getVariantPlugin()->removeBlock($this->block->getConfiguration()['uuid']);
     $this->pageVariant->save();
     drupal_set_message($this->t('The block %label has been removed.', ['%label' => $this->block->label()]));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function persistBlock(BlockPluginInterface $block)
 {
     $configuration = $block->getConfiguration();
     $entity = $this->entityLayoutService->getContentBlockByUuid($configuration['uuid']);
     $entity->updateBlock($configuration);
     $entity->save();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $configuration = $this->block->getConfiguration();
     $this->megaMenu->removeBlock($form_state->get('link'), $configuration['id']);
     $this->megaMenu->save();
     drupal_set_message($this->t('The @label block has been removed.', ['@label' => $configuration['label']]));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * {@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'));
 }
Пример #5
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)
 {
     // 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());
 }
Пример #6
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()]));
 }
 /**
  * {@inheritdoc}
  */
 public function setPlugin(PluginInspectionInterface $plugin)
 {
     $this->plugin = $plugin;
     $this->entity = $this->menuStorage->load($this->plugin->getDerivativeId());
 }
Пример #8
0
 /**
  * Function to handle persisting of the block once saved.
  *
  * @param  BlockPluginInterface $block
  *   The block to be persisted.
  *
  * @return string
  */
 protected function persistBlock(BlockPluginInterface $block)
 {
     $this->entityLayout->addBlock($block->getConfiguration());
     return $this->entityLayout->save();
 }
 /**
  * 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());
 }
 /**
  * Build a block row for the layout table.
  *
  * @param BlockPluginInterface $block
  *   The block to render a row for.
  * @param $weight_delta
  *   The calculated weight delta.
  * @param string $target_entity_type
  * @param string $bundle_entity_type
  * @param string $target_bundle
  *
  * @return array
  */
 protected function buildBlockRow(BlockPluginInterface $block, $weight_delta, $target_entity_type, $bundle_entity_type, $target_bundle)
 {
     $configuration = $block->getConfiguration();
     $block_row = ['#attributes' => ['class' => ['draggable']]];
     $block_row['label'] = ['#plain_text' => $block->label()];
     $block_row['category'] = ['#plain_text' => $block->getPluginDefinition()['category']];
     $block_row['weight'] = ['#type' => 'weight', '#default_value' => isset($configuration['weight']) ? $configuration['weight'] : 0, '#delta' => $weight_delta, '#title' => $this->t('Weight for @block block', ['@block' => $block->label()]), '#title_display' => 'invisible', '#attributes' => ['class' => ['block-weight']]];
     $block_row['operations'] = ['#type' => 'operations', '#links' => ['edit' => ['title' => $this->t('Edit'), 'url' => Url::fromRoute("entity_layout.{$target_entity_type}.block.edit", ['block_id' => $configuration['uuid'], $bundle_entity_type => $target_bundle]), 'attributes' => ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]], 'remove' => ['title' => $this->t('Remove'), 'url' => Url::fromRoute("entity_layout.{$target_entity_type}.block.remove", ['block_id' => $configuration['uuid'], $bundle_entity_type => $target_bundle]), 'attributes' => ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]]]];
     return $block_row;
 }
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $site_info = $form_state->getValue('site_information');
     $this->configFactory->getEditable('system.site')->set('name', $site_info['site_name'])->set('slogan', $site_info['site_slogan'])->save();
     $this->plugin->submitConfigurationForm($form, $form_state);
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 protected function persistBlock(BlockPluginInterface $block)
 {
     $content_entity = $this->getContentEntityFromRouteMath();
     $content_block = $this->entityLayoutManager->createContentBlock($this->entityLayout, $content_entity, $block->getConfiguration());
     return $content_block->save();
 }