-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SoantaExtraBundle] Allow AdminAction to generate multiple actions "b…
…uttons" (#298) --------- Co-authored-by: Martin Poirier Théorêt <[email protected]>
- Loading branch information
1 parent
82dffeb
commit aa87229
Showing
8 changed files
with
236 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Admin; | ||
|
||
use App\Entity\User; | ||
use Draw\Bundle\SonataExtraBundle\ActionableAdmin\ObjectActionExecutioner; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Attribute\AsController; | ||
|
||
#[AsController] | ||
class SetPreferredLocaleAction | ||
{ | ||
public function __invoke( | ||
Request $request, | ||
ObjectActionExecutioner $objectActionExecutioner, | ||
): Response { | ||
return $objectActionExecutioner->execute( | ||
static function (User $user) use ($request, $objectActionExecutioner): void { | ||
$user->setPreferredLocale($request->get('_locale') ?? 'en'); | ||
|
||
$objectActionExecutioner->getAdmin()->update($user); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
packages/sonata-extra-bundle/Resources/views/Action/action.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{% for action in item.action.actions %} | ||
<li> | ||
<a class="sonata-action-element" href="{{ object is defined ? admin.generateObjectUrl(item.action.name, object) : admin.generateUrl(item.action.name) }}"> | ||
{% if item.action.icon %} | ||
<i class="{{ item.action.icon }}" aria-hidden="true"></i> | ||
<a class="sonata-action-element" href="{{ action.generateUrl(admin, object) }}"> | ||
{% if action.icon %} | ||
<i class="{{ action.icon }}" aria-hidden="true"></i> | ||
{% endif %} | ||
{{ item.action|translate_label }} | ||
{{ action|translate_label }} | ||
</a> | ||
</li> | ||
</li> | ||
{% endfor %} |
16 changes: 9 additions & 7 deletions
16
packages/sonata-extra-bundle/Resources/views/Action/list_action.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{% if admin.hasAccess(actions.action.name, object) %} | ||
<a class="btn btn-sm btn-default" href="{{ admin.generateObjectUrl(actions.action.name, object) }}"> | ||
{% if actions.action.icon %} | ||
<i class="{{ actions.action.icon }}" aria-hidden="true"></i> | ||
{% endif %} | ||
{{ actions.action|translate_label }} | ||
</a> | ||
{% endif %} | ||
{% for action in actions.action.actions %} | ||
<a class="btn btn-sm btn-default" href="{{ action.generateUrl(admin, object) }}"> | ||
{% if action.icon %} | ||
<i class="{{ action.icon }}" aria-hidden="true"></i> | ||
{% endif %} | ||
{{ action|translate_label }} | ||
</a> | ||
{% endfor %} | ||
{% endif %} |
96 changes: 96 additions & 0 deletions
96
packages/sonata-extra-bundle/Test/AdminTestHelperTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Bundle\SonataExtraBundle\Test; | ||
|
||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
use Symfony\Component\DomCrawler\Link; | ||
|
||
trait AdminTestHelperTrait | ||
{ | ||
protected function selectListObjectLink( | ||
Crawler $crawler, | ||
int|string $identifier, | ||
string $action, | ||
): Link { | ||
return $crawler | ||
->filter(\sprintf('.sonata-ba-list-field-actions[objectid="%s"]', $identifier)) | ||
->selectLink($action) | ||
->link() | ||
; | ||
} | ||
|
||
protected function selectMenuObjectLink( | ||
Crawler $crawler, | ||
string $action, | ||
): Link { | ||
return $crawler | ||
->filter('ul.dropdown-menu') | ||
->selectLink($action) | ||
->link() | ||
; | ||
} | ||
|
||
protected function submitBatchAction( | ||
KernelBrowser $client, | ||
array $indexes, | ||
string $action, | ||
string $button = 'OK', | ||
): void { | ||
$crawler = $client->submitForm( | ||
$button, | ||
[ | ||
'idx' => $indexes, | ||
'action' => $action, | ||
] | ||
); | ||
|
||
$client->submit( | ||
$crawler->selectButton('Yes, execute')->form() | ||
); | ||
} | ||
|
||
protected function appendDefaultFiltersToListUrl(string $listUrl): string | ||
{ | ||
return \sprintf( | ||
'%s%s%s', | ||
$listUrl, | ||
null === parse_url($listUrl, \PHP_URL_QUERY) ? '?' : '&', | ||
http_build_query( | ||
[ | ||
'filter' => [ | ||
'_page' => 1, | ||
'_per_page' => 25, | ||
], | ||
] | ||
) | ||
); | ||
} | ||
|
||
protected function filterListByIdentifier( | ||
KernelBrowser $client, | ||
string $listUrl, | ||
int|string $identifier, | ||
string $identifierName = 'id', | ||
): Crawler { | ||
return $client->request( | ||
'GET', | ||
\sprintf( | ||
'%s?%s', | ||
$listUrl, | ||
http_build_query( | ||
[ | ||
'filter' => [ | ||
$identifierName => [ | ||
'type' => 3, | ||
'value' => $identifier, | ||
], | ||
], | ||
] | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters