You are here

protected function ContentEntityStorageBase::hasFieldValueChanged in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::hasFieldValueChanged()

Checks whether the field values changed compared to the original entity.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: Field definition of field to compare for changes.

\Drupal\Core\Entity\ContentEntityInterface $entity: Entity to check for field changes.

\Drupal\Core\Entity\ContentEntityInterface $original: Original entity to compare against.

Return value

bool True if the field value changed from the original entity.

1 call to ContentEntityStorageBase::hasFieldValueChanged()
SqlContentEntityStorage::saveToDedicatedTables in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
Saves values of fields that use dedicated tables.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 492
Contains \Drupal\Core\Entity\ContentEntityStorageBase.

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function hasFieldValueChanged(FieldDefinitionInterface $field_definition, ContentEntityInterface $entity, ContentEntityInterface $original) {
  $field_name = $field_definition
    ->getName();
  $langcodes = array_keys($entity
    ->getTranslationLanguages());
  if ($langcodes !== array_keys($original
    ->getTranslationLanguages())) {

    // If the list of langcodes has changed, we need to save.
    return TRUE;
  }
  foreach ($langcodes as $langcode) {
    $items = $entity
      ->getTranslation($langcode)
      ->get($field_name)
      ->filterEmptyItems();
    $original_items = $original
      ->getTranslation($langcode)
      ->get($field_name)
      ->filterEmptyItems();

    // If the field items are not equal, we need to save.
    if (!$items
      ->equals($original_items)) {
      return TRUE;
    }
  }
  return FALSE;
}