diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 53aea1ffaf..4274219298 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -1359,6 +1359,8 @@ final public function setTemplateRegistry(MutableTemplateRegistryInterface $temp } /** + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. Use TemplateRegistry services instead + * * @param array $templates */ public function setTemplates(array $templates) @@ -1370,6 +1372,8 @@ public function setTemplates(array $templates) } /** + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. Use TemplateRegistry services instead + * * @param string $name * @param string $template */ @@ -3262,24 +3266,43 @@ public function canAccessObject($action, $object) } /** - * @return string[] + * @return MutableTemplateRegistryInterface */ - protected function configureExportFields(): array + final public function getTemplateRegistry() { - return $this->getModelManager()->getExportFields($this->getClass()); + // NEXT_MAJOR: Remove the deprecation and uncomment the exception. + if (!$this->hasTemplateRegistry()) { + @trigger_error(sprintf( + 'Calling %s() when there is no template registry is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw an exception in 4.0.' + .' Use %s::hasTemplateRegistry() to know if the template registry is set.', + __METHOD__, + __CLASS__ + ), E_USER_DEPRECATED); + } + //if (false === $this->hasTemplateRegistry()) { + // throw new \LogicException(sprintf('Unable to find the template registry for admin `%s`.', static::class)); + //} + + return $this->templateRegistry; } - protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface + final public function hasTemplateRegistry(): bool { - return $query; + return null !== $this->templateRegistry; } /** - * @return MutableTemplateRegistryInterface + * @return string[] */ - final protected function getTemplateRegistry() + protected function configureExportFields(): array { - return $this->templateRegistry; + return $this->getModelManager()->getExportFields($this->getClass()); + } + + protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface + { + return $query; } /** diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index 8ff6a9a397..32fc789e91 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -27,6 +27,7 @@ use Sonata\AdminBundle\Object\MetadataInterface; use Sonata\AdminBundle\Route\RouteGeneratorInterface; use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface; +use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface; use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Form\Validator\ErrorElement; @@ -39,31 +40,32 @@ /** * @author Thomas Rabaix * - * @method array configureActionButtons(string $action, ?object $object = null) - * @method string getSearchResultLink(object $object) - * @method void showMosaicButton(bool $isShown) - * @method bool isDefaultFilter(string $name) // NEXT_MAJOR: Remove this - * @method bool isCurrentRoute(string $name, ?string $adminCode) - * @method bool canAccessObject(string $action, object $object) - * @method mixed getPersistentParameter(string $name) - * @method array getExportFields() - * @method array getSubClasses() - * @method AdminInterface getRoot() - * @method string getRootCode() - * @method array getActionButtons(string $action, ?object $object) - * @method FieldDescriptionCollection|null getList() - * @method void setFilterPersister(?FilterPersisterInterface $filterPersister = null) - * @method string getBaseRoutePattern() - * @method string getBaseRouteName() - * @method ItemInterface getSideMenu(string $action, ?AdminInterface $childAdmin = null) - * @method void addParentAssociationMapping(string $code, string $value) - * @method RouteGeneratorInterface getRouteGenerator() - * @method string getClassnameLabel() - * @method AdminInterface|null getCurrentChildAdmin() - * @method string|null getParentAssociationMapping() - * @method void reorderFormGroup(string $group, array $keys) - * @method void defineFormBuilder(FormBuilderInterface $formBuilder) - * @method string getPagerType() + * @method array configureActionButtons(string $action, ?object $object = null) + * @method string getSearchResultLink(object $object) + * @method void showMosaicButton(bool $isShown) + * @method bool isDefaultFilter(string $name) // NEXT_MAJOR: Remove this + * @method bool isCurrentRoute(string $name, ?string $adminCode) + * @method bool canAccessObject(string $action, object $object) + * @method mixed getPersistentParameter(string $name) + * @method array getExportFields() + * @method array getSubClasses() + * @method AdminInterface getRoot() + * @method string getRootCode() + * @method array getActionButtons(string $action, ?object $object) + * @method FieldDescriptionCollection|null getList() + * @method void setFilterPersister(?FilterPersisterInterface $filterPersister = null) + * @method string getBaseRoutePattern() + * @method string getBaseRouteName() + * @method ItemInterface getSideMenu(string $action, ?AdminInterface $childAdmin = null) + * @method void addParentAssociationMapping(string $code, string $value) + * @method RouteGeneratorInterface getRouteGenerator() + * @method string getClassnameLabel() + * @method AdminInterface|null getCurrentChildAdmin() + * @method string|null getParentAssociationMapping() + * @method void reorderFormGroup(string $group, array $keys) + * @method void defineFormBuilder(FormBuilderInterface $formBuilder) + * @method string getPagerType() + * @method MutableTemplateRegistryInterface getTemplateRegistry() * * @phpstan-template T of object * @phpstan-extends AccessRegistryInterface @@ -592,6 +594,9 @@ public function isChild(); */ public function getTemplate($name); + // NEXT_MAJOR: uncomment this method in 4.0 + //public function getTemplateRegistry(): MutableTemplateRegistryInterface; + /** * Set the translation domain. *