annotate core/lib/Drupal/Core/Entity/EntityChangesDetectionTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 namespace Drupal\Core\Entity;
Chris@14 4
Chris@14 5 /**
Chris@14 6 * Provides helper methods to detect changes in an entity object.
Chris@14 7 *
Chris@14 8 * @internal This may be replaced by a proper entity comparison handler.
Chris@14 9 */
Chris@14 10 trait EntityChangesDetectionTrait {
Chris@14 11
Chris@14 12 /**
Chris@14 13 * Returns an array of field names to skip when checking for changes.
Chris@14 14 *
Chris@14 15 * @param \Drupal\Core\Entity\ContentEntityInterface $entity
Chris@14 16 * A content entity object.
Chris@14 17 *
Chris@14 18 * @return string[]
Chris@14 19 * An array of field names.
Chris@14 20 */
Chris@14 21 protected function getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity) {
Chris@14 22 /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
Chris@14 23 $entity_type = $entity->getEntityType();
Chris@14 24
Chris@14 25 // A list of known revision metadata fields which should be skipped from
Chris@14 26 // the comparision.
Chris@14 27 $fields = [
Chris@14 28 $entity_type->getKey('revision'),
Chris@14 29 $entity_type->getKey('revision_translation_affected'),
Chris@14 30 ];
Chris@14 31 $fields = array_merge($fields, array_values($entity_type->getRevisionMetadataKeys()));
Chris@14 32
Chris@17 33 // Computed fields should be skipped by the check for translation changes.
Chris@17 34 foreach (array_diff_key($entity->getFieldDefinitions(), array_flip($fields)) as $field_name => $field_definition) {
Chris@17 35 if ($field_definition->isComputed()) {
Chris@17 36 $fields[] = $field_name;
Chris@17 37 }
Chris@17 38 }
Chris@17 39
Chris@14 40 return $fields;
Chris@14 41 }
Chris@14 42
Chris@14 43 }