BulkEntityTypeInfo.php in Commerce Bulk 8
File
src/BulkEntityTypeInfo.php
View source
<?php
namespace Drupal\commerce_bulk;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\commerce_product\Entity\ProductAttributeInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\taxonomy\VocabularyInterface;
class BulkEntityTypeInfo implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $currentUser;
public function __construct(AccountInterface $current_user) {
$this->currentUser = $current_user;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'));
}
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;
}
}