Same name and namespace in other branches
- 8.9.x core/modules/filter/src/FilterPermissions.php \Drupal\filter\FilterPermissions
- 9 core/modules/filter/src/FilterPermissions.php \Drupal\filter\FilterPermissions
Provides dynamic permissions of the filter module.
Hierarchy
- class \Drupal\filter\FilterPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of FilterPermissions
File
- core/
modules/ filter/ src/ FilterPermissions.php, line 13
Namespace
Drupal\filterView source
class FilterPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* 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>',
],
// This permission is generated on behalf of $format text format,
// therefore add this text format as a config dependency.
'dependencies' => [
$format
->getConfigDependencyKey() => [
$format
->getConfigDependencyName(),
],
],
];
}
}
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FilterPermissions:: |
protected | property | The entity type manager. | |
FilterPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
FilterPermissions:: |
public | function | Returns an array of filter permissions. | |
FilterPermissions:: |
public | function | Constructs a new FilterPermissions instance. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 3 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 1 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |