Skip to content

Commit

Permalink
Fixes #3944 Whitescreen if az_person not enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
trackleft committed Dec 11, 2024
1 parent e67998e commit be1cf58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/custom/az_core/az_core.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ services:
arguments:
- '@entity_type.manager'
- '@?externalauth.authmap'
- '@module_handler'
17 changes: 15 additions & 2 deletions modules/custom/az_core/src/AZUserToolbarLinkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,13 @@ class AZUserToolbarLinkBuilder extends ToolbarLinkBuilder {
*/
protected $entityTypeManager;

/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;

/**
* ToolbarHandler constructor.
*
Expand All @@ -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;
}

/**
Expand All @@ -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');
Expand Down

0 comments on commit be1cf58

Please sign in to comment.