Shopware-6-Blog-Plugin icon indicating copy to clipboard operation
Shopware-6-Blog-Plugin copied to clipboard

Custom Field

Open s1de21 opened this issue 2 years ago • 9 comments

is there a way to add a custom field or even a custom taxonomy for blog entries like location etc.?

s1de21 avatar Jul 25 '22 13:07 s1de21

i'm also interested!

andevit avatar Aug 02 '22 10:08 andevit

I've noticed the BlogEntriesDefinition does contain support for custom fields so adding one programmatically should work, but I would rather add one through the admin panel. Would it be possible to add support for adding a custom field to blog entities and being able to edit the values for each blog through the admin panel?

Alphaegen avatar Oct 13 '22 06:10 Alphaegen

@ChristopherDosin I've noticed that this issue hasn't been responded to yet. Any way you can add a response or close the issue?

Alphaegen avatar Oct 13 '22 06:10 Alphaegen

customFields are available within the database already.

If you want to show some customFields, you would need to extend the current module to be able to show these inside the administration.

We might need to extend the documentation to show you how you can actually set the customFields within the administration.

ChristopherDosin avatar Oct 30 '22 09:10 ChristopherDosin

I guess it's very hard to implement, because the custom field detail form (sw-custom-field-set-detail-base) have to be aware of the sas_blog_entries entity. But the known entities are hardcoded at custom-field.service.js (search for $entityNameStore). This is required to assign a custom field set to the blog entities. The only alternative is to show every available custom field set in the blog module. But I don't like this idea.

timonf avatar Oct 30 '22 22:10 timonf

@viennt We should take a look into this for our version 2.

@timonf I am not sure how familiar you are with the customFieds / how you are using them. But you you have basically two ways. Either use these UI implemented customFields that you know from the products etc.

Or you can use them directly inside your template. Let's say you want to extend the product view with a short description below the actual description. Then you just call your customField like this:

<template v-if="product.customFields">
        <sw-inherit-wrapper
            v-model="product.customFields.shortDescription"
            :has-parent="!!parentProduct.id"
            :inherited-value="parentProduct.id ? parentProduct.customFields.shortDescription : null"
        >
            <template #content="props">
                <sw-field
                    type="textarea"
                    :map-inheritance="props"
                    :value="props.currentValue"
                    :disabled="props.isInherited || !allowEdit"
                    :label="$tc('sw-product.basicForm.labelShortDesc')"
                    :placeholder="$tc('sw-product.basicForm.placeholderShortDesc')"
                    @input="props.updateCurrentValue"
                />
            </template>
        </sw-inherit-wrapper>
    </template>

The JS would be like

import template from './sw-product-basic-form.html.twig';
const {Component} = Shopware;
Component.override('sw-product-basic-form', {
    template,
    methods: {
        createdComponent() {
            this.initCustomField();
            this.$super('createdComponent');
        },
        initCustomField() {
            this.product.customFields = this.product.customFields ?? {};
            this.parentProduct.customFields = this.parentProduct.customFields ?? {};
        },
    },
});

Bildschirmfoto 2022-10-31 um 08 49 50

Hope this helps.

ChristopherDosin avatar Oct 31 '22 06:10 ChristopherDosin