-
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.
Add 'setPreferredLocaleActions' with custom route pattern and params
- Loading branch information
1 parent
9e8a519
commit d3cf270
Showing
2 changed files
with
46 additions
and
1 deletion.
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