You are here

class ShipmentPermissionProvider in Commerce Shipping 8.2

Provides permissions for shipments.

Hierarchy

Expanded class hierarchy of ShipmentPermissionProvider

File

src/ShipmentPermissionProvider.php, line 15

Namespace

Drupal\commerce_shipping
View source
class ShipmentPermissionProvider implements EntityPermissionProviderInterface, EntityHandlerInterface {
  use StringTranslationTrait;

  /**
   * The entity type bundle info.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityTypeBundleInfo;

  /**
   * Constructs a new ShipmentPermissionProvider object.
   *
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
   *   The entity type bundle info.
   */
  public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info) {
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static($container
      ->get('entity_type.bundle.info'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildPermissions(EntityTypeInterface $entity_type) {
    $entity_type_id = $entity_type
      ->id();
    $bundles = $this->entityTypeBundleInfo
      ->getBundleInfo($entity_type_id);
    $permissions = [];
    foreach ($bundles as $bundle_name => $bundle_info) {
      $permissions["manage {$bundle_name} {$entity_type_id}"] = [
        'title' => $this
          ->t('[Shipments] Manage %bundle', [
          '%bundle' => $bundle_info['label'],
        ]),
        'provider' => 'commerce_shipping',
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ShipmentPermissionProvider::$entityTypeBundleInfo protected property The entity type bundle info.
ShipmentPermissionProvider::buildPermissions public function Builds permissions for the given entity type. Overrides EntityPermissionProviderInterface::buildPermissions
ShipmentPermissionProvider::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
ShipmentPermissionProvider::__construct public function Constructs a new ShipmentPermissionProvider object.
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.