function ContentEntityStorageBase::hasFieldValueChanged
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::hasFieldValueChanged()
- 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::hasFieldValueChanged()
- 11.x 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 934
Class
- ContentEntityStorageBase
- Base class for content entity storage handlers.
Namespace
Drupal\Core\EntityCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.