diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 53aea1ffaf2..bd23fe45039 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.34, will be dropped in 4.0. Use TemplateRegistry services instead + * * @param string $name * @param string $template */ @@ -3061,9 +3065,7 @@ public function configureActionButtons($action, $object = null) && $this->hasAccess('create') ) { $list['create'] = [ - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('button_create'), -// 'template' => $this->getTemplateRegistry()->getTemplate('button_create'), + 'template' => $this->getTemplateRegistry()->getTemplate('button_create'), ]; } @@ -3072,9 +3074,7 @@ public function configureActionButtons($action, $object = null) && $this->canAccessObject('edit', $object) ) { $list['edit'] = [ - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('button_edit'), - //'template' => $this->getTemplateRegistry()->getTemplate('button_edit'), + 'template' => $this->getTemplateRegistry()->getTemplate('button_edit'), ]; } @@ -3083,9 +3083,7 @@ public function configureActionButtons($action, $object = null) && $this->canAccessObject('history', $object) ) { $list['history'] = [ - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('button_history'), - // 'template' => $this->getTemplateRegistry()->getTemplate('button_history'), + 'template' => $this->getTemplateRegistry()->getTemplate('button_history'), ]; } @@ -3095,9 +3093,7 @@ public function configureActionButtons($action, $object = null) && $this->canAccessObject('acl', $object) ) { $list['acl'] = [ - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('button_acl'), - // 'template' => $this->getTemplateRegistry()->getTemplate('button_acl'), + 'template' => $this->getTemplateRegistry()->getTemplate('button_acl'), ]; } @@ -3107,9 +3103,7 @@ public function configureActionButtons($action, $object = null) && \count($this->getShow()) > 0 ) { $list['show'] = [ - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('button_show'), - // 'template' => $this->getTemplateRegistry()->getTemplate('button_show'), + 'template' => $this->getTemplateRegistry()->getTemplate('button_show'), ]; } @@ -3118,9 +3112,7 @@ public function configureActionButtons($action, $object = null) && $this->hasAccess('list') ) { $list['list'] = [ - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('button_list'), - // 'template' => $this->getTemplateRegistry()->getTemplate('button_list'), + 'template' => $this->getTemplateRegistry()->getTemplate('button_list'), ]; } @@ -3162,9 +3154,7 @@ public function getDashboardActions() $actions['create'] = [ 'label' => 'link_add', 'translation_domain' => 'SonataAdminBundle', - // NEXT_MAJOR: Remove this line and use commented line below it instead - 'template' => $this->getTemplate('action_create'), - // 'template' => $this->getTemplateRegistry()->getTemplate('action_create'), + 'template' => $this->getTemplateRegistry()->getTemplate('action_create'), 'url' => $this->generateUrl('create'), 'icon' => 'plus-circle', ]; @@ -3262,24 +3252,33 @@ public function canAccessObject($action, $object) } /** - * @return string[] + * @return MutableTemplateRegistryInterface */ - protected function configureExportFields(): array + final public function getTemplateRegistry() { - return $this->getModelManager()->getExportFields($this->getClass()); + if ($this->hasTemplateRegistry()) { + return $this->templateRegistry; + } + + throw new \LogicException(sprintf('Unable to find the templateRegistry for admin `%s`', static::class)); } - protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface + final public function hasTemplateRegistry(): bool { - return $query; + return $this->templateRegistry instanceof MutableTemplateRegistryInterface; } /** - * @return MutableTemplateRegistryInterface + * @return string[] */ - final protected function getTemplateRegistry() + protected function configureExportFields(): array + { + return $this->getModelManager()->getExportFields($this->getClass()); + } + + protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface { - return $this->templateRegistry; + return $query; } /** @@ -3425,9 +3424,7 @@ protected function buildList() ); $fieldDescription->setAdmin($this); - // NEXT_MAJOR: Remove this line and use commented line below it instead - $fieldDescription->setTemplate($this->getTemplate('batch')); - // $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch')); + $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch')); $mapper->add($fieldDescription, ListMapper::TYPE_BATCH); } @@ -3451,9 +3448,7 @@ protected function buildList() ); $fieldDescription->setAdmin($this); - // NEXT_MAJOR: Remove this line and use commented line below it instead - $fieldDescription->setTemplate($this->getTemplate('select')); - // $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select')); + $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select')); $mapper->add($fieldDescription, ListMapper::TYPE_SELECT); }