You are here

class CustomPublishingOptionPermissions in Custom Publishing Options 8

Hierarchy

Expanded class hierarchy of CustomPublishingOptionPermissions

File

src/CustomPublishingOptionPermissions.php, line 10

Namespace

Drupal\custom_pub
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomPublishingOptionPermissions::$entityTypeManager protected property The entity type manager.
CustomPublishingOptionPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
CustomPublishingOptionPermissions::permissions public function Get permissions for Custom Publishing Options.
CustomPublishingOptionPermissions::__construct public function Constructs a CustomPublishingOptionPermissions instance.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.