-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Introduce separate BlockByIdentifier class to get Layout Block based on CMS Block Identifier #28147
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
Introduce separate BlockByIdentifier class to get Layout Block based on CMS Block Identifier #28147
Conversation
Hi @lbajsarowicz. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
After further investigation, I realized that additional Identities are not necessary, as these are used only as tags, not as cache keys. The only thing that was missing before and is missing now is to tag block with CMS Block identities, so that when CMS Block is requested to be removed from cache, the Layout Block cache should be cleaned too. I'm going to adjust that now. |
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.
Hi @lbajsarowicz,
Could you fix unit tests failures ?
I can't find any failing report for Static Tests, neither for Unit Tests. |
Hi @slavvka could you add more info why unit and static tests fails? We don’t have anything in reports |
@magento run all tests |
Hi @sidolov, thank you for the review. |
@@ -10,6 +10,8 @@ | |||
|
|||
/** | |||
* Cms block content block | |||
* @deprecated This class introduces caching issues and should no longer be used |
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.
What issues?
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.
Must be this one, that was fixed? 5c84c1a
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.
Not really. Except the fact the previous one uses both id
and identifier
for cache key, there was something more (I'll try to find out what was the other issue)
Co-authored-by: Ihor Sviziev <[email protected]>
I don't understand why do Magento needs this new block. It seems that everything from this PR could be done in the existing block without creating a new entity and without BC. Something like this: if (is_numeric($identifier)) {
// loadById to be compatible with custom code that uses id.
} else {
// new logic
} |
@vovayatsyuk If we want to follow SOLID principles - the arguments have to explicit, without type juggling. It's exactly the same like Page by Identifier interface. |
But we already have a block to show cms blocks. I can only agree with this change if we'll remove another block in the future. But this leads to the next thought - why create a new block instead of refactoring the existing one and remove deprecated logic in the next major release? |
@vovayatsyuk The only issue for introducing that Interface was the requirement for backwards compatibility, as this PR was created before 2.4 was released. If I knew that's going to hang for a year, I'd just modify the original implementation with happy "do it all" (against the SOLID principles) way. |
@vovayatsyuk in my opinion - we can go with both options. in the current implementation of cms/block/block we have following issues:
Also as @lbajsarowicz said - addressing all of these issues will cause the not following SOLID principles and probably will be backward incompatible. |
From the discussion above - seems like we all agreed that this solution is good enough to be accepted. |
@sidolov is there any reason why this PR isn't getting merged? |
@ihor-sviziev the pull request in the delivery queue right now and will be delivered soon. There are no reasons to postpone the merging process. |
… Block based on CMS Block Identifier #28147
Hi @lbajsarowicz, thank you for your contribution! |
@sidolov , @ihor-sviziev @vovayatsyuk - Thanks for your support. Glad to have this merged. |
Description (*)
The existing class is anti-pattern:
\Magento\Framework\Model\AbstractModel::load
to load Modelblock_id
is identifier, thegetIdentities
method returns same identity whatever the Scope is (return [\Magento\Cms\Model\Block::CACHE_TAG . '_' . $this->getBlockId()];
), which is painful when you use the sameidentifier
for multiple per-store CMS blocks.Why can't we fix the original Block? Some of developers might have used:
That is why we keep old Block backwards-compatible and introducing new one that can be used explicitly:
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)
Resolved issues: