Skip to content

Commit

Permalink
Added page actions for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jun 30, 2020
1 parent 411d689 commit 291ed38
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion system/src/Grav/Common/Flex/Types/Pages/PageIndex.php
Expand Up @@ -471,7 +471,7 @@ protected function getLevelListingRecurse(array $options): array
'visible' => $child->visible(),
'routable' => $child->routable(),
'tags' => $tags,
'actions' => null,
'actions' => $this->getListingActions($child),
];
$extras = array_filter($extras, static function ($v) {
return $v !== null;
Expand Down Expand Up @@ -522,6 +522,24 @@ protected function getLevelListingRecurse(array $options): array
return [$status, $msg ?? 'PLUGIN_ADMIN.NO_ROUTE_PROVIDED', $response, $path];
}

protected function getListingActions(PageObject $object): array
{
$actions = [];
if ($object->isAuthorized('read')) {
$actions[] = 'preview';
$actions[] = 'edit';
}
if ($object->isAuthorized('update')) {
$actions[] = 'copy';
$actions[] = 'move';
}
if ($object->isAuthorized('delete')) {
$actions[] = 'delete';
}

return $actions;
}

/**
* @param FlexStorageInterface $storage
* @return CompiledJsonFile|\Grav\Common\File\CompiledYamlFile|null
Expand Down

0 comments on commit 291ed38

Please sign in to comment.