class FilterPermissions

Same name in other branches
  1. 9 core/modules/filter/src/FilterPermissions.php \Drupal\filter\FilterPermissions
  2. 10 core/modules/filter/src/FilterPermissions.php \Drupal\filter\FilterPermissions
  3. 11.x core/modules/filter/src/FilterPermissions.php \Drupal\filter\FilterPermissions

Provides dynamic permissions of the filter module.

Hierarchy

Expanded class hierarchy of FilterPermissions

File

core/modules/filter/src/FilterPermissions.php, line 14

Namespace

Drupal\filter
View source
class FilterPermissions implements ContainerInjectionInterface {
    use StringTranslationTrait;
    use DeprecatedServicePropertyTrait;
    
    /**
     * {@inheritdoc}
     */
    protected $deprecatedProperties = [
        'entityManager' => 'entity.manager',
    ];
    
    /**
     * The entity type manager.
     *
     * @var \Drupal\Core\Entity\EntityTypeManagerInterface
     */
    protected $entityTypeManager;
    
    /**
     * Constructs a new FilterPermissions instance.
     *
     * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
     *   The entity type manager.
     */
    public function __construct(EntityTypeManagerInterface $entity_type_manager) {
        $this->entityTypeManager = $entity_type_manager;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->get('entity_type.manager'));
    }
    
    /**
     * Returns an array of filter permissions.
     *
     * @return array
     */
    public function permissions() {
        $permissions = [];
        // Generate permissions for each text format. Warn the administrator that any
        // of them are potentially unsafe.
        
        /** @var \Drupal\filter\FilterFormatInterface[] $formats */
        $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>',
                    ],
                ];
            }
        }
        return $permissions;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
FilterPermissions::$deprecatedProperties protected property
FilterPermissions::$entityTypeManager protected property The entity type manager.
FilterPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
FilterPermissions::permissions public function Returns an array of filter permissions.
FilterPermissions::__construct public function Constructs a new FilterPermissions instance.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.