diff --git a/environment_indicator.permissions.yml b/environment_indicator.permissions.yml index 6b07d287932b52776e6c7bf1dd0df9bcab52aef9..0e54a0fef55bff3f83c135a2801e84e1b8d61a9e 100644 --- a/environment_indicator.permissions.yml +++ b/environment_indicator.permissions.yml @@ -6,5 +6,9 @@ access environment indicator: title: 'See all environment indicators' description: 'See all the environment indicators in the site.' +view environment indicator current release: + title: 'View environment indicator current release' + description: 'View the configured environment indicator current release information.' + permission_callbacks: - Drupal\environment_indicator\EnvironmentIndicatorPermissions::permissions diff --git a/environment_indicator.services.yml b/environment_indicator.services.yml index eeeca3ceb310b42efde0662c388575bfa05320e6..63893cf17029eb4bd49bb64430d45ba4198ce7e0 100644 --- a/environment_indicator.services.yml +++ b/environment_indicator.services.yml @@ -16,3 +16,4 @@ services: - '@entity_type.manager' - '@state' - '@settings' + - '@current_user' diff --git a/src/Service/EnvironmentIndicator.php b/src/Service/EnvironmentIndicator.php index fd0d8be54d9417d47c75a4f8a969054191b6112f..bdb859333f5ed591a2c3b7cc9b11402ac661a688 100644 --- a/src/Service/EnvironmentIndicator.php +++ b/src/Service/EnvironmentIndicator.php @@ -8,6 +8,7 @@ use Drupal\Core\Site\Settings; use Drupal\Core\State\StateInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; @@ -45,6 +46,13 @@ class EnvironmentIndicator { */ protected $settings; + /** + * The current user. + * + * @var \Drupal\Core\Session\AccountProxyInterface + */ + protected $account; + /** * Indicator constructor. * @@ -56,17 +64,21 @@ class EnvironmentIndicator { * The state service. * @param \Drupal\Core\Site\Settings $settings * The settings service. + * @param \Drupal\Core\Session\AccountProxyInterface $account + * The current user. */ public function __construct( ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, StateInterface $state, Settings $settings, + AccountProxyInterface $account, ) { $this->configFactory = $config_factory; $this->entityTypeManager = $entity_type_manager; $this->state = $state; $this->settings = $settings; + $this->account = $account; } /** @@ -120,8 +132,17 @@ protected function getVersionIdentifier(string $type): ?string { public function getTitle(): ?string { $env = $this->configFactory->get('environment_indicator.indicator'); $environment = $env->get('name'); - $release = $this->getCurrentRelease(); - return $environment ? ($release ? "($release) $environment" : $environment) : NULL; + + if (!$environment) { + return NULL; + } + + if ($this->account->hasPermission('view environment indicator current release')) { + $release = $this->getCurrentRelease(); + return $release ? "($release) $environment" : $environment; + } + + return $environment; } /**