diff --git a/src/Controller/TagController.php b/src/Controller/TagController.php index aa6b8c47..a222b6ff 100644 --- a/src/Controller/TagController.php +++ b/src/Controller/TagController.php @@ -51,12 +51,16 @@ class TagController extends AbstractController } $tags = $repository->getTagCount($query); + $multiUpdateForm = $this->getMultiUpdateForm($repository); + if ($multiUpdateForm !== null) { + $multiUpdateForm = $multiUpdateForm->createView(); + } return $this->render('tags/index.html.twig', [ 'tags' => $tags, 'query' => $query, 'toolbarForm' => $form->createView(), - 'multiUpdateForm' => $this->getMultiUpdateForm($repository)->createView(), + 'multiUpdateForm' => $multiUpdateForm, ]); } @@ -145,10 +149,16 @@ class TagController extends AbstractController return $this->redirectToRoute('tags'); } - protected function getMultiUpdateForm(TagRepository $repository): FormInterface + protected function getMultiUpdateForm(TagRepository $repository): ?FormInterface { $dto = new MultiUpdateTableDTO(); - $dto->addDelete($this->generateUrl('tags_multi_delete')); + if ($this->isGranted('delete_tag')) { + $dto->addDelete($this->generateUrl('tags_multi_delete')); + } + + if (!$dto->hasAction()) { + return null; + } return $this->createForm(MultiUpdateTable::class, $dto, [ 'action' => $this->generateUrl('tags'), diff --git a/src/Form/MultiUpdate/MultiUpdateTableDTO.php b/src/Form/MultiUpdate/MultiUpdateTableDTO.php index df5f6a8e..b39a0335 100644 --- a/src/Form/MultiUpdate/MultiUpdateTableDTO.php +++ b/src/Form/MultiUpdate/MultiUpdateTableDTO.php @@ -51,6 +51,11 @@ class MultiUpdateTableDTO return $this->actions; } + public function hasAction(): bool + { + return \count($this->actions) > 1; + } + public function addAction(string $label, string $url): MultiUpdateTableDTO { $this->actions[$label] = $url; diff --git a/templates/tags/index.html.twig b/templates/tags/index.html.twig index 525789b1..cb61a19f 100644 --- a/templates/tags/index.html.twig +++ b/templates/tags/index.html.twig @@ -14,12 +14,19 @@ {{ widgets.nothing_found('kimai.tagUpdate') }} {% else %} - {% set columns = { - 'id': {'class': 'alwaysVisible multiCheckbox', 'orderBy': false, 'title': false, 'html_before': tables.datatable_multiupdate_all()}, + {% set columns = {} %} + + {% if multiUpdateForm is not null %} + {% set columns = columns|merge({ + 'id': {'class': 'alwaysVisible multiCheckbox', 'orderBy': false, 'title': false, 'html_before': tables.datatable_multiupdate_all()}, + }) %} + {% endif %} + + {% set columns = columns|merge({ 'name': {'class': 'alwaysVisible'}, 'amount': {'class': 'text-center w-min'}, 'actions': {'class': 'actions alwaysVisible'}, - } %} + }) %} {% set tableName = 'admin_tags' %} {% set manageAllowed = is_granted('manage_tag') %} @@ -32,7 +39,11 @@ {% endif %}