public function Common::userAllowedActions in Filebrowser 8.2
Same name and namespace in other branches
- 3.x src/Services/Common.php \Drupal\filebrowser\Services\Common::userAllowedActions()
Returns an array containing the allowed actions for logged in user. Array is used to complete building the form ActionForm.php
array with the following keys: 'operation': the form action id that this element will trigger 'title': title for the form element 'type': 'link' will create a link that opens in a slide-down window 'button' will create a button that opens in a slide-down window 'default' creates a normal submit button 'needs_item': this element needs items selected on the form
Parameters
$node:
Return value
array
File
- src/
Services/ Common.php, line 305
Class
- Common
- Class Common @package Drupal\filebrowser\Services
Namespace
Drupal\filebrowser\ServicesCode
public function userAllowedActions($node) {
/** @var \Drupal\filebrowser\Filebrowser $filebrowser */
$actions = [];
$account = \Drupal::currentUser();
$filebrowser = $node->filebrowser;
// needs_item indicates this button needs items selected on the form
// Upload button
if ($filebrowser->enabled && $account
->hasPermission(Common::FILE_UPLOAD)) {
$actions[] = [
'operation' => 'upload',
'title' => $this
->t('Upload'),
'type' => 'link',
'needs_item' => FALSE,
'route' => 'filebrowser.action',
];
}
//Create folder
if ($filebrowser->createFolders && $account
->hasPermission(Common::CREATE_FOLDER)) {
$actions[] = [
'operation' => 'folder',
'title' => $this
->t('Add folder'),
'needs_item' => FALSE,
'type' => 'link',
];
}
// Delete items button
if ($account
->hasPermission(Common::DELETE_FILES)) {
$actions[] = [
'operation' => 'delete',
'title' => $this
->t('Delete'),
'needs_item' => TRUE,
'type' => 'button',
];
}
// Rename items button
if ($filebrowser->enabled && $account
->hasPermission(Common::RENAME_FILES)) {
$actions[] = [
'operation' => 'rename',
'title' => $this
->t('Rename items'),
'needs_item' => TRUE,
'type' => 'button',
];
}
// Edit description button
if ($filebrowser->enabled && $account
->hasPermission(Common::EDIT_DESCRIPTION)) {
$actions[] = [
'operation' => 'description',
'title' => $this
->t('Edit description'),
'needs_item' => TRUE,
'type' => 'button',
];
}
if ($this
->canDownloadArchive($node) && function_exists('zip_open')) {
$actions[] = [
'operation' => 'archive',
'title' => $this
->t('Download archive'),
'needs_item' => TRUE,
'type' => 'default',
];
}
return $actions;
}