Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityChangesDetectionTrait.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
5 /**
6  * Provides helper methods to detect changes in an entity object.
7  *
8  * @internal This may be replaced by a proper entity comparison handler.
9  */
10 trait EntityChangesDetectionTrait {
11
12   /**
13    * Returns an array of field names to skip when checking for changes.
14    *
15    * @param \Drupal\Core\Entity\ContentEntityInterface $entity
16    *   A content entity object.
17    *
18    * @return string[]
19    *   An array of field names.
20    */
21   protected function getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity) {
22     /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
23     $entity_type = $entity->getEntityType();
24
25     // A list of known revision metadata fields which should be skipped from
26     // the comparision.
27     $fields = [
28       $entity_type->getKey('revision'),
29       $entity_type->getKey('revision_translation_affected'),
30     ];
31     $fields = array_merge($fields, array_values($entity_type->getRevisionMetadataKeys()));
32
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;
37       }
38     }
39
40     return $fields;
41   }
42
43 }