From f1c08b01444791431015b3811ae05ed69fb5f17b Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Fri, 15 Sep 2023 14:29:08 -0700 Subject: [PATCH] VACMS-14793: Adds Menu Alter trait and module for controlling header and footer menus. Co-authored-by: Daniel Sasser Co-authored-by: Christia Troyer --- config/sync/core.extension.yml | 1 + .../EventSubscriber/FormEventSubscriber.php | 69 +++++++++++++++++++ .../src/Traits/MenuFormAlter.php | 20 ++++++ .../va_gov_header_footer.info.yml | 5 ++ .../va_gov_header_footer.services.yml | 6 ++ .../EventSubscriber/FormEventSubscriber.php | 13 ---- 6 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php create mode 100644 docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php create mode 100644 docroot/modules/custom/va_gov_header_footer/va_gov_header_footer.info.yml create mode 100644 docroot/modules/custom/va_gov_header_footer/va_gov_header_footer.services.yml diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index dfc41445259..cd149d56c1d 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -253,6 +253,7 @@ module: va_gov_github: 0 va_gov_govdelivery: 0 va_gov_graphql: 0 + va_gov_header_footer: 0 va_gov_help_center: 0 va_gov_links: 0 va_gov_live_field_migration: 0 diff --git a/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php b/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php new file mode 100644 index 00000000000..d7148cf4031 --- /dev/null +++ b/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php @@ -0,0 +1,69 @@ +permsService = $permsService; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents(): array { + return [ + FormHookEvents::FORM_ALTER => ['formAlter'], + ]; + } + + /** + * Form alters for va_gov_home. + * + * @param \Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event + * The form event. + */ + public function formAlter(FormAlterEvent $event): void { + $form = &$event->getForm(); + $formId = $event->getFormId(); + $admin = $this->permsService->hasAdminRole(TRUE); + if (in_array($formId, $this->menus) && !$admin) { + $this->hideMenuLinkDescriptionField($form); + } + } + +} diff --git a/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php b/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php new file mode 100644 index 00000000000..2f27229e093 --- /dev/null +++ b/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php @@ -0,0 +1,20 @@ +permsService->hasAdminRole(TRUE); $this->hubMenuFormAlter($form, $admin); } - if ($event->getFormId() === 'menu_link_content_va-gov-footer_form' || $event->getFormId() === 'menu_link_content_footer-bottom-rail_form') { - $this->hideMenuLinkDescriptionField($form); - } } /** @@ -125,16 +122,6 @@ public function hubMenuHideParentLink(array &$form, bool $admin): static { return $this; } - /** - * Hides the description field on certain menu link forms. - * - * @param array $form - * The form element array. - */ - public function hideMenuLinkDescriptionField(array &$form): void { - $form['description']['#access'] = FALSE; - } - /** * {@inheritdoc} */