diff --git a/docs/reference/configuration.rst b/docs/reference/configuration.rst index 655c266f..a168fe00 100644 --- a/docs/reference/configuration.rst +++ b/docs/reference/configuration.rst @@ -10,6 +10,15 @@ Timezone detectors User timezone detector ^^^^^^^^^^^^^^^^^^^^^^ +.. versionadded:: 2.x + + If the model class for the authenticated user implements ``Sonata\IntlBundle\Timezone\TimezoneAwareInterface``, + it returns the timezone from its ``getTimezone()`` method. + +**DEPRECATED** +Relying on ``Sonata\UserBundle\Model\User`` is deprecated since 2.x in favor of +explicit implementation of ``Sonata\IntlBundle\Timezone\TimezoneAwareInterface``. + If the SonataUserBundle_ is enabled, it returns the timezone from the ``Sonata\UserBundle\Model\User::getTimezone()`` method. diff --git a/src/Timezone/UserBasedTimezoneDetector.php b/src/Timezone/UserBasedTimezoneDetector.php index 8c3db76f..0f71ffe6 100644 --- a/src/Timezone/UserBasedTimezoneDetector.php +++ b/src/Timezone/UserBasedTimezoneDetector.php @@ -49,6 +49,13 @@ public function getTimezone() // NEXT_MAJOR: Remove this check when `User` implement `TimezoneAwareInterface` if ($user instanceof User) { + @trigger_error(sprintf( + 'Timezone inference based on the %s class is deprecated since sonata-project/intl-bundle 2.7 and will be dropped in 3.0 version.' + .' Implement %s explicitely in your user class instead.', + User::class, + TimezoneAwareInterface::class + ), E_USER_DEPRECATED); + return $user->getTimezone(); }