From d42377d61d05c94032f2cf0c11ad14d298e6114e Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Fri, 1 Sep 2023 08:24:26 -0700 Subject: [PATCH 1/7] VACMS-14793: Hide Link Description Field in Footers --- .../EventSubscriber/FormEventSubscriber.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php b/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php index 3ec9e72d96..e9b5d1c23a 100644 --- a/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php +++ b/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php @@ -35,12 +35,15 @@ public function __construct(UserPermsService $permsService) { * @param \Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event * The form event. */ - public function formAlter(FormAlterEvent $event) { + public function formAlter(FormAlterEvent $event): void { + $form = &$event->getForm(); if ($event->getFormId() === 'menu_link_content_home-page-hub-list_form') { - $form = &$event->getForm(); $admin = $this->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, $admin); + } } /** @@ -51,7 +54,7 @@ public function formAlter(FormAlterEvent $event) { * @param bool $admin * TRUE if current user is an admin. */ - public function hubMenuFormAlter(array &$form, bool $admin) { + public function hubMenuFormAlter(array &$form, bool $admin): void { $this->hubMenuHideAddtributes($form) ->hubMenuHideExpanded($form) ->hubMenuHideViewMode($form, $admin) @@ -122,6 +125,16 @@ 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} */ From 3461a0453b8e5d608891fcbecb49292c1fa78c8f Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Fri, 8 Sep 2023 03:47:31 -0700 Subject: [PATCH 2/7] VACMS-14793: Fix footer rail form and other fixes --- .../va_gov_home/src/EventSubscriber/FormEventSubscriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php b/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php index e9b5d1c23a..a739988e16 100644 --- a/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php +++ b/docroot/modules/custom/va_gov_home/src/EventSubscriber/FormEventSubscriber.php @@ -41,8 +41,8 @@ public function formAlter(FormAlterEvent $event): void { $admin = $this->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, $admin); + if ($event->getFormId() === 'menu_link_content_va-gov-footer_form' || $event->getFormId() === 'menu_link_content_footer-bottom-rail_form') { + $this->hideMenuLinkDescriptionField($form); } } From a36e5ca834f9c9ce5e848656ab5d17ffc6a6e678 Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Fri, 15 Sep 2023 14:29:08 -0700 Subject: [PATCH 3/7] 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 dfc4144525..cd149d56c1 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 0000000000..d7148cf403 --- /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 0000000000..2f27229e09 --- /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} */ From f9e0d156e414ab14a518366669c62205c16c4133 Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Mon, 18 Sep 2023 08:35:26 -0700 Subject: [PATCH 4/7] VACMS-14793: Rename MenuAlterTrait for clarity --- .../src/EventSubscriber/FormEventSubscriber.php | 4 ++-- .../src/Traits/{MenuFormAlter.php => MenuFormAlterTrait.php} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename docroot/modules/custom/va_gov_header_footer/src/Traits/{MenuFormAlter.php => MenuFormAlterTrait.php} (93%) 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 index d7148cf403..38840b6b06 100644 --- a/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php +++ b/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php @@ -4,7 +4,7 @@ use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; use Drupal\core_event_dispatcher\FormHookEvents; -use Drupal\va_gov_header_footer\Traits\MenuFormAlter; +use Drupal\va_gov_header_footer\Traits\MenuFormAlterTrait; use Drupal\va_gov_user\Service\UserPermsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -13,7 +13,7 @@ */ class FormEventSubscriber implements EventSubscriberInterface { - use MenuFormAlter; + use MenuFormAlterTrait; /** * The VA user permission service. diff --git a/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php b/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlterTrait.php similarity index 93% rename from docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php rename to docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlterTrait.php index 2f27229e09..1805e05a81 100644 --- a/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php +++ b/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlterTrait.php @@ -5,7 +5,7 @@ /** * Provides centralized menu form alter methods. */ -trait MenuFormAlter { +trait MenuFormAlterTrait { /** * Hides the description field on certain menu link forms. From 5fb8549494f5a97548c8ac5bdb8a461fea3687ae Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Mon, 18 Sep 2023 18:33:53 -0700 Subject: [PATCH 5/7] VACMS-14793: Move menu form alter trait to menus more centralized menus module --- config/sync/core.extension.yml | 1 + .../src/EventSubscriber/FormEventSubscriber.php | 2 +- .../va_gov_menus/config/schema/va_gov_menus.schema.yml | 8 ++++++++ .../src/Traits/MenuFormAlterTrait.php | 2 +- docroot/modules/custom/va_gov_menus/va_gov_menus.info.yml | 5 +++++ 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml rename docroot/modules/custom/{va_gov_header_footer => va_gov_menus}/src/Traits/MenuFormAlterTrait.php (88%) create mode 100644 docroot/modules/custom/va_gov_menus/va_gov_menus.info.yml diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index cd149d56c1..851382789e 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -262,6 +262,7 @@ module: va_gov_magichead: 0 va_gov_media: 0 va_gov_menu_access: 0 + va_gov_menus: 0 va_gov_migrate: 0 va_gov_multilingual: 0 va_gov_multilingual_tmgmt: 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 index 38840b6b06..1a8503ed30 100644 --- a/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php +++ b/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php @@ -4,7 +4,7 @@ use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; use Drupal\core_event_dispatcher\FormHookEvents; -use Drupal\va_gov_header_footer\Traits\MenuFormAlterTrait; +use Drupal\va_gov_menus\Traits\MenuFormAlterTrait; use Drupal\va_gov_user\Service\UserPermsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml b/docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml new file mode 100644 index 0000000000..7df4aabc0f --- /dev/null +++ b/docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml @@ -0,0 +1,8 @@ +# Schema for the configuration files of the VA.gov Menus Helper module. +va_gov_menus.settings: + type: config_object + label: 'VA.gov Menus Helper settings' + mapping: + example: + type: string + label: 'Example' diff --git a/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlterTrait.php b/docroot/modules/custom/va_gov_menus/src/Traits/MenuFormAlterTrait.php similarity index 88% rename from docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlterTrait.php rename to docroot/modules/custom/va_gov_menus/src/Traits/MenuFormAlterTrait.php index 1805e05a81..802bfe149b 100644 --- a/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlterTrait.php +++ b/docroot/modules/custom/va_gov_menus/src/Traits/MenuFormAlterTrait.php @@ -1,6 +1,6 @@ Date: Wed, 20 Sep 2023 15:19:52 -0700 Subject: [PATCH 6/7] VACMS-14793: Removing unnecessary module files --- .../va_gov_menus/config/schema/va_gov_menus.schema.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml diff --git a/docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml b/docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml deleted file mode 100644 index 7df4aabc0f..0000000000 --- a/docroot/modules/custom/va_gov_menus/config/schema/va_gov_menus.schema.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Schema for the configuration files of the VA.gov Menus Helper module. -va_gov_menus.settings: - type: config_object - label: 'VA.gov Menus Helper settings' - mapping: - example: - type: string - label: 'Example' From dc25f9e1553420ee8b55248b4657cce577dffe47 Mon Sep 17 00:00:00 2001 From: Daniel Sasser Date: Wed, 20 Sep 2023 19:19:43 -0700 Subject: [PATCH 7/7] VACMS-14793: Do not use the trait yet. We have to wait until the va_gov_menus module is installed. --- .../src/EventSubscriber/FormEventSubscriber.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 index 1a8503ed30..3fdc8946a3 100644 --- a/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php +++ b/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php @@ -4,7 +4,6 @@ use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; use Drupal\core_event_dispatcher\FormHookEvents; -use Drupal\va_gov_menus\Traits\MenuFormAlterTrait; use Drupal\va_gov_user\Service\UserPermsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -13,8 +12,6 @@ */ class FormEventSubscriber implements EventSubscriberInterface { - use MenuFormAlterTrait; - /** * The VA user permission service. * @@ -62,7 +59,7 @@ public function formAlter(FormAlterEvent $event): void { $formId = $event->getFormId(); $admin = $this->permsService->hasAdminRole(TRUE); if (in_array($formId, $this->menus) && !$admin) { - $this->hideMenuLinkDescriptionField($form); + $form['description']['#access'] = FALSE; } }