Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if emergency publisher role exists before changing permissions #389

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}