Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Nov 6, 2021
2 parents ad8d758 + 2a6b2b2 commit 89d231c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"psalm/plugin-symfony": "^3.0",
"sonata-project/admin-bundle": "^4.0",
"sonata-project/block-bundle": "^4.0",
"sonata-project/classification-bundle": "^4.0@dev",
"sonata-project/classification-bundle": "^4.0@alpha",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.3",
"symfony/messenger": "^4.4 || ^5.3",
Expand Down
30 changes: 15 additions & 15 deletions src/Admin/BaseMediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@ public function __construct(
$this->contextManager = $contextManager;
}

public function prePersist(object $object): void
final public function getObjectMetadata(object $object): MetadataInterface
{
$provider = $this->pool->getProvider($object->getProviderName());

$url = $provider->generatePublicUrl(
$object,
$provider->getFormatName($object, MediaProviderInterface::FORMAT_ADMIN)
);

return new Metadata($this->toString($object), $object->getDescription(), $url);
}

protected function prePersist(object $object): void
{
$parameters = $this->getPersistentParameters();
$object->setContext($parameters['context']);
}

public function configurePersistentParameters(): array
protected function configurePersistentParameters(): array
{
$parameters = [];

Expand Down Expand Up @@ -112,7 +124,7 @@ public function configurePersistentParameters(): array
]);
}

public function alterNewInstance(object $object): void
protected function alterNewInstance(object $object): void
{
if ($this->hasRequest()) {
if ($this->getRequest()->isMethod('POST')) {
Expand Down Expand Up @@ -141,18 +153,6 @@ public function alterNewInstance(object $object): void
}
}

final public function getObjectMetadata(object $object): MetadataInterface
{
$provider = $this->pool->getProvider($object->getProviderName());

$url = $provider->generatePublicUrl(
$object,
$provider->getFormatName($object, MediaProviderInterface::FORMAT_ADMIN)
);

return new Metadata($this->toString($object), $object->getDescription(), $url);
}

protected function configureListFields(ListMapper $list): void
{
$list
Expand Down
8 changes: 4 additions & 4 deletions src/Admin/GalleryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public function __construct(string $code, string $class, string $baseControllerN
$this->pool = $pool;
}

public function prePersist(object $object): void
protected function prePersist(object $object): void
{
$parameters = $this->getPersistentParameters();

$object->setContext($parameters['context']);
}

public function postUpdate(object $object): void
protected function postUpdate(object $object): void
{
$object->reorderGalleryItems();
}

public function configurePersistentParameters(): array
protected function configurePersistentParameters(): array
{
if (!$this->hasRequest()) {
return [];
Expand All @@ -63,7 +63,7 @@ public function configurePersistentParameters(): array
];
}

public function alterNewInstance(object $object): void
protected function alterNewInstance(object $object): void
{
if ($this->hasRequest()) {
$object->setContext($this->getRequest()->get('context'));
Expand Down
6 changes: 2 additions & 4 deletions tests/Admin/BaseMediaAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Sonata\ClassificationBundle\Model\CategoryManagerInterface;
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
use Sonata\MediaBundle\Entity\BaseMedia;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Provider\MediaProviderInterface;
use Sonata\MediaBundle\Provider\Pool;
Expand Down Expand Up @@ -61,7 +60,7 @@ protected function setUp(): void

$this->mediaAdmin = new TestMediaAdmin(
'media',
BaseMedia::class,
Media::class,
'SonataMediaBundle:MediaAdmin',
$this->pool,
$this->categoryManager,
Expand All @@ -74,7 +73,6 @@ protected function setUp(): void

public function testAlterNewInstance(): void
{
$media = new Media();
$category = new Category();
$context = new Context();

Expand All @@ -86,7 +84,7 @@ public function testAlterNewInstance(): void
$this->categoryManager->method('find')->with(1)->willReturn($category);
$this->request->setMethod('POST');

$this->mediaAdmin->alterNewInstance($media);
$media = $this->mediaAdmin->getNewInstance();

static::assertSame('context', $media->getContext());
static::assertSame($category, $media->getCategory());
Expand Down

0 comments on commit 89d231c

Please sign in to comment.