From be1cf5819afb7f327d2b94251262ec6efad41ade Mon Sep 17 00:00:00 2001 From: Chris Green Date: Wed, 11 Dec 2024 16:49:39 -0700 Subject: [PATCH] Fixes #3944 Whitescreen if az_person not enabled. --- modules/custom/az_core/az_core.services.yml | 1 + .../az_core/src/AZUserToolbarLinkBuilder.php | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/custom/az_core/az_core.services.yml b/modules/custom/az_core/az_core.services.yml index 7a7f676e9c..8899f46d40 100755 --- a/modules/custom/az_core/az_core.services.yml +++ b/modules/custom/az_core/az_core.services.yml @@ -34,3 +34,4 @@ services: arguments: - '@entity_type.manager' - '@?externalauth.authmap' + - '@module_handler' diff --git a/modules/custom/az_core/src/AZUserToolbarLinkBuilder.php b/modules/custom/az_core/src/AZUserToolbarLinkBuilder.php index d1e5dc9d83..0c0bec5f25 100644 --- a/modules/custom/az_core/src/AZUserToolbarLinkBuilder.php +++ b/modules/custom/az_core/src/AZUserToolbarLinkBuilder.php @@ -3,6 +3,7 @@ namespace Drupal\az_core; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Url; use Drupal\externalauth\AuthmapInterface; @@ -27,6 +28,13 @@ class AZUserToolbarLinkBuilder extends ToolbarLinkBuilder { */ protected $entityTypeManager; + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + /** * ToolbarHandler constructor. * @@ -36,11 +44,14 @@ class AZUserToolbarLinkBuilder extends ToolbarLinkBuilder { * The entity type manager. * @param \Drupal\externalauth\AuthmapInterface $authmap * The authmap service. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + * The module handler. */ - public function __construct(AccountProxyInterface $account, EntityTypeManagerInterface $entityTypeManager, ?AuthmapInterface $authmap) { + public function __construct(AccountProxyInterface $account, EntityTypeManagerInterface $entityTypeManager, ?AuthmapInterface $authmap, ModuleHandlerInterface $moduleHandler) { parent::__construct($account); $this->entityTypeManager = $entityTypeManager; $this->authmap = $authmap; + $this->moduleHandler = $moduleHandler; } /** @@ -51,9 +62,11 @@ public function __construct(AccountProxyInterface $account, EntityTypeManagerInt */ public function renderToolbarLinks() { $build = parent::renderToolbarLinks(); + // Check if the az_person module is enabled. + $az_person_enabled = $this->moduleHandler->moduleExists('az_person'); $additional_links = []; // Only valid if we have the externalauth module. - if (!empty($this->authmap)) { + if (!empty($this->authmap) && $az_person_enabled) { // Check if we have permission. if ($this->account->hasPermission('edit matching netid content')) { $auth = $this->authmap->get($this->account->id(), 'cas');