How to add definition, entity classes for new fields in existing tables?

Hi

I have to add two more fields published_from, published_to in cms_page table.

I have created a migration file. The migration is working fine.

Then i need to create the definition file right?

<?php declare(strict_types=1);

namespace Hatslogic\Sw\ProductsAndLayoutsScheduler\Core\Content\Cms; use Shopware\Core\Content\Cms\CmsPageDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityExtensionInterface; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField; class CmsPageExtension implements EntityExtensionInterface {     public function extendFields(FieldCollection $collection): void     {         $collection-\>add(             (new DateTimeField('published\_from', 'publishedFrom')),             (new DateTimeField('published\_to', 'publishedTo'))         );     }     public function getDefinitionClass(): string     {         return CmsPageDefinition::class;     } } But i am getting the following error "Only AssociationFields, FkFields/ReferenceVersionFields for a ManyToOneAssociationField or fields flagged as Runtime can be added as Extension." How to add definition, entity classes for new fields in existing tables?

Entity extensions are not meant to be used for scalar extensions. for that, there are the custom fields.
you could only use associations or foreign keys

most entities have the custom fields column in the database. but not all modules in the admin does have a UI for that. so it is possible to create new custom fields with your plugin. but sometimes you need to extend a module to show them to the admin user

import { Component } from 'src/core/shopware';
import template from './sw-cms-sidebar.html.twig';
const { Criteria } = Shopware.Data;

Component.override('sw-cms-sidebar', {
    template,

    data() {
        return {
            customFieldSets: [],
            isLoading: false
        };
    },

    computed: {
    	customFieldSetRepository() {
            return this.repositoryFactory.create('custom_field_set');
        },

        customFieldSetCriteria() {
            const criteria = new Criteria();
            criteria.setPage(1);
            criteria.setLimit(100);
            criteria.addFilter(
                Criteria.equals('relations.entityName', 'cms_page')
            );

            criteria.getAssociation('customFields')
                .addSorting(Criteria.sort('config.customFieldPosition', 'ASC'))
                .setLimit(100);

            return criteria;
        },
    },

    created() {
        this.loadEntityData();
    },

    methods: {
        loadEntityData() {
            this.isLoading = true;

            this.customFieldSetRepository
                .search(this.customFieldSetCriteria, Shopware.Context.api)
                .then((result) => {
                	this.isLoading = false;
                    this.customFieldSets = result.filter((set) => set.customFields.length > 0);
                });
        }
    }
});

{% block sw_cms_sidebar_page_settings_type_field %}

{% parent %}
    
          
          
    
{% endblock %}

I have displayed the custom fields in admin side using the above code.

1 „Gefällt mir“