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
- class \Drupal\commerce_bulk\BulkEntityTypeInfo implements ContainerInjectionInterface uses StringTranslationTrait
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_bulkView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BulkEntityTypeInfo:: |
protected | property | The current user. | |
BulkEntityTypeInfo:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
BulkEntityTypeInfo:: |
public | function | Adds commerce_bulk operations on an entity that supports it. | |
BulkEntityTypeInfo:: |
public | function | EntityTypeInfo constructor. | |
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. |