-
-
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
Conversation
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.
I guess these extension points are intended to be kept in the next major.
I'll check this later |
With these changes I can now add block in the Page composer but it still needs the validate method to be able to create the block.
I tested and after that I can create the block. |
Is not clear for me if these methods are added back just to fix a BC break (and must be deprecated), or if they are intended to be kept in the next major. Could you please confirm that? |
This commit make bug: 9533247 becouse To fix it and keep BC-break all methods from To add BlockBundle 4 support |
Thank you for the answer.
IIUC, I think we should add a SonataMediaBundle/src/Block/GalleryBlockService.php Lines 40 to 45 in 4be6b0f
|
How do I solve this: "Attempted to call an undefined method named "getAdmin" of class "Sonata\PageBundle\Mapper\PageFormMapper"."
|
And is it ok to remove the |
If this goes smoothly: now that I have experience on this I can consider adding BlockBundle 4 support other SonataBundle blocks too. |
@phansys this is the real problem |
I didn't dive in this issue, but maybe you could use a class property in order to store the required admin instance. Otherwise, you should implement a solution based on |
How I understand this is that we just need to provide the current admin (sonata.page.admin.block in this case) to it so that it can create the virtual ManyToOne relation in ImmutableArrayType form. The block admin saves the id of an Media as int in the block settings and loads the object when needed from media admin but we need to create that that form to be able to set the int (and use media admin to do so). This has been the implementation for this more than 5 years and I have feeling that it has always been considered as hacky. My question is can I just get the sonata.page.admin.block from the container in that line? Does it beak something else? I tested this and it works as it should. like this: |
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 comment
The 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 comment
The 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 func_get_args()
), I think you must use it.
@phansys waiting for review |
src/Block/GalleryBlockService.php
Outdated
'class' => 'fa fa-picture-o', | ||
]); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: delete it. |
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.
* NEXT_MAJOR: delete it. | |
* NEXT_MAJOR: delete it. | |
* | |
* @deprecated Will be removed in version 4.0. Use getMetadata instead. |
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.
It triggers deprecation notice already..
@@ -13,7 +13,7 @@ | |||
|
|||
namespace Sonata\MediaBundle\Block; | |||
|
|||
use Sonata\AdminBundle\Form\FormMapper; | |||
use Sonata\BlockBundle\Form\Mapper\FormMapper; |
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 Sonata\BlockBundle\Form\Mapper\FormMapper; | |
use Sonata\AdminBundle\Form\Mapper\FormMapper as AdminFormMapper; | |
use Sonata\BlockBundle\Form\Mapper\FormMapper; |
Use AdminFormMapper in buildCreateForm
and buildEditForm
Use FormMapper in configureCreateForm
and configureEditForm
This can make some problem, I will check it.
@@ -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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Well this can be changed to be "prepare for Block 4 support".
I would happily do this later.
This was supposed to be patch for these blocks to work at all and now they work.
OK?
static::class | ||
), E_USER_DEPRECATED); | ||
} | ||
$this->configureEditForm($formMapper, $block); |
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.
FormMapper are not the same:
public function buildEditForm(Sonata\AdminBundle\Form\FormMapper $form, BlockInterface $block)
public function configureEditForm(Sonata\BlockBundle\Form\Mapper\FormMapper $form, BlockInterface $block)
You should use something like PageFormMapper:
$blockMapper = new PageFormMapper($formMapper);
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.
Sonata\BlockBundle\Form\Mapper\FormMapper
has been introduced in block bundle 3.13
And this requires 3.17: https://github.com/sonata-project/SonataMediaBundle/blob/3.x/composer.json#L66
block bundles formmapper uses the same adminbundle formmapper without some functions.
Is this really needed?
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.
The thing is that when I introduced the BC break in #1699, it was extending AbstractAdminBlockService
, so to be compatible again, we should just copy those methods that don't exist in these classes, we cannot change the signature of those methods. IMHO the compatibility with BlockBundle 4 should be done in another PR.
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.
Yet, somehow these blocks work with my changes. they do not need all of those methods.
This is really frustrating. |
@haivala Change this PR to fix only. Focus on:
In another we can focus on BlockBundle 4 support:
|
Any progress here? Should we revert the change? |
Subject
I am targeting this branch, because it is patch.
Closes #1731
Changelog