$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['publish'
] =
[ 'title' =>
$this->
t('Publish content'
),
// The 'Publish' operation should be the default one for the currently
// active workspace.
'weight'
=> ($active_workspace &&
$entity->
id() ==
$active_workspace->
id()) ? 0 : 20,
'url' => Url::
fromRoute('entity.workspace.publish_form',
['workspace' =>
$entity->
id()],
['query' =>
['destination' =>
$entity->
toUrl('collection'
)->
toString()]] ),
];
}