function EntityUntranslatableFieldsConstraintValidator::hasUntranslatableFieldsChanges

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityUntranslatableFieldsConstraintValidator::hasUntranslatableFieldsChanges()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityUntranslatableFieldsConstraintValidator::hasUntranslatableFieldsChanges()
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityUntranslatableFieldsConstraintValidator::hasUntranslatableFieldsChanges()

Checks whether an entity has untranslatable field changes.

Parameters

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

Return value

bool TRUE if untranslatable fields have changes, FALSE otherwise.

1 call to EntityUntranslatableFieldsConstraintValidator::hasUntranslatableFieldsChanges()
EntityUntranslatableFieldsConstraintValidator::validate in core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php

File

core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php, line 96

Class

EntityUntranslatableFieldsConstraintValidator
Validates the EntityChanged constraint.

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint

Code

protected function hasUntranslatableFieldsChanges(ContentEntityInterface $entity) {
    $skip_fields = $this->getFieldsToSkipFromTranslationChangesCheck($entity);
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $original */
    if (isset($entity->original)) {
        $original = $entity->original;
    }
    else {
        $original = $this->entityTypeManager
            ->getStorage($entity->getEntityTypeId())
            ->loadRevision($entity->getLoadedRevisionId());
    }
    foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
        if (in_array($field_name, $skip_fields, TRUE) || $definition->isTranslatable() || $definition->isComputed()) {
            continue;
        }
        $items = $entity->get($field_name)
            ->filterEmptyItems();
        $original_items = $original->get($field_name)
            ->filterEmptyItems();
        if ($items->hasAffectingChanges($original_items, $entity->getUntranslated()
            ->language()
            ->getId())) {
            return TRUE;
        }
    }
    return FALSE;
}

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