Skip to content

Commit

Permalink
minor #4032 In Config\Actions class: add missing styles for built-in …
Browse files Browse the repository at this point in the history
…actions (freepius)

This PR was merged into the 3.0.x-dev branch.

Discussion
----------

In Config\Actions class: add missing styles for built-in actions

(Even if these actions are not enabled by default)

Indeed, it avoids us to write the following code, just to add the normal styles:

```twig
$actions->add(Crud::PAGE_EDIT, Action::INDEX);
$actions->update(Crud::PAGE_EDIT, Action::INDEX, fn (Action $action) => $action->addCssClass.... etc etc);
```

Commits
-------

ff1108d In Config\Actions class: add missing styles for built-in actions (even if these actions are not enabled by default)
  • Loading branch information
javiereguiluz committed Dec 14, 2020
2 parents eb81a1e + ff1108d commit 509363d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ These are the built-in actions included by default in each page:
* Page ``Crud::PAGE_EDIT`` (``'edit'``):

* Added by default: ``Action::SAVE_AND_RETURN``, ``Action::SAVE_AND_CONTINUE``
* Other available actions: ``Action::DELETE``, ``Action::INDEX``
* Other available actions: ``Action::DELETE``, ``Action::DETAIL``, ``Action::INDEX``

* Page ``Crud::PAGE_NEW`` (``'new'``):

Expand Down
7 changes: 4 additions & 3 deletions src/Config/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,18 @@ private function createBuiltInAction(string $pageName, string $actionName): Acti

if (Action::DETAIL === $actionName) {
return Action::new(Action::DETAIL, '__ea__action.detail')
->linkToCrudAction(Action::DETAIL);
->linkToCrudAction(Action::DETAIL)
->addCssClass(Crud::PAGE_EDIT === $pageName ? 'btn btn-secondary' : '');
}

if (Action::INDEX === $actionName) {
return Action::new(Action::INDEX, '__ea__action.index')
->linkToCrudAction(Action::INDEX)
->addCssClass(Crud::PAGE_DETAIL === $pageName ? 'btn btn-secondary' : '');
->addCssClass(\in_array($pageName, [Crud::PAGE_DETAIL, Crud::PAGE_EDIT, Crud::PAGE_NEW], true) ? 'btn btn-secondary' : '');
}

if (Action::DELETE === $actionName) {
$cssClass = Crud::PAGE_DETAIL === $pageName ? 'btn btn-link pr-0 text-danger' : 'text-danger';
$cssClass = \in_array($pageName, [Crud::PAGE_DETAIL, Crud::PAGE_EDIT], true) ? 'btn btn-link pr-0 text-danger' : 'text-danger';

return Action::new(Action::DELETE, '__ea__action.delete', Crud::PAGE_INDEX === $pageName ? null : 'fa fa-fw fa-trash-o')
->linkToCrudAction(Action::DELETE)
Expand Down

0 comments on commit 509363d

Please sign in to comment.