/** * 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) { parent::submitForm($form, $form_state); // Only save the blocks that are actually allowed and not every key value // pair from the form. $allowed_blocks = array_filter($form_state->getValue('allowed_blocks', [])); $this->entity->setAllowedBlocks($allowed_blocks); // Update the block configuration. $layout = $form_state->getValue('layout', []); if (is_array($layout)) { foreach ($layout as $block_id => $block_configuration) { $this->entity->updateBlock($block_id, $block_configuration); } } $this->save($form, $form_state); drupal_set_message($this->t('The entity layout has been saved.')); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $entity_type_id = $this->contentEntity->getEntityTypeId(); // If the form state has not been initialized then show just an // initialize button. if ($form_state->get('initialized') === FALSE) { return ['initialize' => ['#type' => 'submit', '#value' => $this->t('Initialize'), '#submit' => ['::initializeLayout'], '#name' => 'initialize-button']]; } $actions = parent::actions($form, $form_state); $actions['reset'] = ['#type' => 'link', '#title' => $this->t('Reset layout'), '#url' => Url::fromRoute("entity_layout.{$entity_type_id}.content.reset", [$entity_type_id => $this->contentEntity->id()]), '#attributes' => ['class' => ['button', 'use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]]; return $actions; }