How to decorate entity definition in shopware 6

I would like to decorate entity definition in plugin shopware 6 to add some modifications. I wolud like to change length string field from standard 255 to 4000.

Definition class to change

my decorate class class with change length string field

...
return new FieldCollection([
            (new StringField('label','label', 4000))->addFlags(new Required()),
            new StringField('description','description', 4000),
            new StringField('error_msg','errorMsg'),
            new StringField('error_msg_min','errorMsgMin'),
            new StringField('error_msg_max','errorMsgMax'),
            ]);
...

my config service

<service id="MyPlugin\Core\Content\Entities\AttributeTranslationDefinitionDecorator"
        decorates="TestPlugin\Entities\Attribute\Translation\AttributeTranslationDefinition" public="false">
        <argument type="service" id="MyPlugin\Core\Content\Entities\AttributeTranslationDefinitionDecorator.inner" />
    </service>

but this not work. I have tried all the ways with pages Adjusting a service - Shopware Developer or How to Decorate Services (Symfony Docs)

Is it possible to change entity definition in other plugins?

That does not change you database. You are missing…

If you just want to change the length to 4000, maybe it is easier to just change it in the database.

Thanks for the reply, That’s how I did it, unfortunately changing on the base is not enough because it still locks me on the definition. StringField is 255 characters by default.

There is some way to change the entity definition in a other plugin or in shopware core ?

What you did was correct. You have to override/decorate the service and in addition change it in the database manually, if you did not use a migration.

Ok but the entity decoration is not working. I changed length in the database by migration but it is not enough, still blocking me on entity definition. So if I want to change the length of the field, I have to change the existing plugin and put it in my repository?

You have to decorate the entity like it is described in the developer manual. If decorating is not possible, you can override it. It’s pretty the same, just without the decorates methods.

Still, your limitation could result through a different location, e.g. in the theme, a different method, …

Can you tell me how to override it ?

This is how you override it. You have to „rebuild“ the complete class with constructor, methods and properties.

I tried but it gets such an error

Looks like your registry property is null. Why is that?

I don’t know, but I found a solution. I use composer-patches to change the definition and it works! Thanks for the answer.

you can set the class in the services.xml to the class of your desired adaptation class. It’s more an overwriting than a decoration but it would solve your problem:

<service id="TestPlugin\Entities\Attribute\Translation\AttributeTranslationDefinition" 
      class="MyPlugin\Core\Content\Entities\AttributeTranslationDefinitionDecorator" public="false">
    <!-- Original arguments here -->
</service>
1 „Gefällt mir“