Skip to content

Commit

Permalink
ACMS-4373: Refactore code and add toolbar test in CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Dec 26, 2024
1 parent 8a65096 commit 033a896
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/acquia_cms_ci.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ jobs:
- acquia_cms_place
- acquia_cms_search
- acquia_cms_site_studio
- acquia_cms_toolbar
- acquia_cms_tour
- acquia_cms_video
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/acquia_cms_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ jobs:
- acquia_cms_place
- acquia_cms_search
- acquia_cms_site_studio
- acquia_cms_toolbar
- acquia_cms_tour
- acquia_cms_video
steps:
Expand Down
28 changes: 3 additions & 25 deletions modules/acquia_cms_toolbar/acquia_cms_toolbar.module
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,10 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array {
/**
* Implements hook_entity_insert().
*/
function acquia_cms_toolbar_entity_insert(EntityInterface $entity) {
if($entity instanceof RoleInterface && !$entity->isSyncing()) {
function acquia_cms_toolbar_user_role_insert(RoleInterface $role) {
if(!$role->isSyncing()) {
$class_resolver = \Drupal::service('class_resolver');
$class_resolver->getInstanceFromDefinition(PermissionManager::class)
->grantPermissionToRoles([$entity->id()]);
}
}

/**
* Update role permission handler.
*
* @param array|null $role_ids
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function update_toolbar_role_permission(array $role_ids = NULL): void {
$roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [
'content_administrator',
'content_author',
'content_editor',
'developer',
'site_builder',
'user_administrator',
]);
foreach ($roles as $role) {
$role->grantPermission('access toolbar')->trustData()->save();
->grantPermissionToRoles([$role->id()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function create(ContainerInterface $container) {
* {@inheritdoc}
*/
public function grantPermissionToRoles(array $role_ids = NULL): void {
$roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [
$roles = $this->entityTypeManager->getStorage('user_role')->loadMultiple($role_ids ?? [
'content_administrator',
'content_author',
'content_editor',
Expand Down
7 changes: 3 additions & 4 deletions modules/acquia_cms_tour/acquia_cms_tour.module
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ function acquia_cms_tour_modules_uninstalled(array $modules) {
/**
* Implements hook_cms_tour_entity_insert().
*/
function acquia_cms_tour_entity_insert(EntityInterface $entity) {
if($entity instanceof RoleInterface &&
!$entity->isSyncing() &&
$entity->id() == 'content_administrator'
function acquia_cms_tour_user_role_insert(RoleInterface $role) {
if(!$role->isSyncing() &&
$role->id() == 'content_administrator'
) {
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator');
$role->grantPermission('access acquia cms tour dashboard')->trustData()->save();
Expand Down

0 comments on commit 033a896

Please sign in to comment.