Skip to content

Commit

Permalink
deprecate methods & parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tambait committed Dec 10, 2020
1 parent f92f8fc commit c05d7f2
Showing 1 changed file with 88 additions and 3 deletions.
91 changes: 88 additions & 3 deletions src/Twig/Extension/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
*/
class SonataAdminExtension extends AbstractExtension
{
/**
* NEXT_MAJOR: Remove this constant.
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
// @todo: there are more locales which are not supported by moment and they need to be translated/normalized/canonicalized here
public const MOMENT_UNSUPPORTED_LOCALES = [
'de' => ['de', 'de-at'],
Expand All @@ -68,7 +73,11 @@ class SonataAdminExtension extends AbstractExtension
protected $translator;

/**
* NEXT_MAJOR: Remove this property.
*
* @var string[]
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
private $xEditableTypeMapping = [];

Expand All @@ -78,7 +87,11 @@ class SonataAdminExtension extends AbstractExtension
private $templateRegistries;

/**
* NEXT_MAJOR: Remove this property.
*
* @var AuthorizationCheckerInterface
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
private $securityChecker;

Expand All @@ -96,14 +109,14 @@ public function __construct(
$translator = null,
?ContainerInterface $templateRegistries = null,
$propertyAccessorOrSecurityChecker = null,
?AuthorizationCheckerInterface $securityChecker = null
?AuthorizationCheckerInterface $securityChecker = null //NEXT_MAJOR: Remove this parameter
) {
// NEXT_MAJOR: make the translator parameter required, move TranslatorInterface check to method signature
// and remove this block

if (null === $translator) {
@trigger_error(
'The $translator parameter will be required fields with the 4.0 release.',
'The $translator parameter will be required field with the 4.0 release.',
E_USER_DEPRECATED
);
} else {
Expand Down Expand Up @@ -162,7 +175,7 @@ public function __construct(
$this->propertyAccessor = $pool->getPropertyAccessor();
$this->securityChecker = $securityChecker;
} else {
$this->securityChecker = $securityChecker;
$this->securityChecker = $securityChecker; //NEXT_MAJOR: Remove this property
$this->propertyAccessor = $propertyAccessorOrSecurityChecker;
}

Expand Down Expand Up @@ -210,10 +223,12 @@ public function getFilters()
'sonata_urlsafeid',
[$this, 'getUrlSafeIdentifier']
),
//NEXT_MAJOR remove this filter
new TwigFilter(
'sonata_xeditable_type',
[$this, 'getXEditableType']
),
//NEXT_MAJOR remove this filter
new TwigFilter(
'sonata_xeditable_choices',
[$this, 'getXEditableChoices']
Expand All @@ -222,7 +237,11 @@ public function getFilters()
}

/**
* NEXT_MAJOR: Remove this method.
*
* @return TwigFunction[]
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getFunctions()
{
Expand Down Expand Up @@ -521,32 +540,65 @@ public function getUrlSafeIdentifier($model, ?AdminInterface $admin = null)
}

/**
* NEXT_MAJOR: Remove this method.
*
* @param string[] $xEditableTypeMapping
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function setXEditableTypeMapping($xEditableTypeMapping)
{
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'The %s method is deprecated in favor of XEditableExtension::setXEditableTypeMapping since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$this->xEditableTypeMapping = $xEditableTypeMapping;
}

/**
* NEXT_MAJOR: Remove this method.
*
* @return string|bool
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getXEditableType($type)
{
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'The %s method is deprecated in favor of XEditableExtension::getXEditableType since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

return $this->xEditableTypeMapping[$type] ?? false;
}

/**
* NEXT_MAJOR: Remove this method.
*
* Return xEditable choices based on the field description choices options & catalogue options.
* With the following choice options:
* ['Status1' => 'Alias1', 'Status2' => 'Alias2']
* The method will return:
* [['value' => 'Status1', 'text' => 'Alias1'], ['value' => 'Status2', 'text' => 'Alias2']].
*
* @return array
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function getXEditableChoices(FieldDescriptionInterface $fieldDescription)
{
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'The %s method is deprecated in favor of XEditableExtension::getXEditableChoices since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$choices = $fieldDescription->getOption('choices', []);
$catalogue = $fieldDescription->getOption('catalogue');
$xEditableChoices = [];
Expand Down Expand Up @@ -588,13 +640,24 @@ public function getXEditableChoices(FieldDescriptionInterface $fieldDescription)
}

/**
* NEXT_MAJOR: Remove this method.
*
* Returns a canonicalized locale for "moment" NPM library,
* or `null` if the locale's language is "en", which doesn't require localization.
*
* @return string|null
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
final public function getCanonicalizedLocaleForMoment(array $context)
{
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'The %s method is deprecated in favor of CanonicalizeExtension::getCanonicalizedLocaleForMoment since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$locale = strtolower(str_replace('_', '-', $context['app']->getRequest()->getLocale()));

// "en" language doesn't require localization.
Expand All @@ -612,13 +675,24 @@ final public function getCanonicalizedLocaleForMoment(array $context)
}

/**
* NEXT_MAJOR: Remove this method.
*
* Returns a canonicalized locale for "select2" NPM library,
* or `null` if the locale's language is "en", which doesn't require localization.
*
* @return string|null
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
final public function getCanonicalizedLocaleForSelect2(array $context)
{
if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
@trigger_error(sprintf(
'The %s method is deprecated in favor of CanonicalizeExtension::getCanonicalizedLocaleForSelect2 since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$locale = str_replace('_', '-', $context['app']->getRequest()->getLocale());

// "en" language doesn't require localization.
Expand Down Expand Up @@ -646,14 +720,25 @@ final public function getCanonicalizedLocaleForSelect2(array $context)
}

/**
* NEXT_MAJOR: Remove this method.
*
* @param string|array $role
* @param object|null $object
* @param string|null $field
*
* @return bool
*
* @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0
*/
public function isGrantedAffirmative($role, $object = null, $field = null)
{
if ('sonata_deprecation_mute' !== (\func_get_args()[3] ?? null)) {
@trigger_error(sprintf(
'The %s method is deprecated in favor of SecurityExtension::isGrantedAffirmative since version 3.x and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

if (null === $this->securityChecker) {
return false;
}
Expand Down

0 comments on commit c05d7f2

Please sign in to comment.