Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BlockBundle 4.x #522

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"require": {
"php": "^7.1",
"cocur/slugify": "^2.0 || ^3.0 || ^4.0",
"sonata-project/admin-bundle": "^3.31",
"sonata-project/core-bundle": "^3.14",
"sonata-project/admin-bundle": "^3.31 || dev-master",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not add this to the stable branch

"sonata-project/core-bundle": "^3.13",
"sonata-project/datagrid-bundle": "^2.3",
"sonata-project/doctrine-extensions": "^1.6.0",
"sonata-project/doctrine-orm-admin-bundle": "^3.4",
Expand All @@ -41,13 +41,13 @@
"conflict": {
"friendsofsymfony/rest-bundle": "<2.1 || >=3.0",
"jms/serializer": "<0.13",
"sonata-project/block-bundle": "<3.14 || >=4.0",
"sonata-project/block-bundle": "<3.14",
"sonata-project/media-bundle": "<3.17 || >=4.0"
},
"require-dev": {
"friendsofsymfony/rest-bundle": "^2.1",
"jms/serializer-bundle": "^1.0 || ^2.0",
"sonata-project/block-bundle": "^3.16.1",
"sonata-project/block-bundle": "^3.16.1 || ^4.0",
"sonata-project/media-bundle": "^3.17",
"symfony/phpunit-bridge": "^5.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/Block/Service/AbstractCategoriesBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Christian Gripp <[email protected]>
Expand Down
109 changes: 107 additions & 2 deletions src/Block/Service/AbstractClassificationBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelTypeList;
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Block\Service\AdminBlockServiceInterface;
use Sonata\BlockBundle\Meta\Metadata;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\ClassificationBundle\Model\ContextInterface;
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
use Sonata\CoreBundle\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\FormBuilder;
use Twig\Environment;

/**
* @author Christian Gripp <[email protected]>
*/
abstract class AbstractClassificationBlockService extends AbstractAdminBlockService
abstract class AbstractClassificationBlockService extends AbstractBlockService
{
/**
* @var ContextManagerInterface
Expand All @@ -44,6 +48,15 @@ public function __construct(
$contextManagerOrDeprecatedTemplating,
$deprecatedContextManager = null
) {
// NEXT_MAJOR: remove the if block
if (!interface_exists(AdminBlockServiceInterface::class)) {
@trigger_error(
'The '.__NAMESPACE__.'\EditableBlockService interface is required since sonata-project/block-bundle 4.0 '.
'You must add it to you '.__CLASS__.'.',
E_USER_DEPRECATED
);
}

// NEXT_MAJOR: remove the if block
if (\is_string($twigOrDeprecatedName)) {
parent::__construct($twigOrDeprecatedName, $contextManagerOrDeprecatedTemplating);
Expand All @@ -56,6 +69,98 @@ public function __construct(
}
}

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

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

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

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

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

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

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/block-bundle 3.16, to be removed in version 4.0.
*/
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block)
{
$this->buildEditForm($formMapper, $block);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/block-bundle 3.16, to be removed in version 4.0.
*/
public function buildEditForm(FormMapper $form, BlockInterface $block)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
{
$this->buildEditForm($formMapper, $block);

Copy link
Member Author

@wbloszyk wbloszyk Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is AbstractAdminBlockService method, we should not change them. Self reference method make infinity loop.

}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/block-bundle 3.16, to be removed in version 4.0.
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/block-bundle 3.16, to be removed in version 4.0.
*/
public function getBlockMetadata($code = null)
{
return new Metadata($this->getName(), (null !== $code ? $code : $this->getName()), false, 'SonataBlockBundle', ['class' => 'fa fa-file']);
}

/**
* @param string $formField
* @param string $field
Expand Down
1 change: 1 addition & 0 deletions src/Block/Service/AbstractCollectionsBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Christian Gripp <[email protected]>
Expand Down
11 changes: 6 additions & 5 deletions src/Block/Service/AbstractTagsBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Christian Gripp <[email protected]>
Expand All @@ -44,11 +45,11 @@ abstract class AbstractTagsBlockService extends AbstractClassificationBlockServi
private $tagAdmin;

/**
* @param string|Environment $twigOrDeprecatedName
* @param EngineInterface|ContextManagerInterface $contextManagerOrDeprecatedTemplating
* @param ContextManagerInterface|TagManagerInterface| $tagManagerOrDeprecatedContextManager
* @param TagManagerInterface|AdminInterface $tagAdminOrDeprecatedTagManager
* @param AdminInterface|null $deprecatedTagAdmin
* @param string|Environment $twigOrDeprecatedName
* @param EngineInterface|ContextManagerInterface $contextManagerOrDeprecatedTemplating
* @param ContextManagerInterface|TagManagerInterface $tagManagerOrDeprecatedContextManager
* @param TagManagerInterface|AdminInterface $tagAdminOrDeprecatedTagManager
* @param AdminInterface|null $deprecatedTagAdmin
*/
public function __construct(
$twigOrDeprecatedName,
Expand Down