3 namespace Drupal\Core\Entity;
6 * Provides helper methods to detect changes in an entity object.
8 * @internal This may be replaced by a proper entity comparison handler.
10 trait EntityChangesDetectionTrait {
13 * Returns an array of field names to skip when checking for changes.
15 * @param \Drupal\Core\Entity\ContentEntityInterface $entity
16 * A content entity object.
19 * An array of field names.
21 protected function getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity) {
22 /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
23 $entity_type = $entity->getEntityType();
25 // A list of known revision metadata fields which should be skipped from
28 $entity_type->getKey('revision'),
29 $entity_type->getKey('revision_translation_affected'),
31 $fields = array_merge($fields, array_values($entity_type->getRevisionMetadataKeys()));
33 // Computed fields should be skipped by the check for translation changes.
34 foreach (array_diff_key($entity->getFieldDefinitions(), array_flip($fields)) as $field_name => $field_definition) {
35 if ($field_definition->isComputed()) {
36 $fields[] = $field_name;