CustomPublishingOptionPermissions.php in Custom Publishing Options 8
Namespace
Drupal\custom_pubFile
src/CustomPublishingOptionPermissions.phpView source
<?php
namespace Drupal\custom_pub;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CustomPublishingOptionPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a CustomPublishingOptionPermissions 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'));
}
/**
* Get permissions for Custom Publishing Options.
*
* @return array
* Permissions array.
*/
public function permissions() {
$permissions = [];
foreach ($this->entityTypeManager
->getStorage('custom_publishing_option')
->loadMultiple() as $machine_name => $publish_option) {
$permissions += [
'can set node publish state to ' . $publish_option
->id() => [
'title' => $this
->t('Can set node publish state to %type.', [
'%type' => $publish_option
->label(),
]),
],
];
}
return $permissions;
}
}
Classes
Name | Description |
---|---|
CustomPublishingOptionPermissions |