You are here

class Permissions in Block Content Permissions 8

Provides dynamic permissions for the block content permissions module.

Hierarchy

Expanded class hierarchy of Permissions

File

src/Permissions.php, line 12

Namespace

Drupal\block_content_permissions
View source
class Permissions {
  use StringTranslationTrait;

  /**
   * Gets permissions.
   *
   * @return array
   *   Array of permissions.
   */
  public function get() {
    $permissions = [];

    // Generate permissions for all block content types.
    foreach (BlockContentType::loadMultiple() as $type) {
      $permissions += $this
        ->buildPermissions($type);
    }
    return $permissions;
  }

  /**
   * Returns a list of block content permissions for a given type.
   *
   * @param \Drupal\block_content\BlockContentTypeInterface $type
   *   The block content type.
   *
   * @return array
   *   Array of permissions.
   */
  protected function buildPermissions(BlockContentTypeInterface $type) {
    $type_id = $type
      ->id();
    $type_name = [
      '%type_name' => $type
        ->label(),
    ];
    return [
      "create {$type_id} block content" => [
        'title' => $this
          ->t('%type_name: Create new block content', $type_name),
      ],
      "delete any {$type_id} block content" => [
        'title' => $this
          ->t('%type_name: Delete any block content', $type_name),
      ],
      "update any {$type_id} block content" => [
        'title' => $this
          ->t('%type_name: Edit any block content', $type_name),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::buildPermissions protected function Returns a list of block content permissions for a given type.
Permissions::get public function Gets permissions.
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.