I try to clone the content element image-slider
or image-gallery
(the error will come at both) to extend them. First I register a new CmsElement like the original only changes the name from image-slider
to image-slider-example
import './component';
import './config';
import './preview';
Shopware.Service('cmsService').registerCmsElement({
name: 'image-slider-example',
label: 'sw-cms.elements.imageSlider.label',
component: 'sw-cms-el-image-slider',
configComponent: 'sw-cms-el-config-image-slider',
previewComponent: 'sw-cms-el-preview-image-slider',
defaultConfig: {
sliderItems: {
source: 'static',
value: [],
required: true,
entity: {
name: 'media'
}
},
displayMode: {
source: 'static',
value: 'standard'
},
minHeight: {
source: 'static',
value: '300px'
},
verticalAlign: {
source: 'static',
value: null
}
},
enrich: function enrich(elem, data) {
if (Object.keys(data).length < 1) {
return;
}
Object.keys(elem.config).forEach((configKey) => {
const entity = elem.config[configKey].entity;
if (!entity) {
return;
}
const entityKey = entity.name;
if (!data[`entity-${entityKey}`]) {
return;
}
elem.data[configKey] = [];
elem.config[configKey].value.forEach((sliderItem) => {
elem.data[configKey].push({
newTab: sliderItem.newTab,
url: sliderItem.url,
media: data[`entity-${entityKey}`].get(sliderItem.mediaId)
});
});
});
}
});
Now It shows me the new element in the Shopping Experience, where I can use it.
After that I create for the storefront the cms-element-image-slider-example.html.twig
file, which will be loaded by Shopware.
{% sw_extends '@Storefront/storefront/element/cms-element-image-slider.html.twig' %}
{% block element_image_slider_alignment %}
<pre>
{{ dump(element) }}
</pre>
{{ parent() }}
{% endblock %}
Now I extend the original storefront element from which I was cloning and add a dump
to see all data. But there I have the issue, that the element.data
are null
but there should be all images stored.