protected function TFTController::add_content_links in Taxonomy File Tree 3.x
Same name and namespace in other branches
- 8 src/Controller/TFTController.php \Drupal\tft\Controller\TFTController::add_content_links()
Render the add file and add folder links.
1 call to TFTController::add_content_links()
- TFTController::content_table in src/
Controller/ TFTController.php - Get the folder content in HTML table form.
File
- src/
Controller/ TFTController.php, line 230
Class
- TFTController
- Class TFTController.
Namespace
Drupal\tft\ControllerCode
protected function add_content_links($tid = 0, $gid = NULL) {
$items = [];
$tempstore = \Drupal::service('tempstore.private')
->get('tft');
$add_file_query = [
'destination' => $tempstore
->get('q'),
];
$add_term_query = [
'destination' => $tempstore
->get('q'),
];
// Do we have a tid ?
if ($tid) {
$add_file_query['tid'] = $tid;
$add_term_query['parent'] = $tid;
if (!$gid) {
$gid = _tft_get_group_gid($tid);
}
}
$group = Group::load($gid);
$user = $this
->currentUser();
// Can the user add terms anywhere, only under Group or never ?
if ($user
->hasPermission(TFT_ADD_TERMS) || $group && $group
->hasPermission(TFT_ADD_TERMS, $user)) {
$query = UrlHelper::buildQuery(array_reverse($add_term_query));
$items[] = [
'#wrapper_attributes' => [
'class' => 'folder-add-content-link',
],
'#type' => 'link',
'#title' => Markup::create('<i class="fi fi-rr-folder-add"></i>' . $this
->t("Add a folder")),
'#url' => Url::fromUri("internal:/tft/term/add?{$query}"),
'#attributes' => [
'id' => 'add-child-folder',
],
];
}
// Can the user create files ?
if ($user
->hasPermission('create media')) {
// Can they add files in this context ?
if ($user
->hasPermission(TFT_ADD_FILE) || $group && $group
->hasPermission(TFT_ADD_FILE, $user)) {
$query = UrlHelper::buildQuery(array_reverse($add_file_query));
$items[] = [
'#wrapper_attributes' => [
'class' => 'folder-add-content-link',
],
'#type' => 'link',
'#title' => Markup::create('<i class="fi fi-rr-file-add"></i>' . $this
->t("Add a file")),
'#url' => Url::fromUri("internal:/media/add/tft_file?{$query}"),
'#attributes' => [
'id' => 'add-child-file',
],
];
}
}
return [
'#theme' => 'item_list',
'#list_type' => 'ul',
'#attributes' => [
'id' => 'folder-add-content-links',
],
'#items' => $items,
];
}