I have 2 entities of the same type & bundle but used in 2 different cases (linked differently to different entities). Upon publishing the second entity, I want to get the new data and put it into the 'main' entity since all logic is built based on the main entity and interacts with other sorts of things.
What I have so far:
$fields_to_exclude = [
'id',
'uuid',
'vid',
];
foreach ($second_entity->getFields() ?: [] as $name => $field) {
if (!in_array($name, $fields_to_exclude)) {
$main_entity->set($name, $field->getValue());
}
}
$main_entity->save();
There are around 120 fields and I need to exclude only 5-10. My problem is that I want to get only fields created in the interface such as 'field_country_name', 'field_category' etc. The function above returns all entity fields (such as ID, UID, etc.) and there are too many to take into consideration. Is there any way to get only the 'custom created fields' ? I could not find anything in the Drupal API.