protected function TFTController::operation_links in Taxonomy File Tree 3.x
Same name and namespace in other branches
- 8 src/Controller/TFTController.php \Drupal\tft\Controller\TFTController::operation_links()
Return an <ul> with links for the current folder.
Return value
array The render array
1 call to TFTController::operation_links()
- TFTController::get_content in src/
Controller/ TFTController.php - Returns folder content.
File
- src/
Controller/ TFTController.php, line 71
Class
- TFTController
- Class TFTController.
Namespace
Drupal\tft\ControllerCode
protected function operation_links($type, $id, $media = NULL, $gid = NULL) {
$links = [];
/** @var \Drupal\Core\TempStore\PrivateTempStore $tempstore */
$tempstore = \Drupal::service('tempstore.private')
->get('tft');
$query = 'destination=' . $tempstore
->get('q');
switch ($type) {
case 'folder':
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = Group::load($gid);
$user = $this
->currentUser();
$edit = FALSE;
// Hide edit link if the user has no access.
if ($user
->hasPermission(TFT_ADD_TERMS) || $group && $group
->hasPermission(TFT_ADD_TERMS, $user)) {
$edit = TRUE;
$links[] = [
'#type' => 'link',
'#title' => $this
->t("edit"),
'#url' => Url::fromUri("internal:/tft/term/edit/{$id}?" . $query),
'#attributes' => [
'class' => 'ops-link term-edit-link',
],
];
}
if ($user
->hasPermission(TFT_DELETE_TERMS) || $group && $group
->hasPermission(TFT_DELETE_TERMS, $user)) {
if ($edit) {
$links[] = [
'#markup' => ' | ',
];
}
$links[] = [
'#type' => 'link',
'#title' => $this
->t("delete"),
'#url' => Url::fromUri("internal:/tft/term/delete/{$id}?" . $query),
'#attributes' => [
'class' => 'ops-link term-edit-link',
],
];
}
break;
case 'file':
/** @var \Drupal\media\Entity\Media $media */
if ($media
->access('update')) {
$links[] = [
'#type' => 'link',
'#title' => $this
->t("edit"),
'#url' => Url::fromUri("internal:/media/{$id}/edit?" . $query),
'#attributes' => [
'class' => 'ops-link node-edit-link',
],
];
$links[] = [
'#markup' => ' | ',
];
}
if ($media
->access('delete')) {
$links[] = [
'#type' => 'link',
'#title' => $this
->t("delete"),
'#url' => Url::fromRoute('entity.media.delete_form', [
'media' => $id,
]),
'#attributes' => [
'class' => 'ops-link',
],
];
}
break;
}
return [
'data' => $links,
];
}