Skip to content

Commit

Permalink
VACMS-14793: Hide Link Description Field in Footers
Browse files Browse the repository at this point in the history
  • Loading branch information
chri5tia committed Sep 1, 2023
1 parent b598bcd commit 72bcf04
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\va_gov_home\EventSubscriber;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
use Drupal\core_event_dispatcher\FormHookEvents;
use Drupal\va_gov_user\Service\UserPermsService;
Expand All @@ -11,6 +12,7 @@
* VA.gov home event subscriber.
*/
class FormEventSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;

/**
* The VA user permission service.
Expand All @@ -29,18 +31,30 @@ public function __construct(UserPermsService $permsService) {
$this->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) {
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);
}
}

/**
Expand All @@ -51,7 +65,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)
Expand Down Expand Up @@ -123,12 +137,13 @@ public function hubMenuHideParentLink(array &$form, bool $admin): static {
}

/**
* {@inheritdoc}
* Hides the description field on certain menu link forms.
*
* @param array $form
* The form element array.
*/
public static function getSubscribedEvents(): array {
return [
FormHookEvents::FORM_ALTER => ['formAlter'],
];
public function hideMenuLinkDescriptionField(array &$form): void {
$form['description']['#access'] = FALSE;
}

}

0 comments on commit 72bcf04

Please sign in to comment.