Skip to content

Commit 5a718e3

Browse files
ACMS-4237: Add insert hook to grant developer role a permission to access newly created filter format.
1 parent c1a1a43 commit 5a718e3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules/acquia_cms_site_studio/acquia_cms_site_studio.module

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use Drupal\acquia_cms_site_studio\Helper\SiteStudioPermissionHelper;
1212
use Drupal\cohesion\Controller\AdministrationController;
1313
use Drupal\Core\Entity\EntityInterface;
1414
use Drupal\Core\Form\FormStateInterface;
15+
use Drupal\filter\FilterFormatInterface;
1516
use Drupal\user\Entity\Role;
1617
use Drupal\user\RoleInterface;
1718

@@ -285,3 +286,21 @@ function acquia_cms_site_studio_library_info_alter(array &$libraries, string $mo
285286
unset($libraries['core']['css']);
286287
}
287288
}
289+
290+
/**
291+
* Implements hook_ENTITY_TYPE_insert().
292+
*
293+
* The permission to developer role to use newly added text format.
294+
*
295+
* @param \Drupal\filter\FilterFormatInterface $filter_format
296+
* The filter format entity.
297+
*/
298+
function acquia_cms_site_studio_filter_format_insert(FilterFormatInterface $filter_format) {
299+
// If the filter format entity isn't syncing, please update it.
300+
// Otherwise, no action is needed.
301+
if (!$filter_format->isSyncing()) {
302+
// Add text format permission to developer role.
303+
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('developer');
304+
$role->grantPermission('use text format ' . $filter_format->id())->save(TRUE);
305+
}
306+
}

0 commit comments

Comments
 (0)