Skip to content

Commit

Permalink
ACMS-4373: Update Audio to use permission manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Jan 6, 2025
1 parent 746e889 commit e9aeb28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 53 deletions.
38 changes: 8 additions & 30 deletions modules/acquia_cms_audio/acquia_cms_audio.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,28 @@
* Install, update and uninstall functions for the acquia_cms_audio module.
*/

use Drupal\acquia_cms_audio\EntityOperations\PermissionManager;
use Drupal\editor\Entity\Editor;

/**
* Implements hook_install().
*/
function acquia_cms_audio_install($is_syncing) {
if (!$is_syncing) {
$roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple([
'content_author',
'content_editor',
]);
foreach ($roles as $role) {
switch ($role->id()) {
case 'content_author':
foreach ([
'create audio media',
'edit own audio media',
'delete own audio media',
] as $permission) {
$role->grantPermission($permission);
}
$role->trustData()->save();
break;

case 'content_editor':
foreach (['edit any audio media', 'delete any audio media'] as $permission) {
$role->grantPermission($permission);
}
$role->trustData()->save();
break;
}
}

// Update the filtered_html & full_html configurations
if (\Drupal::moduleHandler()->moduleExists('editor')) {
_acquia_cms_audio_editor_config_rewrite();
}
$class_resolver = \Drupal::service('class_resolver');
$class_resolver->getInstanceFromDefinition(PermissionManager::class)
->grantPermissionToRoles();
_acquia_cms_audio_editor_config_rewrite();
}
}

/**
* Function to rewrite filtered_html & full_html configurations.
*/
function _acquia_cms_audio_editor_config_rewrite(): void {
if(!\Drupal::moduleHandler()->moduleExists('editor')) {
return;
}
$editors = [
"filtered_html",
"full_html",
Expand Down
31 changes: 8 additions & 23 deletions modules/acquia_cms_audio/acquia_cms_audio.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,16 @@
* Install, update and uninstall functions for the acquia_cms_audio module.
*/

use Drupal\Core\Entity\EntityInterface;
use Drupal\acquia_cms_audio\EntityOperations\PermissionManager;
use Drupal\user\RoleInterface;

/**
* Implements hook_content_model_role_presave_alter().
* Implements hook_entity_insert().
*/
function acquia_cms_audio_entity_insert(EntityInterface $entity) {
switch ($entity->id()) {
case 'content_author':
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load($entity->id());
foreach ([
'create audio media',
'edit own audio media',
'delete own audio media',
] as $permission) {
$role->grantPermission($permission);
}
$role->trustData()->save();
break;

case 'content_editor':
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load($entity->id());
foreach (['edit any audio media', 'delete any audio media'] as $permission) {
$role->grantPermission($permission);
}
$role->trustData()->save();
break;
function acquia_cms_audio_user_role_insert(RoleInterface $role) {
if(!$role->isSyncing()) {
$class_resolver = \Drupal::service('class_resolver');
$class_resolver->getInstanceFromDefinition(PermissionManager::class)
->grantPermissionToRoles([$role->id()]);
}
}

0 comments on commit e9aeb28

Please sign in to comment.