Redesign the interface view of Shopware management CMS component editor
P粉797855790
2023-08-14 12:07:32
<p>In creating a new CMS element for use in Shopware's WYSIWYG editor, we have three components: one named <code>component</code> and another named <code> configComponent</code>, and another named <code>previewComponent</code>. </p>
The <p><code>configComponent</code> is obviously used to select the configuration of the element, while the <code>component</code> component is used to update the view in the editor. For example, display the content selected in the configuration section. My problem is that it only updates the view in the editor after the user clicks the save button, which leads to a bad user experience - it should update in real time. </p>
<p><strong>I think I need to somehow <code>$emit</code>an update event</strong> after selecting the entity id from <code>configComponent</code>, Then pass the ID of the selected entity to the <code>component</code> component. </p>
<p>So, in twig of <code>component</code>, I have the following code: </p>
<pre class="brush:js;toolbar:false;"> <config-component @entity-picked="entityPickedHandler" />
</pre>
<p>From my understanding of the documentation, this should be called in <code>component</code> when the <code>entity-picked</code> event is emitted from <code>configComponent</code> "entityPickedHandler" method. </p>
<p>For example, this is the event handler in <code>component</code>: </p>
<pre class="brush:js;toolbar:false;">methods: {
entityPickedHandler(data) {
console.log('Trigger event:', data);
}
}
</pre>
<p>Then, emit the event from <code>configComponent</code>: </p>
<pre class="brush:js;toolbar:false;">computed: {
myEntity: {
get() {
return this.element.config.entity.value;
},
set(value) {
// this.$set(this.element.data, 'entityId', value);
this.element.config.entity.value = value;
console.log('Try to emit entity-picked event');
this.$emit('entity-picked', value);
}
}
}
</pre>
<p>Obviously, this doesn't work because <code>console.log()</code> in the <code>entityPickedHandler</code> handler never outputs. However, the event should have been emitted. </p>
Getter/Setter can be a little tricky with scope. The usual approach seems to be correct. Maybe try storing the entity in a data property and setting a listener on it.
renew
Or as a listener inside the
component
component:The data can then be updated from
configComponent
using:Then, in the twig file of
configComponent
, themyentity
method is used in thev-model## of
sw-entity-single-select#: