Skip to content

Commit

Permalink
ACMS-4373: Acquia Starter Kit Tour and Toolbar refactor install and e…
Browse files Browse the repository at this point in the history
…ntity_insert hooks.
  • Loading branch information
rajeshreeputra committed Dec 23, 2024
1 parent 52583c8 commit 014e109
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions modules/acquia_cms_toolbar/acquia_cms_toolbar.install
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ use Drupal\user\Entity\Role;
*/
function acquia_cms_toolbar_install($is_syncing) {
if (!$is_syncing) {
$roles = Role::loadMultiple();
$roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple([
'content_administrator',
'content_author',
'content_editor',
'developer',
'site_builder',
'user_administrator',
]);
foreach ($roles as $role) {
switch ($role->id()) {
case 'content_administrator':
Expand All @@ -21,7 +28,7 @@ function acquia_cms_toolbar_install($is_syncing) {
case 'developer':
case 'site_builder':
case 'user_administrator':
user_role_grant_permissions($role->id(), ['access toolbar']);
$role->grantPermission('access toolbar')->trustData()->save();
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/acquia_cms_toolbar/acquia_cms_toolbar.module
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ function acquia_cms_toolbar_entity_insert(EntityInterface $entity) {
case 'developer':
case 'site_builder':
case 'user_administrator':
user_role_grant_permissions($entity->id(), ['access toolbar']);
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load($entity->id());
$role->grantPermission('access toolbar')->trustData()->save();
break;
}
}
4 changes: 2 additions & 2 deletions modules/acquia_cms_tour/acquia_cms_tour.install
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use Drupal\user\Entity\Role;
*/
function acquia_cms_tour_install($is_syncing) {
if (!$is_syncing) {
if (Role::load('content_administrator')) {
user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']);
if ($role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator')) {
$role->grantPermission('access toolbar')->trustData()->save();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/acquia_cms_tour/acquia_cms_tour.module
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function acquia_cms_tour_modules_uninstalled(array $modules) {
function acquia_cms_tour_entity_insert(EntityInterface $entity) {
switch ($entity->id()) {
case 'content_administrator':
user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']);
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator');
$role->grantPermission('access acquia cms tour dashboard')->trustData()->save();
break;
}
}

0 comments on commit 014e109

Please sign in to comment.