You are here

protected function PromotionListBuilder::getDefaultOperations in Commerce Core 8.2

Gets this list's default operations.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.

Return value

array The array structure is identical to the return value of self::getOperations().

Overrides EntityListBuilder::getDefaultOperations

File

modules/promotion/src/PromotionListBuilder.php, line 310

Class

PromotionListBuilder
Defines the list builder for promotions.

Namespace

Drupal\commerce_promotion

Code

protected function getDefaultOperations(EntityInterface $entity) {
  $operations = parent::getDefaultOperations($entity);
  if ($entity
    ->access('update')) {
    $operations['coupons'] = [
      'title' => $this
        ->t('Coupons'),
      'weight' => 20,
      'url' => new Url('entity.commerce_promotion_coupon.collection', [
        'commerce_promotion' => $entity
          ->id(),
      ]),
    ];
    if (!$entity
      ->isEnabled() && $entity
      ->hasLinkTemplate('enable-form')) {
      $operations['enable'] = [
        'title' => $this
          ->t('Enable'),
        'weight' => -10,
        'url' => $this
          ->ensureDestination($entity
          ->toUrl('enable-form')),
      ];
    }
    elseif ($entity
      ->hasLinkTemplate('disable-form')) {
      $operations['disable'] = [
        'title' => $this
          ->t('Disable'),
        'weight' => 40,
        'url' => $this
          ->ensureDestination($entity
          ->toUrl('disable-form')),
      ];
    }
  }
  return $operations;
}