X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsettings_tray%2Fsrc%2FForm%2FSystemMenuOffCanvasForm.php;fp=web%2Fcore%2Fmodules%2Fsettings_tray%2Fsrc%2FForm%2FSystemMenuOffCanvasForm.php;h=71e15236109356c58b0385c84e30a815734c1971;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php b/web/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php new file mode 100644 index 000000000..71e152361 --- /dev/null +++ b/web/core/modules/settings_tray/src/Form/SystemMenuOffCanvasForm.php @@ -0,0 +1,154 @@ +menuStorage = $menu_storage; + $this->entityTypeManager = $entity_type_manager; + $this->stringTranslation = $string_translation; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_type.manager')->getStorage('menu'), + $container->get('entity_type.manager'), + $container->get('string_translation') + ); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = $this->plugin->buildConfigurationForm([], $form_state); + // Move the menu levels section to the bottom. + $form['menu_levels']['#weight'] = 100; + + $form['entity_form'] = [ + '#type' => 'details', + '#title' => $this->t('Edit menu %label', ['%label' => $this->menu->label()]), + '#open' => TRUE, + '#access' => $this->menu->access('edit'), + ]; + $form['entity_form'] += $this->getEntityForm($this->menu)->buildForm([], $form_state); + + // Print the menu link titles as text instead of a link. + if (!empty($form['entity_form']['links']['links'])) { + foreach (Element::children($form['entity_form']['links']['links']) as $child) { + $title = $form['entity_form']['links']['links'][$child]['title'][1]['#title']; + $form['entity_form']['links']['links'][$child]['title'][1] = ['#markup' => $title]; + } + } + // Change the header text. + $form['entity_form']['links']['links']['#header'][0] = $this->t('Link'); + $form['entity_form']['links']['links']['#header'][1]['data'] = $this->t('On'); + + // Remove the label, ID, description, and buttons from the entity form. + unset($form['entity_form']['label'], $form['entity_form']['id'], $form['entity_form']['description'], $form['entity_form']['actions']); + // Since the overview form is further nested than expected, update the + // #parents. See \Drupal\menu_ui\MenuForm::form(). + $form_state->set('menu_overview_form_parents', ['settings', 'entity_form', 'links']); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->plugin->validateConfigurationForm($form, $form_state); + $this->getEntityForm($this->menu)->validateForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->plugin->submitConfigurationForm($form, $form_state); + $this->getEntityForm($this->menu)->submitForm($form, $form_state); + $this->menu->save(); + } + + /** + * Gets the entity form for this menu. + * + * @param \Drupal\system\MenuInterface $menu + * The menu entity. + * + * @return \Drupal\Core\Entity\EntityFormInterface + * The entity form. + */ + protected function getEntityForm(MenuInterface $menu) { + $entity_form = $this->entityTypeManager->getFormObject('menu', 'edit'); + $entity_form->setEntity($menu); + return $entity_form; + } + + /** + * {@inheritdoc} + */ + public function setPlugin(PluginInspectionInterface $plugin) { + $this->plugin = $plugin; + $this->menu = $this->menuStorage->load($this->plugin->getDerivativeId()); + } + +}