class DomainEntityPermissions in Domain Access Entity 8
Dynamic permissions class for Domain Entity.
Hierarchy
- class \Drupal\domain_entity\DomainEntityPermissions uses StringTranslationTrait
Expanded class hierarchy of DomainEntityPermissions
File
- src/DomainEntityPermissions.php, line 10 
Namespace
Drupal\domain_entityView source
class DomainEntityPermissions {
  use StringTranslationTrait;
  /**
   * Define permissions.
   */
  public function permissions() {
    $permissions = [];
    $mapper = \Drupal::service('domain_entity.mapper');
    $bundle_info = \Drupal::service('entity_type.bundle.info');
    foreach ($mapper
      ->getEnabledEntityTypes() as $type_id => $entity_type) {
      $bundles = $bundle_info
        ->getBundleInfo($type_id);
      if (!empty($bundles)) {
        foreach ($bundles as $bundle_id => $bundle) {
          $permissions += $this
            ->bundlePermissions($bundle_id, $bundle['label'], $entity_type
            ->id(), $entity_type
            ->getBundleLabel());
        }
      }
    }
    return $permissions;
  }
  /**
   * Helper method to generate bundle permission list.
   *
   * @param int $id
   *   Bundle ID.
   * @param string $label
   *   Bundle label.
   * @param int $entityTypeId
   *   Entity type ID.
   * @param string $entityTypeLabel
   *   Entity type label.
   *
   * @see DomainAccessPermissions
   *
   * @return array
   *   An array of permission names and descriptions.
   */
  private function bundlePermissions($id, $label, $entityTypeId, $entityTypeLabel) {
    // Build standard list of bundle permissions for this type.
    $perms = [
      "create {$id} {$entityTypeId} content on assigned domains" => [
        'title' => $this
          ->t('%entity_type_name: %type_name: Create new content on assigned domains', [
          '%type_name' => $label,
          '%entity_type_name' => $entityTypeLabel,
        ]),
      ],
      "update {$id} {$entityTypeId} content on assigned domains" => [
        'title' => $this
          ->t('%entity_type_name: %type_name: Edit any content on assigned domains', [
          '%type_name' => $label,
          '%entity_type_name' => $entityTypeLabel,
        ]),
      ],
      "delete {$id} {$entityTypeId} content on assigned domains" => [
        'title' => $this
          ->t('%entity_type_name: %type_name: Delete any content on assigned domains', [
          '%type_name' => $label,
          '%entity_type_name' => $entityTypeLabel,
        ]),
      ],
    ];
    return $perms;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| DomainEntityPermissions:: | private | function | Helper method to generate bundle permission list. | |
| DomainEntityPermissions:: | public | function | Define permissions. | |
| StringTranslationTrait:: | protected | property | The string translation service. | 1 | 
| StringTranslationTrait:: | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait:: | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait:: | protected | function | Gets the string translation service. | |
| StringTranslationTrait:: | public | function | Sets the string translation service to use. | 2 | 
| StringTranslationTrait:: | protected | function | Translates a string to the current language or to a given language. | 
