-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Prepare for BlockBundle 4.0 support and fix #1731 #1732
Changes from all commits
a407784
69de70b
db3704e
030f041
4be6b0f
7ed46d7
9541daf
7df47c0
c4a7145
116f48d
2652129
bee56aa
2cdc1d3
8050085
f4eefb3
3ddc959
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,17 @@ | |
|
||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Sonata\AdminBundle\Admin\AdminInterface; | ||
use Sonata\AdminBundle\Form\FormMapper; | ||
use Sonata\AdminBundle\Form\Type\ModelListType; | ||
use Sonata\BlockBundle\Block\BlockContextInterface; | ||
use Sonata\BlockBundle\Block\Service\AbstractBlockService; | ||
use Sonata\BlockBundle\Block\Service\EditableBlockService; | ||
use Sonata\BlockBundle\Form\Mapper\FormMapper; | ||
use Sonata\BlockBundle\Meta\Metadata; | ||
use Sonata\BlockBundle\Meta\MetadataInterface; | ||
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; | ||
|
@@ -41,7 +44,7 @@ | |
* | ||
* @author Thomas Rabaix <[email protected]> | ||
*/ | ||
class GalleryBlockService extends AbstractBlockService | ||
class GalleryBlockService extends AbstractBlockService implements EditableBlockService | ||
{ | ||
/** | ||
* @var ManagerInterface | ||
|
@@ -112,10 +115,12 @@ public function configureSettings(OptionsResolver $resolver) | |
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | ||
public function configureCreateForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
$this->configureEditForm($formMapper, $block); | ||
} | ||
|
||
public function configureEditForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
$contextChoices = []; | ||
|
||
|
@@ -140,7 +145,7 @@ public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | |
'translation_domain' => 'SonataMediaBundle', | ||
]); | ||
$fieldDescription->setAssociationAdmin($this->getGalleryAdmin()); | ||
$fieldDescription->setAdmin($formMapper->getAdmin()); | ||
$fieldDescription->setAdmin($this->container->get('sonata.page.admin.block')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is OK for old Symfony practice. For new pratice we should avoid using container. Please move it this service to block property and set it in constructor. This will allow inject required servaices insted container. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the container should be removed in next major not in this patch. The container is used else where in the blocks too for example when we are getting the media admin. Can we have another pull request for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Container should be remove in Block 4 support becouse you must change constructor parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well this can be changed to be "prepare for Block 4 support". |
||
$fieldDescription->setOption('edit', 'list'); | ||
$fieldDescription->setAssociationMapping(['fieldName' => 'gallery', 'type' => ClassMetadataInfo::MANY_TO_ONE]); | ||
|
||
|
@@ -196,6 +201,56 @@ public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | |
]); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::configureCreateForm() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
$this->configureCreateForm($formMapper, $block); | ||
haivala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::configureEditForm() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
$this->configureEditForm($formMapper, $block); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function validateBlock(ErrorElement $errorElement, BlockInterface $block) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::validate() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
|
||
$this->validate($errorElement, $block); | ||
} | ||
|
||
public function validate(ErrorElement $errorElement, BlockInterface $block) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -244,8 +299,26 @@ public function preUpdate(BlockInterface $block) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMetadata(): MetadataInterface | ||
{ | ||
return new Metadata($this->getName(), null, null, 'SonataMediaBundle', [ | ||
'class' => 'fa fa-picture-o', | ||
]); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function getBlockMetadata($code = null) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::getMetadata() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
|
||
return new Metadata($this->getName(), (null !== $code ? $code : $this->getName()), false, 'SonataMediaBundle', [ | ||
'class' => 'fa fa-picture-o', | ||
]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,15 @@ | |
|
||
namespace Sonata\MediaBundle\Block; | ||
|
||
use Sonata\AdminBundle\Form\FormMapper; | ||
use Sonata\BlockBundle\Block\BlockContextInterface; | ||
use Sonata\BlockBundle\Block\Service\AbstractBlockService; | ||
use Sonata\BlockBundle\Block\Service\EditableBlockService; | ||
use Sonata\BlockBundle\Form\Mapper\FormMapper; | ||
use Sonata\BlockBundle\Meta\Metadata; | ||
use Sonata\BlockBundle\Meta\MetadataInterface; | ||
use Sonata\BlockBundle\Model\BlockInterface; | ||
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; | ||
|
@@ -32,7 +35,7 @@ | |
/** | ||
* @final since sonata-project/media-bundle 3.21.0 | ||
*/ | ||
class GalleryListBlockService extends AbstractBlockService | ||
class GalleryListBlockService extends AbstractBlockService implements EditableBlockService | ||
{ | ||
/** | ||
* @var GalleryManagerInterface | ||
|
@@ -57,10 +60,12 @@ public function __construct($twigOrName, ?EngineInterface $templating, GalleryMa | |
$this->pool = $pool; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | ||
public function configureCreateForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
$this->configureEditForm($formMapper, $block); | ||
} | ||
|
||
public function configureEditForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
$contextChoices = []; | ||
|
||
|
@@ -122,6 +127,55 @@ public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | |
]); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::configureCreateForm() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
$this->configureCreateForm($formMapper, $block); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function buildEditForm(FormMapper $formMapper, BlockInterface $block) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::configureEditForm() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
$this->configureEditForm($formMapper, $block); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function validateBlock(ErrorElement $errorElement, BlockInterface $block) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::validate() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
$this->validate($errorElement, $block); | ||
} | ||
|
||
public function validate(ErrorElement $errorElement, BlockInterface $block) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -173,8 +227,26 @@ public function configureSettings(OptionsResolver $resolver) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMetadata(): MetadataInterface | ||
{ | ||
return new Metadata($this->getName(), null, null, 'SonataMediaBundle', [ | ||
'class' => 'fa fa-picture-o', | ||
]); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function getBlockMetadata($code = null) | ||
{ | ||
if ('sonata_deprecation_mute' !== (\func_get_args()[2] ?? null)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this 2 need to be changed to 1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends on how are you providing the arguments for this method, but since there is no magic usage for argument 2 (offset 1 for |
||
@trigger_error(sprintf( | ||
'Method %s() is deprecated since sonata-project/media-bundle 3.x and will be removed in version 4.0. Use %s::getMetadata() instead.', | ||
__METHOD__, | ||
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
|
||
return new Metadata($this->getName(), (null !== $code ? $code : $this->getName()), false, 'SonataMediaBundle', [ | ||
'class' => 'fa fa-picture-o', | ||
]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use AdminFormMapper in
buildCreateForm
andbuildEditForm
Use FormMapper in
configureCreateForm
andconfigureEditForm
This can make some problem, I will check it.