class AccessUnpublishedPermissions in Access unpublished 8
Calculates the permissions for access_unpublished.
@package Drupal\access_unpublished
Hierarchy
- class \Drupal\access_unpublished\AccessUnpublishedPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of AccessUnpublishedPermissions
File
- src/
AccessUnpublishedPermissions.php, line 16
Namespace
Drupal\access_unpublishedView source
class AccessUnpublishedPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new AccessUnpublishedPermissions instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The translation service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $translation) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('string_translation'));
}
/**
* Permissions callback.
*
* @return array
* Returns permissions for all nodes.
*/
public function permissions() {
$permissions = [];
$definitions = $this->entityTypeManager
->getDefinitions();
foreach ($definitions as $definition) {
if (AccessUnpublished::applicableEntityType($definition)) {
$permission = 'access_unpublished ' . $definition
->id();
if ($definition
->get('bundle_entity_type')) {
$bundles = $this->entityTypeManager
->getStorage($definition
->getBundleEntityType())
->loadMultiple();
foreach ($bundles as $bundle) {
$permissions[$permission . ' ' . $bundle
->id()] = [
'title' => $this
->t('Access unpublished %bundle @type', [
'%bundle' => strtolower($bundle
->label()),
'@type' => $definition
->getPluralLabel(),
]),
];
}
}
else {
$permissions[$permission] = [
'title' => $this
->t('Access unpublished @type', [
'@type' => $definition
->getPluralLabel(),
]),
];
}
}
}
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessUnpublishedPermissions:: |
protected | property | The entity type manager. | |
AccessUnpublishedPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
AccessUnpublishedPermissions:: |
public | function | Permissions callback. | |
AccessUnpublishedPermissions:: |
public | function | Constructs a new AccessUnpublishedPermissions instance. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |