Shopware 6允许扩展CMS元素吗?

huangapple go评论65阅读模式
英文:

Extend CMS Elements in Shopware 6 allowed?

问题

技术上,可以在插件中使用自定义字段扩展标准的Shopware 6 CMS元素。例如,我想要在图像元素中扩展标题和副标题,可以在图像上显示这些内容。我认为为了这种情况创建一个全新的元素并不是很合理。

在技术上,可以将自定义元素添加到图像配置中,并在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);

但需要注意的是,这个过程并没有正式文档记录,我不确定它是否会在代码审查中被接受。

英文:

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.

答案1

得分: 1

虽然我认为从代码角度来看,这种方法看起来很简洁,但一个潜在的异议可能是,即使在卸载插件后,这可能会在默认CMS元素的数据库条目中保留数据。您必须确保在卸载插件后不会留下任何痕迹,并且图像元素的外观应该与安装并使用您的插件之前的状态完全相同。您还需要考虑在安装您的插件之前可能已经使用了图像元素。您必须确保它们在安装您的插件后也会正常显示,包括您新添加的标题和子标题起初丢失的情况。

个人认为,如果您可以创建一个全新的自定义CMS元素,那将会减少很多麻烦。虽然从一开始重新创建大部分现有的图像元素无疑需要更多的工作,但最终将为您和用户提供解决上述问题以及有关插件审核的担忧。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 17:58:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75660438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定