Skip to content

Commit

Permalink
Deprecate Pool::getContainer method (#6475)
Browse files Browse the repository at this point in the history
The code that uses this method is already deprecated.
  • Loading branch information
franmomu authored Oct 12, 2020
1 parent a08dfb9 commit fd8cb6a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
UPGRADE 3.x
===========

### Deprecated `Sonata\AdminBundle\Admin\Pool::getContainer()` method.

This method has been deprecated without replacement.

### Deprecated using shortcut notation when specifying the `user_model` option in `sonata:admin:generate-object-acl` command.

The shortcut notation (`AppBundle:User`) has been deprecated in favor of the FQCN (`App\Model\User`) when passing
Expand Down
6 changes: 3 additions & 3 deletions docs/cookbook/recipe_image_previews.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ we are manipulating form fields we do this from within ``ImageAdmin::configureFo
// use $fileFormOptions so we can add other options to the field
$fileFormOptions = ['required' => false];
if ($image && ($webPath = $image->getWebPath())) {
// get the container so the full path to the image can be set
$container = $this->getConfigurationPool()->getContainer();
$fullPath = $container->get('request_stack')->getCurrentRequest()->getBasePath().'/'.$webPath;
// get the request so the full path to the image can be set
$request = $this->getRequest();
$fullPath = $request->getBasePath().'/'.$webPath;

// add a 'help' option containing the preview's img tag
$fileFormOptions['help'] = '<img src="'.$fullPath.'" class="admin-preview"/>';
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,7 @@ final public function getBreadcrumbsBuilder()
), E_USER_DEPRECATED);
if (null === $this->breadcrumbsBuilder) {
$this->breadcrumbsBuilder = new BreadcrumbsBuilder(
$this->getConfigurationPool()->getContainer()->getParameter('sonata.admin.configuration.breadcrumbs')
$this->getConfigurationPool()->getContainer('sonata_deprecation_mute')->getParameter('sonata.admin.configuration.breadcrumbs')
);
}

Expand Down
13 changes: 12 additions & 1 deletion src/Admin/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,21 @@ public function getInstance($id)
}

/**
* @return ContainerInterface|null
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/admin-bundle 3.x.
*
* @return ContainerInterface
*/
public function getContainer()
{
if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
@trigger_error(sprintf(
'Method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in version 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

return $this->container;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mapper/BaseGroupedMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function with($name, array $options = [])

// NEXT_MAJOR: remove this code
if ($this->admin instanceof AbstractAdmin && $pool = $this->admin->getConfigurationPool()) {
if ($pool->getContainer()->getParameter('sonata.admin.configuration.translate_group_label')) {
if ($pool->getContainer('sonata_deprecation_mute')->getParameter('sonata.admin.configuration.translate_group_label')) {
$defaultOptions['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($name, $this->getName(), 'group');
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Admin/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ public function testGetAdminServiceIds(): void
$this->assertSame(['sonata.user.admin.group1', 'sonata.user.admin.group2', 'sonata.user.admin.group3'], $this->pool->getAdminServiceIds());
}

/**
* NEXT_MAJOR: Remove this test.
*
* @group legacy
*/
public function testGetContainer(): void
{
$this->assertInstanceOf(ContainerInterface::class, $this->pool->getContainer());
Expand Down
3 changes: 2 additions & 1 deletion tests/Mapper/BaseGroupedMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@ public function labelDataProvider(): array
*/
public function testLabel(bool $translated, string $name, ?string $label, string $expectedLabel): void
{
// NEXT_MAJOR: Remove $container variable and the call to setParameter.
$container = $this->baseGroupedMapper
->getAdmin()
->getConfigurationPool()
->getContainer();
->getContainer('sonata_deprecation_mute');

$container->setParameter('sonata.admin.configuration.translate_group_label', $translated);

Expand Down

0 comments on commit fd8cb6a

Please sign in to comment.