Skip to content

Commit

Permalink
Fix TemplateRegistry usages
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed Sep 14, 2020
1 parent c4d0026 commit ced1804
Showing 1 changed file with 31 additions and 8 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 templateRegistry is deprecated since sonata-project/admin-bundle 3.x'
.' and will throw an exception in 4.0. '
.' Use %s::hasTemplateRegistry() to know if there is TemplateRegistry set.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);
}
//if (false === $this->hasTemplateRegistry()) {
// throw new \LogicException(sprintf('Unable to find the templateRegistry for admin `%s`', static::class));
//}

return $this->templateRegistry;
}

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->templateRegistry;
return $this->getModelManager()->getExportFields($this->getClass());
}

protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
{
return $query;
}

/**
Expand Down

0 comments on commit ced1804

Please sign in to comment.