Symfony 7 – proper way to reuse parts of common forms with many entities

I need a help with check if my thinking is correct.

My application allows to publish adverts on website. I have have many entites with similar fields. For example consider this approach:

I have 3 entities:

  • Customer (contains: id, name, description)
  • Advertisement (contains: id, name, description, address1, address2, city)
  • DeliveryAddress: (contains: id, address1, adddress2, city)

I have two traits (to avoid declare the same entity properties many times):
BaseTrait: name, description
AddressTrait: address1, address2, city

And I have 2 custom form fields:

  • address (contains: address1, address2, city)
  • baseInfo (contains: name, description)

My goal is use fields address, and baseInfo to combine it in one field and attach constraints from entity to fields, included in these custom fields, for example:

class Advertisement {
    // My entity
    #[AssertNotBlank]
    private string $name;

    #[AssertNotBlank]
    private string $description;

    #[AssertNotBlank]
    private string $address1;

    #[AssertNotBlank]
    private string $address2;

    #[AssertNotBlank]
    private string $city;

//Form 
$builder->add('baseInfo', BaseType::class, [ // Map properties from this field to Advertisement properties: name, description
$builder->add('address', AddressType::class, [ // Map properties from this field to Customer properties: address1, address2, city

So after submit form, I should have errors for fields name, description, address1, address2, city when will be empty (because Entity defines constraints NotBlank).

I would like do the same (reuse some of my custom fields) with other entities, like:

class Customer {
    // My entity
    #[AssertNotBlank]
    private string $name;

    #[AssertNotBlank]
    private string $description;

    #[AssertNotBlank]
    private string $anotherProperty;
//Form 
$builder->add('baseInfo', BaseType::class, [ // Map properties from this field to Customer properties: name, description
$builder->add('anotherProperty', TextType::class

Similar, fields name, description should have constraints from Entity

I tried many things from ChatGPT or Symfony docs, but no luck. When I try to add custom field, I cannot set mapping=>true, because property address/baseInfo doesn’t exist inside entity (its logical). When I put mapping=>false, then validation is skiped.

I tried to combine validation groups, but not luck as well. Seems that Symfony docs doesn’t say anything how to nest Entity fields into custom form type with custom fields (with constraints).

I didn’t share my code here, becasue I’m wondering if my thinking is correct. Maybe I could resolve it by parent Abstract class or make full form based on something Interface etc. But it means, that for (for example 50 entities), I will have to create 50 similar or unique forms, what it’s unecessary effort for me.

So in sum, will be grateful for ideas how to proper resolve this issue
and don’t repeat too much code.

Will be grateful for all your hints.