You are here

public function BulkEntityTypeInfo::entityOperation in Commerce Bulk 8

Adds commerce_bulk operations on an entity that supports it.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity on which to define an operation.

Return value

array An array of operation definitions.

See also

hook_entity_operation()

File

src/BulkEntityTypeInfo.php, line 60

Class

BulkEntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\commerce_bulk

Code

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;
}