public function ConfigPagesListBuilder::getOperations in Config Pages 8.2
Same name and namespace in other branches
- 8.3 src/ConfigPagesListBuilder.php \Drupal\config_pages\ConfigPagesListBuilder::getOperations()
- 8 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 121
Class
- ConfigPagesListBuilder
- Defines a class to build a listing of custom config_pages entities.
Namespace
Drupal\config_pagesCode
public function getOperations(EntityInterface $entity) {
$operations = [];
$account = $this->account;
$edit_permission = $account
->hasPermission('edit config_pages entity') || $account
->hasPermission('edit ' . $entity
->id() . ' config page entity');
if (!$edit_permission) {
return $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;
}