Skip to content

Commit

Permalink
Fix admin template setters (#6766)
Browse files Browse the repository at this point in the history
* Fix template setters in AbstractAdmin

Update tests/Templating/MutableTemplateRegistryTest.php

Co-authored-by: Javier Spagnoletti <[email protected]>

Update src/Templating/MutableTemplateRegistry.php

Co-authored-by: Javier Spagnoletti <[email protected]>

* Update src/Templating/MutableTemplateRegistry.php

Co-authored-by: Javier Spagnoletti <[email protected]>

Co-authored-by: Javier Spagnoletti <[email protected]>
  • Loading branch information
wbloszyk and phansys authored Jan 17, 2021
1 parent d314375 commit c3bd1e0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1195,11 +1195,6 @@ final public function setTemplateRegistry(MutableTemplateRegistryInterface $temp
$this->templateRegistry = $templateRegistry;
}

/**
* @deprecated since sonata-project/admin-bundle 3.76, will be dropped in 4.0. Use TemplateRegistry services instead
*
* @param array<string, string> $templates
*/
public function setTemplates(array $templates)
{
// NEXT_MAJOR: Remove this line
Expand All @@ -1208,12 +1203,6 @@ public function setTemplates(array $templates)
$this->getTemplateRegistry()->setTemplates($templates);
}

/**
* @deprecated since sonata-project/admin-bundle 3.76, will be dropped in 4.0. Use TemplateRegistry services instead
*
* @param string $name
* @param string $template
*/
public function setTemplate($name, $template)
{
// NEXT_MAJOR: Remove this line
Expand Down
2 changes: 2 additions & 0 deletions src/Templating/MutableTemplateRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ final class MutableTemplateRegistry extends AbstractTemplateRegistry implements
// public function setTemplates(array $templates): void
public function setTemplates(array $templates)
{
//NEXT_MAJOR: merge arrays and update the doc https://github.com/sonata-project/SonataAdminBundle/blob/3.x/docs/reference/templates.rst
$this->templates = $templates;
//$this->templates = $templates + $this->templates;
}

// NEXT_MAJOR: change method declaration for new one
Expand Down
19 changes: 19 additions & 0 deletions src/Templating/MutableTemplateRegistryAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@ interface MutableTemplateRegistryAwareInterface

// NEXT_MAJOR: uncomment this method in 4.0
//public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void;

/**
* NEXT_MAJOR: remove this method declaration with docblock and uncomment code below.
*
* @param string $name
* @param string $template
*/
public function setTemplate($name, $template);

//public function setTemplate(string $name, string $template);

/**
* NEXT_MAJOR: remove this method declaration and uncomment code below.
*
* @param array<string, string> $templates
*/
public function setTemplates(array $templates);

//public function setTemplates(array $templates): void;
}
2 changes: 2 additions & 0 deletions tests/Templating/MutableTemplateRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function testGetTemplates(): void
];

$this->templateRegistry->setTemplates($templates);
// NEXT_MAJOR: remove this first assert and uncomment second
$this->assertSame($templates, $this->templateRegistry->getTemplates());
//$this->assertSame($templates + ['list' => '@FooAdmin/CRUD/list.html.twig'], $this->templateRegistry->getTemplates());
}

/**
Expand Down

0 comments on commit c3bd1e0

Please sign in to comment.