-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add support for symfony contracts translator interface #6342
Closed
Closed
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
41ade71
Add support for contracts translator interface to prepare for symfony 5
dmaicher 007c5e1
add one more test
dmaicher 5eb6cab
add one more test
dmaicher a7a88e1
ignore test when legacy interface does not exist
dmaicher 96ae31c
support transChoice with contracts interface
dmaicher b9c0db5
fix CS
dmaicher ad2ed34
change AdminInterface
dmaicher b1facc4
Apply suggestions from code review
dmaicher 296a8fd
fixes
dmaicher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -52,9 +52,10 @@ | |
use Symfony\Component\Routing\Generator\UrlGeneratorInterface as RoutingUrlGeneratorInterface; | ||
use Symfony\Component\Security\Acl\Model\DomainObjectInterface; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; | ||
use Symfony\Component\Validator\Mapping\GenericMetadata; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
|
@@ -309,7 +310,7 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A | |
* | ||
* NEXT_MAJOR: remove this property | ||
* | ||
* @var \Symfony\Component\Translation\TranslatorInterface | ||
* @var TranslatorInterface|LegacyTranslatorInterface | ||
* | ||
* @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 | ||
*/ | ||
|
@@ -2443,7 +2444,11 @@ public function transChoice($id, $count, array $parameters = [], $domain = null, | |
|
||
$domain = $domain ?: $this->getTranslationDomain(); | ||
|
||
return $this->translator->transChoice($id, $count, $parameters, $domain, $locale); | ||
if ($this->translator instanceof LegacyTranslatorInterface) { | ||
return $this->translator->transChoice($id, $count, $parameters, $domain, $locale); | ||
} | ||
|
||
return $this->translator->trans($id, ['%count%' => $count] + $parameters, $domain, $locale); | ||
dmaicher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public function setTranslationDomain($translationDomain) | ||
|
@@ -2461,9 +2466,11 @@ public function getTranslationDomain() | |
* | ||
* NEXT_MAJOR: remove this method | ||
* | ||
* @param LegacyTranslatorInterface|TranslatorInterface $translator | ||
* | ||
* @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 | ||
*/ | ||
public function setTranslator(TranslatorInterface $translator) | ||
public function setTranslator($translator) | ||
dmaicher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$args = \func_get_args(); | ||
if (isset($args[1]) && $args[1]) { | ||
|
@@ -2473,6 +2480,16 @@ public function setTranslator(TranslatorInterface $translator) | |
), E_USER_DEPRECATED); | ||
} | ||
|
||
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) { | ||
throw new \TypeError(sprintf( | ||
'Argument 1 passed to "%s()" must be an instance of "%s" or "%s", %s given.', | ||
__METHOD__, | ||
LegacyTranslatorInterface::class, | ||
TranslatorInterface::class, | ||
\is_object($translator) ? 'instance of '.\get_class($translator) : \gettype($translator) | ||
)); | ||
} | ||
|
||
$this->translator = $translator; | ||
} | ||
|
||
|
@@ -2482,6 +2499,8 @@ public function setTranslator(TranslatorInterface $translator) | |
* NEXT_MAJOR: remove this method | ||
* | ||
* @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 | ||
* | ||
* @return LegacyTranslatorInterface|TranslatorInterface | ||
*/ | ||
public function getTranslator() | ||
{ | ||
|
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 |
---|---|---|
|
@@ -33,8 +33,9 @@ | |
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
|
@@ -64,6 +65,7 @@ | |
* @method void reorderFormGroup(string $group, array $keys) | ||
* @method void defineFormBuilder(FormBuilderInterface $formBuilder) | ||
* @method string getPagerType() | ||
* @method void setTranslator($translator); | ||
dmaicher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
interface AdminInterface extends AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface | ||
{ | ||
|
@@ -90,10 +92,8 @@ public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder); | |
*/ | ||
public function getDatagridBuilder(); | ||
|
||
public function setTranslator(TranslatorInterface $translator); | ||
|
||
/** | ||
* @return TranslatorInterface | ||
* @return TranslatorInterface|LegacyTranslatorInterface | ||
*/ | ||
public function getTranslator(); | ||
|
||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnt this available on sf4.4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in master the compat code can be droped safely right? if thats the case we should add next major cments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed. On master it can be typehinted with
Symfony\Contracts\Translation\TranslatorInterface
and we can drop all usages of the old legacy interfaceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But actually on master most usages should be fully removed anyway 😊
See https://github.com/sonata-project/SonataAdminBundle/pull/6342/files#diff-61e6d1f8fafe87b868adbe28ce0ba8f6R311
https://github.com/sonata-project/SonataAdminBundle/pull/6342/files#diff-61e6d1f8fafe87b868adbe28ce0ba8f6R2467
https://github.com/sonata-project/SonataAdminBundle/pull/6342/files#diff-30aa995d1ac562ec3c1e60958ab6032fR49
etc