/** * {@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()); }
/** * {@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} */ protected function persistBlock(BlockPluginInterface $block) { $configuration = $block->getConfiguration(); $entity = $this->entityLayoutService->getContentBlockByUuid($configuration['uuid']); $entity->updateBlock($configuration); $entity->save(); }
/** * {@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) { $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()])); }
/** * 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(); }
/** * 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} */ protected function persistBlock(BlockPluginInterface $block) { $content_entity = $this->getContentEntityFromRouteMath(); $content_block = $this->entityLayoutManager->createContentBlock($this->entityLayout, $content_entity, $block->getConfiguration()); return $content_block->save(); }