function EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityChangesDetectionTrait.php \Drupal\Core\Entity\EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityChangesDetectionTrait.php \Drupal\Core\Entity\EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck()
  3. 10 core/lib/Drupal/Core/Entity/EntityChangesDetectionTrait.php \Drupal\Core\Entity\EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck()

Returns an array of field names to skip when checking for changes.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: A content entity object.

Return value

string[] An array of field names.

3 calls to EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck()
ContentEntityBase::getFieldsToSkipFromTranslationChangesCheck in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Returns an array of field names to skip in ::hasTranslationChanges.
ContentTranslationHandler::entityFormSharedElements in core/modules/content_translation/src/ContentTranslationHandler.php
Process callback: determines which elements get clue in the form.
EntityUntranslatableFieldsConstraintValidator::hasUntranslatableFieldsChanges in core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php
Checks whether an entity has untranslatable field changes.

File

core/lib/Drupal/Core/Entity/EntityChangesDetectionTrait.php, line 21

Class

EntityChangesDetectionTrait
Provides helper methods to detect changes in an entity object.

Namespace

Drupal\Core\Entity

Code

protected function getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity) {
    
    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $entity->getEntityType();
    // A list of known revision metadata fields which should be skipped from
    // the comparison.
    $fields = [
        $entity_type->getKey('revision'),
        $entity_type->getKey('revision_translation_affected'),
    ];
    $fields = array_merge($fields, array_values($entity_type->getRevisionMetadataKeys()));
    // Computed fields should be skipped by the check for translation changes.
    foreach (array_diff_key($entity->getFieldDefinitions(), array_flip($fields)) as $field_name => $field_definition) {
        if ($field_definition->isComputed()) {
            $fields[] = $field_name;
        }
    }
    return $fields;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.