layoutTempstoreRepository = $layout_tempstore_repository; $this->classResolver = $class_resolver; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('layout_builder.tempstore_repository'), $container->get('class_resolver') ); } /** * {@inheritdoc} */ public function getCancelUrl() { return $this->sectionStorage->getLayoutBuilderUrl()->setOption('query', ['layout_is_rebuilding' => TRUE]); } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL) { $this->sectionStorage = $section_storage; $this->delta = $delta; $form = parent::buildForm($form, $form_state); if ($this->isAjax()) { $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit'; $form['actions']['cancel']['#attributes']['class'][] = 'dialog-cancel'; } return $form; } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->handleSectionStorage($this->sectionStorage, $form_state); $this->layoutTempstoreRepository->set($this->sectionStorage); $form_state->setRedirectUrl($this->getCancelUrl()); } /** * {@inheritdoc} */ protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) { return $this->rebuildAndClose($this->sectionStorage); } /** * Performs any actions on the section storage before saving. * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ abstract protected function handleSectionStorage(SectionStorageInterface $section_storage, FormStateInterface $form_state); }