You are here

public function ConfigPagesListBuilder::getOperations in Config Pages 8

Same name and namespace in other branches
  1. 8.3 src/ConfigPagesListBuilder.php \Drupal\config_pages\ConfigPagesListBuilder::getOperations()
  2. 8.2 src/ConfigPagesListBuilder.php \Drupal\config_pages\ConfigPagesListBuilder::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/ConfigPagesListBuilder.php, line 91

Class

ConfigPagesListBuilder
Defines a class to build a listing of custom config_pages entities.

Namespace

Drupal\config_pages

Code

public function getOperations(EntityInterface $entity) {
  $operations = [];

  // Use user entry path if available for edit/add form page.
  $path = $entity->menu['path'];
  if (!empty($path)) {
    $operations['edit'] = [
      'title' => t('Edit'),
      'weight' => 10,
      'query' => [],
      'url' => Url::fromUserInput($path),
    ];
  }
  else {

    // Use default config page path in another case.
    $operations['edit'] = [
      'title' => t('Edit'),
      'weight' => 10,
      'query' => [],
      'url' => Url::fromRoute('config_pages.add_form', [
        'config_pages_type' => $entity
          ->id(),
      ]),
    ];
  }
  uasort($operations, '\\Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
  return $operations;
}