You are here

function commerce_pricelist_entity_operation in Commerce Pricelist 8.2

Implements hook_entity_operation().

File

./commerce_pricelist.module, line 155
Allows defining prices for specific stores, customers, quantities.

Code

function commerce_pricelist_entity_operation(EntityInterface $entity) {
  $current_user = \Drupal::currentUser();
  if ($entity
    ->getEntityTypeId() !== 'commerce_product_variation' || !$current_user
    ->hasPermission('administer commerce_pricelist')) {
    return;
  }
  $operations = [];
  $operations['prices'] = [
    'title' => t('Prices'),
    'url' => Url::fromRoute('view.commerce_product_variation_prices.page', [
      'commerce_product_variation' => $entity
        ->id(),
      'commerce_product' => $entity
        ->getProduct()
        ->id(),
    ]),
    'weight' => 50,
  ];
  return $operations;
}