3 namespace Drupal\filter;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides dynamic permissions of the filter module.
13 class FilterPermissions implements ContainerInjectionInterface {
15 use StringTranslationTrait;
20 * @var \Drupal\Core\Entity\EntityManagerInterface
22 protected $entityManager;
25 * Constructs a new FilterPermissions instance.
27 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
30 public function __construct(EntityManagerInterface $entity_manager) {
31 $this->entityManager = $entity_manager;
37 public static function create(ContainerInterface $container) {
38 return new static($container->get('entity.manager'));
42 * Returns an array of filter permissions.
46 public function permissions() {
48 // Generate permissions for each text format. Warn the administrator that any
49 // of them are potentially unsafe.
50 /** @var \Drupal\filter\FilterFormatInterface[] $formats */
51 $formats = $this->entityManager->getStorage('filter_format')->loadByProperties(['status' => TRUE]);
52 uasort($formats, 'Drupal\Core\Config\Entity\ConfigEntityBase::sort');
53 foreach ($formats as $format) {
54 if ($permission = $format->getPermissionName()) {
55 $permissions[$permission] = [
56 'title' => $this->t('Use the <a href=":url">@label</a> text format', [':url' => $format->url(), '@label' => $format->label()]),
59 '#markup' => $this->t('Warning: This permission may have security implications depending on how the text format is configured.'),