From 1d24432767eded76daf916bf59d9d5979499d34c Mon Sep 17 00:00:00 2001 From: Andy Broomfield Date: Tue, 15 Oct 2024 16:36:54 +0100 Subject: [PATCH 1/3] Check if emergency publisher role exits before changing permissions Fix #388 --- localgov_alert_banner.install | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/localgov_alert_banner.install b/localgov_alert_banner.install index 908a378a..8644eb4f 100644 --- a/localgov_alert_banner.install +++ b/localgov_alert_banner.install @@ -11,8 +11,10 @@ use Drupal\Core\Config\FileStorage; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use Symfony\Component\Yaml\Yaml; +use Drupal\user\RoleInterface; /** * Implements hook_install(). @@ -230,14 +232,19 @@ function localgov_alert_banner_update_9002() { * from the toolbar. */ function localgov_alert_banner_update_10002() { - $module_handler = \Drupal::service('module_handler'); - $perms[] = 'view the administration theme'; - if ($module_handler->moduleExists('node')) { - $perms[] = 'access content overview'; - } - if ($module_handler->moduleExists('toolbar')) { - $perms[] = 'access toolbar'; +$module_handler = \Drupal::service('module_handler'); + +$perms[] = 'view the administration theme'; +if ($module_handler->moduleExists('node')) { + $perms[] = 'access content overview'; +} +if ($module_handler->moduleExists('toolbar')) { + $perms[] = 'access toolbar'; +} + +// Add and revoke permissions if emergency publisher exists. +if (Role::load('emergency_publisher) instanceof RoleInterface) { + user_role_grant_permissions('emergency_publisher', $perms); + user_role_revoke_permissions('emergency_publisher', ['access administration pages']); } - user_role_grant_permissions('emergency_publisher', $perms); - user_role_revoke_permissions('emergency_publisher', ['access administration pages']); } From 62f625b3e182d277e364dba2f453a343620de8b3 Mon Sep 17 00:00:00 2001 From: Alistair Wearring <95761929+AWearring@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:57:37 +0100 Subject: [PATCH 2/3] Fix issues with `localgov_alert_banner.install` Removed duplicated declarations and added missing ' on line 245 --- localgov_alert_banner.install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/localgov_alert_banner.install b/localgov_alert_banner.install index 8644eb4f..92be53a6 100644 --- a/localgov_alert_banner.install +++ b/localgov_alert_banner.install @@ -14,7 +14,6 @@ use Drupal\field\Entity\FieldStorageConfig; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use Symfony\Component\Yaml\Yaml; -use Drupal\user\RoleInterface; /** * Implements hook_install(). @@ -243,7 +242,7 @@ if ($module_handler->moduleExists('toolbar')) { } // Add and revoke permissions if emergency publisher exists. -if (Role::load('emergency_publisher) instanceof RoleInterface) { +if (Role::load('emergency_publisher') instanceof RoleInterface) { user_role_grant_permissions('emergency_publisher', $perms); user_role_revoke_permissions('emergency_publisher', ['access administration pages']); } From 00e076e675931f7823b149021c3ff352bbd4f54a Mon Sep 17 00:00:00 2001 From: Alistair Wearring <95761929+AWearring@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:02:15 +0100 Subject: [PATCH 3/3] Resolved spacing issues --- localgov_alert_banner.install | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/localgov_alert_banner.install b/localgov_alert_banner.install index 92be53a6..1a086235 100644 --- a/localgov_alert_banner.install +++ b/localgov_alert_banner.install @@ -231,18 +231,18 @@ function localgov_alert_banner_update_9002() { * from the toolbar. */ function localgov_alert_banner_update_10002() { -$module_handler = \Drupal::service('module_handler'); + $module_handler = \Drupal::service('module_handler'); -$perms[] = 'view the administration theme'; -if ($module_handler->moduleExists('node')) { - $perms[] = 'access content overview'; -} -if ($module_handler->moduleExists('toolbar')) { - $perms[] = 'access toolbar'; -} + $perms[] = 'view the administration theme'; + if ($module_handler->moduleExists('node')) { + $perms[] = 'access content overview'; + } + if ($module_handler->moduleExists('toolbar')) { + $perms[] = 'access toolbar'; + } -// Add and revoke permissions if emergency publisher exists. -if (Role::load('emergency_publisher') instanceof RoleInterface) { + // Add and revoke permissions if emergency publisher exists. + if (Role::load('emergency_publisher') instanceof RoleInterface) { user_role_grant_permissions('emergency_publisher', $perms); user_role_revoke_permissions('emergency_publisher', ['access administration pages']); }