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 fd16a68
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 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;
}
}
18 changes: 15 additions & 3 deletions modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\acquia_cms_tour\Form;

use Drupal\Core\Extension\InfoParserInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\State\StateInterface;
Expand Down Expand Up @@ -50,6 +51,13 @@ abstract class AcquiaCmsDashboardBase extends ConfigFormBase implements AcquiaDa
*/
protected $infoParser;

/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleList;

/**
* Constructs a new AcquiaConnectorForm.
*
Expand All @@ -61,12 +69,15 @@ abstract class AcquiaCmsDashboardBase extends ConfigFormBase implements AcquiaDa
* The link generator.
* @param \Drupal\Core\Extension\InfoParserInterface $info_parser
* The info file parser.
* @param \Drupal\Core\Extension\ModuleExtensionList $module_handler
* The module list.
*/
public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser) {
public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, ModuleExtensionList $module_list) {
$this->state = $state;
$this->moduleHandler = $module_handler;
$this->linkGenerator = $link_generator;
$this->infoParser = $info_parser;
$this->moduleList = $module_list;
}

/**
Expand All @@ -77,7 +88,8 @@ public static function create(ContainerInterface $container) {
$container->get('state'),
$container->get('module_handler'),
$container->get('link_generator'),
$container->get('info_parser')
$container->get('info_parser'),
$container->get('extension.list.module'),
);
}

Expand All @@ -101,7 +113,7 @@ public function getModule() {
* Get human readable module name.
*/
public function getModuleName() {
return $this->moduleHandler->getName($this->module);
return $this->moduleList->getName($this->module);
}

/**
Expand Down

0 comments on commit fd16a68

Please sign in to comment.