I want to inherit props from a sw-component which I’m overriding

Viewed 282

I want to inherit props from a sw-component which I’m overriding. I know I can get the component from the registry, but the part I’m willing to inherit comes from the default() property of a prop.

We want to add more options to the link config without having to copy the whole return part of the overriding buttonConfig.default()

import template from './sw-text-editor.html.twig';
import './sw-text-editor.scss';

const { Component } = Shopware;

Component.register('sw-text-editor', {
    template,

    props: {

        buttonConfig: {
            type: Array,
            required: false,
            default() {
                return [
                    {
                        type: 'link',
                        title: this.$tc('sw-text-editor-toolbar.title.link'),
                        icon: 'default-text-editor-link',
                        expanded: false,
                        newTab: false,
                        displayAsButton: false,
                        buttonVariant: '',
                        buttonVariantList: [
                            {
                                id: 'primary',
                                name: this.$tc('sw-text-editor-toolbar.link.buttonVariantPrimary')
                            },
                            {
                                id: 'secondary',
                                name: this.$tc('sw-text-editor-toolbar.link.buttonVariantSecondary')
                            },
                            {
                                id: 'primary-sm',
                                name: this.$tc('sw-text-editor-toolbar.link.buttonVariantPrimarySmall')
                            },
                            {
                                id: 'secondary-sm',
                                name: this.$tc('sw-text-editor-toolbar.link.buttonVariantSecondarySmall')
                            }
                        ],
                        value: '',
                        tag: 'a'
                    },
                ];
            }
        }
    },
});
1 Answers

This can be done by overriding the createdComponent method. Calling the parent createdComponent method is done with this.$super('createdComponent')

Related