Skip to content

Commit

Permalink
Merge pull request #389 from localgovdrupal/fix/1.x-388-emergency-pub…
Browse files Browse the repository at this point in the history
…lisher-role

Check if emergency publisher role exits before changing permissions
  • Loading branch information
andybroomfield authored Oct 15, 2024
2 parents f927fce + 00e076e commit b70ea28
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions localgov_alert_banner.install
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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;

Expand Down Expand Up @@ -231,13 +232,18 @@ function localgov_alert_banner_update_9002() {
*/
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';
}
user_role_grant_permissions('emergency_publisher', $perms);
user_role_revoke_permissions('emergency_publisher', ['access administration pages']);

// 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']);
}
}

0 comments on commit b70ea28

Please sign in to comment.