Creating entity fields based on the fields from another entity I've been trying to create a data structure that resembles something like:

            +-----------+-----------+-----------+
            | Service 1 | Service 2 | Service x |
            +-----------+-----------+-----------+
            |  Price 1  |  Price 2  |  Price x  |
+-----------+-----------+-----------+-----------+---------------+
| Feature 1 |    Yes    |    Yes    |    Yes    | Description 1 |
+-----------+-----------+-----------+-----------+---------------+
| Feature 2 |     1     |     6     |    20     | Description 2 |
+-----------+-----------+-----------+-----------+---------------+
| Feature x |    No     |    No     |    Yes    | Description x |
+-----------+-----------+-----------+-----------+---------------+


I've created a content entity Services, which has the following fields:


Service Name
Price
Feature 1
Feature 2
Feature x


This works great, until I realise that I'm not including the descriptions of each feature.

Drawing on my knowledge of database normalisation, I intend to extrapolate the description and feature to its own content entity, Services Info. I think that would probably work just fine, with one small exception, I now need to maintain the list of features in two entities, something I'm loathed to do.

Is there any way I can get Drupal to synchronise the fields across two tables? So that if/when I add more features to the Services entity, it'll appear in the Services Info entity, waiting for me to input a description for it?

Or, if there's a better, more Drupally way to approach this problem, then please feel free to chime in!

UPDATE:

I realise that my question might not be clear enough, so I thought I'd explain what I'd do if I weren't using Drupal to make this...

I'd have the following SQL tables:

tbl_services:

SERVICE NAME (FK)
FEATURE NAME (FK)
SERVICE FEATURE VALUE


tbl_services_info:

SERVICE NAME (PK)
PRICE


tbl_services_features:

FEATURE NAME (PK)
FEATURE DESCRIPTION
FEATURE RECOMMENDED


... Now I'm looking at it, I guess I'm missing an entity..? Which if I introduced I could have them reference each other correctly?

If I were to implement it this way I'd also have the issue of not being able to REQUIRE that ALL SERVICE NAMEs have ALL SERVICE FEATURE VALUEs declared for ALL FEATURE NAMEs... Could I? Or would I just have to create a custom input form for the entities?
Sounds like you want to "listen" for the creation of entities of type Services, and upon creation, you want to programmatically create another of type Services Info. For that, I'd recommend adding the hook_ENTITY_TYPE_insert hook into your custom module. Replace hook and ENTITY_TYPE with your custom module name and entity type, of course.

The function signature will include $entity as a variable, so you can do any sort of tests you want to do on it (for example, make sure the corresponding Services Info entry hasn't already been created, to avoid a possible infinite loop if you ever decide to write the sync for both entity types).

This method will look something like:

function my_module_services_insert($entity) {

  // If desired, add code here to check for pre-existing mathing Services Info; this will depend on your implementation.
  // For example, if name is unique, run an entity query for services_info entities with a matching name.

  $new_entity_fields = [
    'name' =&gt; $entity-&gt;getName(), // This assumes you want the entry to have the same name as the Services entry; change if desired
    // Other fields as desired
  ];
  $storage = \Drupal::entityTypeManager()-&gt;getStorage('services_info'); // replace 'services_info' with your entity type
  $entity_new = $storage[$content_type]-&gt;create($new_entity_fields);
  $entity_new-&gt;save();
}


That should do the trick. Good luck!