Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom ModelManagerException messages #8141

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ It's auto-generated by sonata-project/dev-kit package.
<env name="KERNEL_CLASS" value="\Sonata\AdminBundle\Tests\App\AppKernel" />
<server name="APP_ENV" value="test" force="true" />
<server name="APP_DEBUG" value="false" />
<ini name="memory_limit" value="256M" />
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
</php>
</phpunit>
1 change: 1 addition & 0 deletions src/Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ protected function getBaseTemplate(): string

/**
* @throws \Exception
* @return string|null|void A custom error message to display in the flag bag instead of the generic one
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
*/
protected function handleModelManagerException(\Exception $exception)
{
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
{
/**
* @psalm-suppress UndefinedInterfaceMethod
* @psalm-suppress PossiblyNullReference - end() can return null, apparently

Check failure on line 177 in src/DependencyInjection/Configuration.php

View workflow job for this annotation

GitHub Actions / Psalm

UnusedPsalmSuppress

src/DependencyInjection/Configuration.php:177:24: UnusedPsalmSuppress: This suppression is never used (see https://psalm.dev/207)
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
*
* @see https://github.com/psalm/psalm-plugin-symfony/issues/174
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
use Exception;
use Sonata\AdminBundle\Controller\CRUDController;

/**
* @phpstan-extends CRUDController<object>
*/
final class CustomModelManagerExceptionMessageController extends CRUDController
{
public const ERROR_MESSAGE = 'message from model manager exception';

protected function handleModelManagerException(Exception $exception)
protected function handleModelManagerException(Exception $exception): string
{
return self::ERROR_MESSAGE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\AdminBundle\Exception\ModelManagerThrowable;

/**
* @phpstan-extends CRUDController<object>
*/
final class CustomModelManagerThrowableMessageController extends CRUDController
{
public const ERROR_MESSAGE = 'message from model manager throwable';

protected function handleModelManagerThrowable(ModelManagerThrowable $exception)
protected function handleModelManagerThrowable(ModelManagerThrowable $exception): string
{
return self::ERROR_MESSAGE;
}
Expand Down
Loading