public function EntityReferenceRevisionsFieldItemList::hasAffectingChanges in Entity Reference Revisions 8
Determines whether the field has relevant changes.
This is for example used to determine if a revision of an entity has changes in a given translation. Unlike \Drupal\Core\Field\FieldItemListInterface::equals(), this can report that for example an untranslatable field, despite being changed and therefore technically affecting all translations, is only internal metadata or only affects a single translation.
Parameters
\Drupal\Core\Field\FieldItemListInterface $original_items: The original field items to compare against.
string $langcode: The language that should be checked.
Return value
bool TRUE if the field has relevant changes, FALSE if not.
Overrides FieldItemList::hasAffectingChanges
File
- src/
EntityReferenceRevisionsFieldItemList.php, line 130
Class
- EntityReferenceRevisionsFieldItemList
- Defines a item list class for entity reference fields.
Namespace
Drupal\entity_reference_revisionsCode
public function hasAffectingChanges(FieldItemListInterface $original_items, $langcode) {
// If there are fewer items, then it is a change.
if (count($this) < count($original_items)) {
return TRUE;
}
foreach ($this as $delta => $item) {
// If this is a different entity, then it is an affecting change.
if (!$original_items
->offsetExists($delta) || $item->target_id != $original_items[$delta]->target_id) {
return TRUE;
}
// If it is the same entity, only consider it as having affecting changes
// if the target entity itself has changes.
if ($item->entity && $item->entity
->hasTranslation($langcode) && $item->entity
->getTranslation($langcode)
->hasTranslationChanges()) {
return TRUE;
}
}
return FALSE;
}