Search code examples
shopware6

Extend CMS Elements in Shopware 6 allowed?


Is it allowed to extend the standard shopware 6 cms elements with custom fields in a plugin?

For example: I would like to extend the image element with a headline and subline, that can be displayed over the image. I don't think it makes sense to create a completely new element just for such a case.

Technically it's working to add my custom elements to the image config and reregister the element in the main.js:

import './module/sw-cms/elements/image/my-config';

let imageConfig = Shopware.Service('cmsService').getCmsElementConfigByName('image');

imageConfig.defaultConfig.my_headline = {
    source: 'static',
    value: null
}

Shopware.Service('cmsService').registerCmsElement(imageConfig);

But this procedure is not officially documented and and i don't know if it will be accepted in the code review.


Solution

  • While I think that this approach looks clean enough code-wise, one potential objection could be that this could leave data in the database entries for default CMS elements, even after your plugin was uninstalled. You'll have to make sure that there will be no traces left after the plugin was uninstalled and the look of the image elements should be completely identical to the state before your plugin was installed and used. You'll also have to think about the fact that image elements might have been used before the installation of your plugin. You'll have to make sure they'll look fine as well after the installation of your plugin with your newly added headline and subline missing initially.

    Personally I think it would be less of a headache if you could create an entirely new custom CMS element. While it is undoubtedly more work to begin with to recreate most of the existing image element, it will ultimately safe you and your users from considering the issues mentioned above as well as worries regarding the review of your plugin.