You are here

class EntityClonePermissions in Entity Clone 8

Provides dynamic permissions of the entity_clone module.

Hierarchy

Expanded class hierarchy of EntityClonePermissions

File

src/EntityClonePermissions.php, line 14

Namespace

Drupal\entity_clone
View source
class EntityClonePermissions implements ContainerInjectionInterface {

  /**
   * The entoty type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The string translation manager.
   *
   * @var \Drupal\Core\StringTranslation\TranslationManager
   */
  protected $translationManager;

  /**
   * The Service Provider that verifies if entity has ownership.
   *
   * @var \Drupal\entity_clone\Services\EntityCloneServiceProvider
   */
  protected $serviceProvider;

  /**
   * Constructs a new EntityClonePermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity type manager.
   * @param \Drupal\Core\StringTranslation\TranslationManager $string_translation
   *   The string translation manager.
   * @param \\Drupal\entity_clone\Services\EntityCloneServiceProvider $service_provider
   *   The Service Provider that verifies if entity has ownership.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager, TranslationManager $string_translation, EntityCloneServiceProvider $service_provider) {
    $this->entityTypeManager = $entity_manager;
    $this->translationManager = $string_translation;
    $this->serviceProvider = $service_provider;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('string_translation'), $container
      ->get('entity_clone.service_provider'));
  }

  /**
   * Returns an array of entity_clone permissions.
   *
   * @return array
   *   The permission list.
   */
  public function permissions() {
    $permissions = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {
      $permissions['clone ' . $entity_type_id . ' entity'] = $this->translationManager
        ->translate('Clone all <em>@label</em> entities.', [
        '@label' => $entity_type
          ->getLabel(),
      ]);
      if ($this->serviceProvider
        ->entityTypeHasOwnerTrait($entity_type)) {
        $permissions['take_ownership_on_clone ' . $entity_type_id . ' entity'] = $this->translationManager
          ->translate('Allow user to take ownership of  <em>@label</em> cloned entities', [
          '@label' => $entity_type
            ->getLabel(),
        ]);
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityClonePermissions::$entityTypeManager protected property The entoty type manager.
EntityClonePermissions::$serviceProvider protected property The Service Provider that verifies if entity has ownership.
EntityClonePermissions::$translationManager protected property The string translation manager.
EntityClonePermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
EntityClonePermissions::permissions public function Returns an array of entity_clone permissions.
EntityClonePermissions::__construct public function Constructs a new EntityClonePermissions instance.