Skip to content

Commit

Permalink
Implement MutableTemplateRegistryAwareInterface in TaggedAdminInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 5, 2021
1 parent 73fa85d commit a085bea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
36 changes: 0 additions & 36 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
use Sonata\AdminBundle\Util\Instantiator;
use Sonata\AdminBundle\Util\ParametersManipulator;
use Sonata\Exporter\Source\SourceIteratorInterface;
Expand Down Expand Up @@ -278,11 +277,6 @@ abstract class AbstractAdmin extends AbstractTaggedAdmin implements AdminInterfa
*/
private $parentAssociationMapping = [];

/**
* @var MutableTemplateRegistryInterface|null
*/
private $templateRegistry;

/**
* The subclasses supported by the admin class.
*
Expand Down Expand Up @@ -861,21 +855,6 @@ final public function generateMenuUrl(string $name, array $parameters = [], int
return $this->getRouteGenerator()->generateMenuUrl($this, $name, $parameters, $referenceType);
}

final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void
{
$this->templateRegistry = $templateRegistry;
}

final public function setTemplates(array $templates): void
{
$this->getTemplateRegistry()->setTemplates($templates);
}

final public function setTemplate(string $name, string $template): void
{
$this->getTemplateRegistry()->setTemplate($name, $template);
}

final public function getNewInstance(): object
{
$object = $this->createNewInstance();
Expand Down Expand Up @@ -1927,21 +1906,6 @@ final public function getSearchResultLink(object $object): ?string
return null;
}

final public function getTemplateRegistry(): MutableTemplateRegistryInterface
{
if (false === $this->hasTemplateRegistry()) {
throw new \LogicException(sprintf('Unable to find the template registry for admin `%s`.', static::class));
}
\assert(null !== $this->templateRegistry);

return $this->templateRegistry;
}

final public function hasTemplateRegistry(): bool
{
return null !== $this->templateRegistry;
}

final public function createFieldDescription(string $propertyName, array $options = []): FieldDescriptionInterface
{
$fieldDescriptionFactory = $this->getFieldDescriptionFactory();
Expand Down
3 changes: 1 addition & 2 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
use Sonata\AdminBundle\FieldDescription\FieldDescriptionRegistryInterface;
use Sonata\AdminBundle\Object\MetadataInterface;
use Sonata\AdminBundle\Templating\MutableTemplateRegistryAwareInterface;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
Expand All @@ -37,7 +36,7 @@
* @phpstan-extends UrlGeneratorInterface<T>
* @phpstan-extends LifecycleHookProviderInterface<T>
*/
interface AdminInterface extends TaggedAdminInterface, AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, ParentAdminInterface, UrlGeneratorInterface, MutableTemplateRegistryAwareInterface
interface AdminInterface extends TaggedAdminInterface, AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, ParentAdminInterface, UrlGeneratorInterface
{
/**
* Returns subjectClass/class/subclass name managed
Expand Down
36 changes: 36 additions & 0 deletions src/DependencyInjection/Admin/AbstractTaggedAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Sonata\AdminBundle\Route\RouteGeneratorInterface;
use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand Down Expand Up @@ -187,6 +188,11 @@ abstract class AbstractTaggedAdmin implements TaggedAdminInterface
*/
private $fieldDescriptionFactory;

/**
* @var MutableTemplateRegistryInterface|null
*/
private $templateRegistry;

public function __construct(string $code, string $class, string $baseControllerName)
{
$this->code = $code;
Expand Down Expand Up @@ -478,4 +484,34 @@ final public function getLabelTranslatorStrategy(): LabelTranslatorStrategyInter

return $this->labelTranslatorStrategy;
}

final public function getTemplateRegistry(): MutableTemplateRegistryInterface
{
if (false === $this->hasTemplateRegistry()) {
throw new \LogicException(sprintf('Unable to find the template registry for admin `%s`.', static::class));
}
\assert(null !== $this->templateRegistry);

return $this->templateRegistry;
}

final public function hasTemplateRegistry(): bool
{
return null !== $this->templateRegistry;
}

final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void
{
$this->templateRegistry = $templateRegistry;
}

final public function setTemplates(array $templates): void
{
$this->getTemplateRegistry()->setTemplates($templates);
}

final public function setTemplate(string $name, string $template): void
{
$this->getTemplateRegistry()->setTemplate($name, $template);
}
}
3 changes: 2 additions & 1 deletion src/DependencyInjection/Admin/TaggedAdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Sonata\AdminBundle\Route\RouteGeneratorInterface;
use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
use Sonata\AdminBundle\Templating\MutableTemplateRegistryAwareInterface;
use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -41,7 +42,7 @@
* - The first and third argument are automatically injected by the AddDependencyCallsCompilerPass.
* - The second one is used as a reference of the Admin in the Pool, with the `setAdminClasses` call.
*/
interface TaggedAdminInterface
interface TaggedAdminInterface extends MutableTemplateRegistryAwareInterface
{
public const ADMIN_TAG = 'sonata.admin';

Expand Down

0 comments on commit a085bea

Please sign in to comment.