diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index 21a36cee3be..690f71df45f 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -252,6 +252,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..5c93ce6e509 --- /dev/null +++ b/docroot/modules/custom/va_gov_header_footer/src/EventSubscriber/FormEventSubscriber.php @@ -0,0 +1,68 @@ +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(); + if (in_array($formId, $this->menus)) { + $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..769309e6469 --- /dev/null +++ b/docroot/modules/custom/va_gov_header_footer/src/Traits/MenuFormAlter.php @@ -0,0 +1,84 @@ +permsService = $permsService; } + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents(): array { + return [ + FormHookEvents::FORM_ALTER => ['formAlter'], + ]; + } + /** * Form alters for va_gov_home. * @@ -41,9 +53,6 @@ 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); - } } /** @@ -61,87 +70,4 @@ public function hubMenuFormAlter(array &$form, bool $admin): void { ->hubMenuHideParentLink($form, $admin); } - /** - * Hides the attributes form field for home page hub list link form. - * - * @param array $form - * The form element array. - * - * @return $this - */ - public function hubMenuHideAddtributes(array &$form): static { - if (!empty($form['options']['attributes'])) { - $form['options']['attributes']['#access'] = FALSE; - } - return $this; - } - - /** - * Hides the expanded form field for home page hub list link form. - * - * @param array $form - * The form element array. - * - * @return $this - */ - public function hubMenuHideExpanded(array &$form): static { - if (!empty($form['expanded'])) { - $form['expanded']['#access'] = FALSE; - } - return $this; - } - - /** - * Hides the view_mode form field for home page hub list link form. - * - * @param array $form - * The form element array. - * @param bool $admin - * TRUE if current user is an administrator. - * - * @return $this - */ - public function hubMenuHideViewMode(array &$form, bool $admin): static { - if (!empty($form['view_mode'])) { - $form['view_mode']['#access'] = $admin; - } - return $this; - } - - /** - * Hides the parent link form field for home page hub list link form. - * - * @param array $form - * The form element array. - * @param bool $admin - * TRUE if current user is an administrator. - * - * @return $this - */ - public function hubMenuHideParentLink(array &$form, bool $admin): static { - if (!empty($form['menu_parent'])) { - $form['menu_parent']['#access'] = $admin; - } - 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} - */ - public static function getSubscribedEvents(): array { - return [ - FormHookEvents::FORM_ALTER => ['formAlter'], - ]; - } - }