You are here

public function PriceModifierListBuilder::getOperations in Price 3.0.x

Same name and namespace in other branches
  1. 8 src/PriceModifierListBuilder.php \Drupal\price\PriceModifierListBuilder::getOperations()
  2. 3.x src/PriceModifierListBuilder.php \Drupal\price\PriceModifierListBuilder::getOperations()

Provides an array of information to build a list of operation links.

Parameters

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

Return value

array An associative array of operation link data for this list, keyed by operation name, containing the following key-value pairs:

  • title: The localized title of the operation.
  • url: An instance of \Drupal\Core\Url for the operation URL.
  • weight: The weight of this operation.

Overrides EntityListBuilder::getOperations

File

src/PriceModifierListBuilder.php, line 32

Class

PriceModifierListBuilder
Defines the list builder.

Namespace

Drupal\price

Code

public function getOperations(EntityInterface $entity) {
  $operations = parent::getOperations($entity);

  // Place the edit operation after the operations added by field_ui.module
  // which have the weights 15, 20, 25.
  if (isset($operations['edit'])) {
    $operations['edit'] = [
      'title' => t('Edit'),
      'weight' => 30,
      'url' => $entity
        ->toUrl('edit-form'),
    ];
  }
  if (isset($operations['delete'])) {
    $operations['delete'] = [
      'title' => t('Delete'),
      'weight' => 35,
      'url' => $entity
        ->toUrl('delete-form'),
    ];
  }

  // Sort the operations to normalize link order.
  uasort($operations, [
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ]);
  return $operations;
}