Skip to content

Commit

Permalink
Improve BlockServices
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed Jun 18, 2020
1 parent 6bb2c09 commit 9acb8cf
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 12 deletions.
76 changes: 72 additions & 4 deletions src/Block/GalleryBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\Doctrine\Model\ManagerInterface;
use Sonata\Form\Type\ImmutableArrayType;
use Sonata\Form\Validator\ErrorElement;
use Sonata\MediaBundle\Model\GalleryInterface;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Provider\Pool;
Expand Down Expand Up @@ -113,7 +114,10 @@ public function configureSettings(OptionsResolver $resolver)
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
Expand Down Expand Up @@ -226,23 +230,30 @@ public function load(BlockInterface $block)
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
*/
public function prePersist(BlockInterface $block)
{
$block->setSetting('galleryId', \is_object($block->getSetting('galleryId')) ? $block->getSetting('galleryId')->getId() : null);
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
*/
public function preUpdate(BlockInterface $block)
{
$block->setSetting('galleryId', \is_object($block->getSetting('galleryId')) ? $block->getSetting('galleryId')->getId() : null);
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function getBlockMetadata($code = null)
{
Expand All @@ -251,6 +262,63 @@ public function getBlockMetadata($code = null)
]);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block)
{
$this->buildEditForm($formMapper, $block);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
*/
public function postPersist(BlockInterface $block)
{
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
*/
public function postUpdate(BlockInterface $block)
{
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
*/
public function preRemove(BlockInterface $block)
{
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
*/
public function postRemove(BlockInterface $block)
{
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
}

private function buildElements(GalleryInterface $gallery): array
{
$elements = [];
Expand Down
21 changes: 17 additions & 4 deletions src/Block/GalleryListBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Validator\ErrorElement;
use Sonata\Form\Type\ImmutableArrayType;
use Sonata\Form\Validator\ErrorElement;
use Sonata\MediaBundle\Model\GalleryManagerInterface;
use Sonata\MediaBundle\Provider\Pool;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
Expand Down Expand Up @@ -59,7 +59,10 @@ public function __construct($twigOrName, ?EngineInterface $templating, GalleryMa
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
Expand Down Expand Up @@ -172,7 +175,10 @@ public function configureSettings(OptionsResolver $resolver)
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function getBlockMetadata($code = null)
{
Expand All @@ -181,6 +187,12 @@ public function getBlockMetadata($code = null)
]);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block)
{
$this->buildEditForm($formMapper, $block);
Expand Down Expand Up @@ -243,7 +255,8 @@ public function postRemove(BlockInterface $block)
/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
Expand Down
21 changes: 17 additions & 4 deletions src/Block/MediaBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Validator\ErrorElement;
use Sonata\Doctrine\Model\ManagerInterface;
use Sonata\Form\Type\ImmutableArrayType;
use Sonata\Form\Validator\ErrorElement;
use Sonata\MediaBundle\Admin\BaseMediaAdmin;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Provider\Pool;
Expand Down Expand Up @@ -113,7 +113,10 @@ public function configureSettings(OptionsResolver $resolver)
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
Expand Down Expand Up @@ -205,7 +208,10 @@ public function preUpdate(BlockInterface $block)
}

/**
* {@inheritdoc}
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function getBlockMetadata($code = null)
{
Expand All @@ -214,6 +220,12 @@ public function getBlockMetadata($code = null)
]);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block)
{
$this->buildEditForm($formMapper, $block);
Expand Down Expand Up @@ -258,7 +270,8 @@ public function postRemove(BlockInterface $block)
/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0.
* @deprecated since sonata-project/media-bundle 3.x, to be removed in 4.0. You should use
* `Sonata\BlockBundle\Block\Service\EditableBlockService` interface instead.
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
Expand Down

0 comments on commit 9acb8cf

Please sign in to comment.