public function MaestroTemplateListBuilder::getOperations in Maestro 3.x
Same name and namespace in other branches
- 8.2 src/Controller/MaestroTemplateListBuilder.php \Drupal\maestro\Controller\MaestroTemplateListBuilder::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/
Controller/ MaestroTemplateListBuilder.php, line 76
Class
- MaestroTemplateListBuilder
- Provides a listing of Maestro Template entities.
Namespace
Drupal\maestro\ControllerCode
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$user = \Drupal::currentUser();
/*
* Check and see if the maestro task console is enabled
*/
if (\Drupal::moduleHandler()
->moduleExists('maestro_template_builder')) {
$operations['tasks'] = [
'title' => t('Task Editor'),
'url' => Url::fromUserInput('/template-builder/' . $entity->id),
'weight' => 1,
];
}
if ($user
->hasPermission('start template ' . $entity->id)) {
$operations['start_process'] = [
'title' => t('Start Process'),
'url' => Url::fromRoute('maestro.start_process', [
'templateMachineName' => $entity->id,
]),
'weight' => 10,
];
}
/*
* Check to see if the current user has permission to start this process
*/
if (\Drupal::currentUser()
->hasPermission('administer maestro templates')) {
$operations['edit']['title'] = t('Edit Template');
$operations['edit']['weight'] = 5;
$operations['edit']['url'] = Url::fromRoute('entity.maestro_template.edit_form', [
'maestro_template' => $entity->id,
]);
// Weight sorting seemingly wasn't happening. Just making sure I can sort by weight for our purposes.
uasort($operations, '\\Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
}
else {
// Make sure the edit is unset for those without this permission.
unset($operations['edit']);
}
return $operations;
}