Skip to content

Commit

Permalink
Fix TemplateRegistry usages (#6387)
Browse files Browse the repository at this point in the history
Update src/Admin/AbstractAdmin.php

Co-authored-by: Javier Spagnoletti <[email protected]>
  • Loading branch information
wbloszyk and phansys authored Sep 15, 2020
1 parent 480c14b commit 00bf1d6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
39 changes: 31 additions & 8 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> $templates
*/
public function setTemplates(array $templates)
Expand All @@ -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
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down
55 changes: 30 additions & 25 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,31 +40,32 @@
/**
* @author Thomas Rabaix <[email protected]>
*
* @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<T>
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 00bf1d6

Please sign in to comment.