You are here

class MediaBulkConfigPermissions in Media Bulk Upload 8

Provides dynamic permissions for nodes of different types.

Hierarchy

Expanded class hierarchy of MediaBulkConfigPermissions

File

src/MediaBulkConfigPermissions.php, line 11

Namespace

Drupal\media_bulk_upload
View source
class MediaBulkConfigPermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of node type permissions.
   *
   * @return array
   *   The node type permissions.
   *   @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  public function mediaBulkConfigPermissions() {
    $perms = [];

    // Generate node permissions for all node types.
    foreach (MediaBulkConfig::loadMultiple() as $mediaBulkConfig) {
      $perms += $this
        ->buildPermissions($mediaBulkConfig);
    }
    return $perms;
  }

  /**
   * Returns a list of node permissions for a given node type.
   *
   * @param \Drupal\node\Entity\NodeType $type
   *   The node type.
   *
   * @return array
   *   An associative array of permission names and descriptions.
   */
  protected function buildPermissions(MediaBulkConfig $mediaBulkConfig) {
    $mediaBulkConfigId = $mediaBulkConfig
      ->id();
    $type_params = [
      '%type_name' => $mediaBulkConfig
        ->label(),
    ];
    return [
      "use {$mediaBulkConfigId} bulk upload form" => [
        'title' => $this
          ->t('%type_name : Use upload form', $type_params),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaBulkConfigPermissions::buildPermissions protected function Returns a list of node permissions for a given node type.
MediaBulkConfigPermissions::mediaBulkConfigPermissions public function Returns an array of node type 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.