# How to decorate entity definition in shopware 6

**URL:** <https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109>\
**Category:** Programming (EN)\
**Tags:** programming\
**Created:** [28. Dezember 2021 um 12:49 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109 "2021-12-28T12:49:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [28. Dezember 2021 um 12:49 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/1 "2021-12-28T12:49:13Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/a/a2ae01f8299ae9e58aa8690853dd58743a0546fa.png)

my decorate class class with change length string field

```auto
...
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

```auto
<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](https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/adjusting-service) or [How to Decorate Services (Symfony Docs)](https://symfony.com/doc/current/service_container/service_decoration.html)

Is it possible to change entity definition in other plugins?

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [28. Dezember 2021 um 13:20 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/2 "2021-12-28T13:20:29Z")

</div>

That does not change you database. You are missing…

> **[Database migrations](https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/database-migrations)**

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

---

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [28. Dezember 2021 um 13:50 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/3 "2021-12-28T13:50:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [30. Dezember 2021 um 10:02 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/4 "2021-12-30T10:02:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [30. Dezember 2021 um 14:11 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/5 "2021-12-30T14:11:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [3. Januar 2022 um 10:31 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/6 "2022-01-03T10:31:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [3. Januar 2022 um 10:50 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/7 "2022-01-03T10:50:31Z")

</div>

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, …

---

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [3. Januar 2022 um 11:44 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/8 "2022-01-03T11:44:24Z")

</div>

Can you tell me how to override it ?

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [3. Januar 2022 um 13:52 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/9 "2022-01-03T13:52:26Z")

</div>

> [@wis154](#):
>
> ```auto
> <service id="MyPlugin\Core\Content\Entities\AttributeTranslationDefinitionDecorator"
> decorates="TestPlugin\Entities\Attribute\Translation\AttributeTranslationDefinition" public="false">
> </service>
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [4. Januar 2022 um 07:02 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/10 "2022-01-04T07:02:32Z")

</div>

I tried but it gets such an error

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/c/c3ecf748a8ca881b404af98197bb95f8e86456cf.png)

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [4. Januar 2022 um 10:28 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/11 "2022-01-04T10:28:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wis154](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@wis154](https://forum.shopware.com/u/wis154)\
**Post date:** [1. Februar 2022 um 07:45 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/12 "2022-02-01T07:45:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dennis\_Konoppa](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/dennis_konoppa/32/27245_2.png) [@Dennis\_Konoppa](https://forum.shopware.com/u/Dennis_Konoppa)\
**Post date:** [14. September 2023 um 09:20 UTC](https://forum.shopware.com/t/how-to-decorate-entity-definition-in-shopware-6/92109/13 "2023-09-14T09:20:37Z")

</div>

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:

```auto
<service id="TestPlugin\Entities\Attribute\Translation\AttributeTranslationDefinition" 
      class="MyPlugin\Core\Content\Entities\AttributeTranslationDefinitionDecorator" public="false">
    <!-- Original arguments here -->
</service>

```
