FilterPermissions.php in Drupal 10
File
core/modules/filter/src/FilterPermissions.php
View source
<?php
namespace Drupal\filter;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FilterPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
public function permissions() {
$permissions = [];
$formats = $this->entityTypeManager
->getStorage('filter_format')
->loadByProperties([
'status' => TRUE,
]);
uasort($formats, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
foreach ($formats as $format) {
if ($permission = $format
->getPermissionName()) {
$permissions[$permission] = [
'title' => $this
->t('Use the <a href=":url">@label</a> text format', [
':url' => $format
->toUrl()
->toString(),
'@label' => $format
->label(),
]),
'description' => [
'#prefix' => '<em>',
'#markup' => $this
->t('Warning: This permission may have security implications depending on how the text format is configured.'),
'#suffix' => '</em>',
],
'dependencies' => [
$format
->getConfigDependencyKey() => [
$format
->getConfigDependencyName(),
],
],
];
}
}
return $permissions;
}
}