You are here

class PublishContentPermissions in Publish Content 8

Handles permissions.

Hierarchy

Expanded class hierarchy of PublishContentPermissions

1 file declares its use of PublishContentPermissions
PublishContentAccess.php in src/Access/PublishContentAccess.php

File

src/PublishContentPermissions.php, line 12

Namespace

Drupal\publishcontent
View source
class PublishContentPermissions {
  use StringTranslationTrait;
  const PUBLISH_ANY_TYPE = "publish any node type @type";
  const PUBLISH_OWN_TYPE = "publish own node type @type";
  const PUBLISH_EDITABLE_TYPE = "publish editable node type @type";
  const UNPUBLISH_ANY_TYPE = "unpublish any node type @type";
  const UNPUBLISH_OWN_TYPE = "unpublish own node type @type";
  const UNPUBLISH_EDITABLE_TYPE = "unpublish editable node type @type";

  /**
   * Returns the name of the permission.
   *
   * @param string $pattern
   *   The pattern for FormattableMarkup.
   * @param array $arguments
   *   The argument for FormattableMarkup.
   *
   * @return string
   *   The name of the permission.
   */
  public static function getPermission($pattern, array $arguments = NULL) {
    return (new FormattableMarkup($pattern, $arguments))
      ->__toString();
  }

  /**
   * Returns the list of permissions.
   */
  public function permissions() {
    $permissions = [];
    $nodeTypes = NodeType::loadMultiple();
    foreach ($nodeTypes as $type => $data) {
      $titleType = ucfirst($type);
      $permissions[self::getPermission(self::PUBLISH_ANY_TYPE, [
        '@type' => $type,
      ])] = [
        'title' => $this
          ->t("@titleType: publish any node type", [
          '@titleType' => $titleType,
        ]),
      ];
      $permissions[self::getPermission(self::PUBLISH_OWN_TYPE, [
        '@type' => $type,
      ])] = [
        'title' => $this
          ->t("@titleType: publish own node type", [
          '@titleType' => $titleType,
        ]),
      ];
      $permissions[self::getPermission(self::PUBLISH_EDITABLE_TYPE, [
        '@type' => $type,
      ])] = [
        'title' => $this
          ->t("@titleType: publish editable node type", [
          '@titleType' => $titleType,
        ]),
      ];
      $permissions[self::getPermission(self::UNPUBLISH_ANY_TYPE, [
        '@type' => $type,
      ])] = [
        'title' => $this
          ->t("@titleType: unpublish any node type", [
          '@titleType' => $titleType,
        ]),
      ];
      $permissions[self::getPermission(self::UNPUBLISH_OWN_TYPE, [
        '@type' => $type,
      ])] = [
        'title' => $this
          ->t("@titleType: unpublish own node type", [
          '@titleType' => $titleType,
        ]),
      ];
      $permissions[self::getPermission(self::UNPUBLISH_EDITABLE_TYPE, [
        '@type' => $type,
      ])] = [
        'title' => $this
          ->t("@titleType: unpublish editable node type", [
          '@titleType' => $titleType,
        ]),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PublishContentPermissions::getPermission public static function Returns the name of the permission.
PublishContentPermissions::permissions public function Returns the list of permissions.
PublishContentPermissions::PUBLISH_ANY_TYPE constant
PublishContentPermissions::PUBLISH_EDITABLE_TYPE constant
PublishContentPermissions::PUBLISH_OWN_TYPE constant
PublishContentPermissions::UNPUBLISH_ANY_TYPE constant
PublishContentPermissions::UNPUBLISH_EDITABLE_TYPE constant
PublishContentPermissions::UNPUBLISH_OWN_TYPE constant
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.