public function WorkspaceListBuilder::getDefaultOperations in Drupal 8
Same name and namespace in other branches
- 9 core/modules/workspaces/src/WorkspaceListBuilder.php \Drupal\workspaces\WorkspaceListBuilder::getDefaultOperations()
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
- core/
modules/ workspaces/ src/ WorkspaceListBuilder.php, line 134
Class
- WorkspaceListBuilder
- Defines a class to build a listing of workspace entities.
Namespace
Drupal\workspacesCode
public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\workspaces\WorkspaceInterface $entity */
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['query']['destination'] = $entity
->toUrl('collection')
->toString();
}
$active_workspace = $this->workspaceManager
->getActiveWorkspace();
if (!$active_workspace || $entity
->id() != $active_workspace
->id()) {
$operations['activate'] = [
'title' => $this
->t('Switch to @workspace', [
'@workspace' => $entity
->label(),
]),
// Use a weight lower than the one of the 'Edit' operation because we
// want the 'Activate' operation to be the primary operation.
'weight' => 0,
'url' => $entity
->toUrl('activate-form', [
'query' => [
'destination' => $entity
->toUrl('collection')
->toString(),
],
]),
];
}
if (!$entity
->hasParent()) {
$operations['deploy'] = [
'title' => $this
->t('Deploy content'),
// The 'Deploy' operation should be the default one for the currently
// active workspace.
'weight' => $active_workspace && $entity
->id() == $active_workspace
->id() ? 0 : 20,
'url' => $entity
->toUrl('deploy-form', [
'query' => [
'destination' => $entity
->toUrl('collection')
->toString(),
],
]),
];
}
else {
/** @var \Drupal\workspaces\WorkspaceInterface $parent */
$parent = $entity->parent->entity;
$operations['merge'] = [
'title' => $this
->t('Merge into @target_label', [
'@target_label' => $parent
->label(),
]),
'weight' => 5,
'url' => Url::fromRoute('entity.workspace.merge_form', [
'source_workspace' => $entity
->id(),
'target_workspace' => $parent
->id(),
], [
'query' => [
'destination' => $entity
->toUrl('collection')
->toString(),
],
]),
];
}
return $operations;
}