-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Added public methods to make Sitemap model plugin friendly #9970
Added public methods to make Sitemap model plugin friendly #9970
Conversation
…tems through a plugin
Hi @7ochem, |
Hi @7ochem, I am happy to report all the internal integration tests are green :) |
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.
We discourage methods that mutate object state.
Better approach in this case would be to introduce the reversed extension point: some kind of $ItemResolver dependency that would be called by sitemap (with sitemap id argument) to load custom sitemap items.
This dependency could be implemented as a composite, or just pluginized by third-party developers to add new items to the custom list.
Hi @7ochem Could you please look at @antonkril comment. thank you |
@avoelkl @antonkril @okorshenko thanks for your time looking into my proposal. I think I know what you mean with the resolver. I'm a bit conflicted here though. The sitemap module seems pretty straight forward (1 model only, no data models, no generators), so I was going for a simple fix. Now you are asking for a level of complexity that doesn't fit the (direct) context. If we'd go for an item resolver, or a pool, then we would better go for a more up scaled refactoring involving actual models for the items (instead of arrays of DataObjects) and adding more "single responsibility" by having a separate class for generating the actual XML output, leaving the old Sitemap model more of a manager service orchestrating the process. What are your thoughts? |
It would probably be over-complication, but that is out of the scope of this PR. I am talking about replacing one customization point with other, more error-proof. |
Hi @7ochem @antonkril @okorshenko, |
@antonkril, thank you for your clarification. I sometimes find it difficult to estimate what level of complexity will be accepted by the Magento team (what level of complexity you are after). I agree with @avoelkl to see if my current suggestion could be merged (as it is an improvement already to the existing situation) and try to improve this afterwards in the way @antonkril suggests. I'd rather take small steps at a time than creating 1 big PR, if that is ok with you? |
Usually, I would recommend our developers not to merge it, but the state of Sitemap is pretty simple. So if you don't have time/do not want to modify the code - ok, let's merge it. It is, definitely, an improvement over the current state. |
Thanks for merging, I just added a new issue with the "up for grabs" label to improve this even more :) |
So @avoelkl do you perhaps know where this will end up? Still in 2.2? Or 2.2.1? |
@okorshenko should I also create a PR for 2.1.x-develop? So we have this improvement also into 2.1 LTS. Eventually #10045 will probably only be created for 2.2 as it is somewhat a new feature |
it make sense to implement #10045 and then backport to 2.1 |
Hi @7ochem,
Sorry for the off-topic, but was it actually announced anywhere that 2.1 will have long-term support? |
Hi @korostii, indeed slightly off topic ;) I gathered some info here once: https://magento.stackexchange.com/a/131008/3326 I did not run into a good definition of the actual scope for LTS releases. Certainly interesting with a new minor release coming shortly. What will this mean for upcoming patch releases for previous minor releases... Anyway, this thread might not be the right place for such a discussion. You should probably open up another issue here on GitHub, or head to the Magento forums or the Magento Stackexchange. |
Description
I have added two public methods to the
\Magento\Sitemap\Model\Sitemap
to be able to add other 'sitemap items' via a plugin.I encountered this problem when I had a third party module already overriding (via preference) the Sitemap model and I ended up doing a classical rewrite conflict fix.
Plugins could prevent rewrite conflicts, but the class that is the subject of these plugins should have public methods to target.
I added the public methods
collectSitemapItems()
andaddSitemapItem()
. I kept the protected method_initSitemapItems()
in the code (instead of replacing_initSitemapItems()
withcollectSitemapItems()
) to maintain backwards compatibility for extensions that already do rewrite the whole\Magento\Sitemap\Model\Sitemap
model and override the_initSitemapItems()
to be able to add sitemap items.Fixed issue/PR
Manual testing scenarios
<type name="Magento\Sitemap\Model\Sitemap"><plugin ... /></type>
)afterCollectSitemapItems(\Magento\Sitemap\Model\Sitemap $subject)
method\Magento\Sitemap\Model\Sitemap::addSitemapItem(\Magento\Framework\DataObject $sitemapItem)
method to add new sitemap itemsExample:
Contribution checklist