[4.x]: Why is `::getSidebarHtml()` never called, and thus `EVENT_DEFINE_SIDEBAR_HTML` never triggered?
What happened?
Description
SEOmatic has code to add an SEO preview to the the sidebar HTML via EVENT_DEFINE_SIDEBAR_HTML:
https://github.com/nystudio107/craft-seomatic/blob/develop-v4/src/seoelements/SeoProduct.php#L175
...which is what I thought all element types had converted over to with Craft 4. And indeed, there is code in Commerce to render the sidebar via ::getSidebarHtml():
https://github.com/craftcms/commerce/blob/develop/src/elements/Product.php#L796
...which calls parent::getSidebarHtml(false) which would trigger the EVENT_DEFINE_SIDEBAR_HTML:
https://github.com/craftcms/cms/blob/develop/src/base/Element.php#L4705
...but apparently, this is just vestigial code? Because it appears this all still works via template hooks?
https://github.com/craftcms/commerce/blob/develop/src/templates/products/_edit.twig#L171
This causes SEOmatic to not render a sidebar for Commerce 4 products:
https://github.com/nystudio107/craft-seomatic/issues/1336
I've fixed this for now by adding the hook back in, but it seems wrong, in that the code to do it via ::getSidebarHtml() appears to be in Commerce. For now, I just have them both in place:
https://github.com/nystudio107/craft-seomatic/commit/4d60b6ce9b63d4e17e15a0874edc8b9b99e259e9
Steps to reproduce
- Set a breakpoint in
Product::getSidebarHtml() - Load an Edit Product page
Expected behavior
The breakpoint would be hit
Actual behavior
The breakpoint is not hit, because it appears the sidebar isn't rendered via this mechanism at all (despite the code being present), but rather entirely via template & template hooks.
Craft CMS version
4.4.13
Craft Commerce version
4.2.11
PHP version
n/a
Operating system and version
n/a
Database type and version
n/a
Image driver and version
n/a
Installed plugins and versions
- SEOmatic
Thanks for reporting, we are aware that the product edit page is not using the element controller to render its edit page. The method you are referring to was implemented to support the slideout edit page in the interim.
We will unify the product editor to use the element controller and remove the product edit controller action in Commerce 5.
Thanks.
https://linear.app/craftcms/issue/COM-242/products-should-use-the-element-editor-controller