You are here

class BulkEntityTypeInfo in Commerce Bulk 8

Manipulates entity type information.

This class contains primarily bridged hooks for compile-time or cache-clear-time hooks. Runtime hooks should be placed in EntityOperations.

Hierarchy

Expanded class hierarchy of BulkEntityTypeInfo

1 file declares its use of BulkEntityTypeInfo
commerce_bulk.module in ./commerce_bulk.module
Contains commerce_bulk.module.

File

src/BulkEntityTypeInfo.php, line 19

Namespace

Drupal\commerce_bulk
View source
class BulkEntityTypeInfo implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * EntityTypeInfo constructor.
   *
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   Current user.
   */
  public function __construct(AccountInterface $current_user) {
    $this->currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('current_user'));
  }

  /**
   * Adds commerce_bulk operations on an entity that supports it.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity on which to define an operation.
   *
   * @return array
   *   An array of operation definitions.
   *
   * @see hook_entity_operation()
   */
  public function entityOperation(EntityInterface $entity) {
    $operations = [];
    if ($entity instanceof ProductAttributeInterface && $this->currentUser
      ->hasPermission("administer commerce_product_attribute")) {
      $url = $entity
        ->toUrl();
      $route = 'view.commerce_bulk_attributes.attribute_page';
      $route_parameters = $url
        ->getRouteParameters();
      $options = $url
        ->getOptions();
      $operations['commerce_bulk_operations'] = [
        'title' => $this
          ->t('Bulk'),
        'weight' => -100,
        'url' => $url
          ->fromRoute($route, $route_parameters, $options),
      ];
    }
    elseif ($entity instanceof VocabularyInterface && $this->currentUser
      ->hasPermission("administer taxonomy")) {
      $url = $entity
        ->toUrl();
      $route = 'view.commerce_bulk_taxonomy.vocabulary_page';
      $route_parameters = $url
        ->getRouteParameters();
      $options = $url
        ->getOptions();
      $operations['commerce_bulk_operations'] = [
        'title' => $this
          ->t('Bulk'),
        'weight' => -100,
        'url' => $url
          ->fromRoute($route, $route_parameters, $options),
      ];
    }
    return $operations;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BulkEntityTypeInfo::$currentUser protected property The current user.
BulkEntityTypeInfo::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
BulkEntityTypeInfo::entityOperation public function Adds commerce_bulk operations on an entity that supports it.
BulkEntityTypeInfo::__construct public function EntityTypeInfo constructor.
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.