You are here

public function MapFieldItemList::equals in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/MapFieldItemList.php \Drupal\Core\Field\MapFieldItemList::equals()
  2. 9 core/lib/Drupal/Core/Field/MapFieldItemList.php \Drupal\Core\Field\MapFieldItemList::equals()

Determines equality to another object implementing FieldItemListInterface.

This method is usually used by the storage to check for not computed value changes, which will be saved into the storage.

Parameters

\Drupal\Core\Field\FieldItemListInterface $list_to_compare: The field item list to compare to.

Return value

bool TRUE if the field item lists are equal, FALSE if not.

Overrides FieldItemList::equals

File

core/lib/Drupal/Core/Field/MapFieldItemList.php, line 13

Class

MapFieldItemList
Defines an item list class for map fields.

Namespace

Drupal\Core\Field

Code

public function equals(FieldItemListInterface $list_to_compare) {
  $count1 = count($this);
  $count2 = count($list_to_compare);
  if ($count1 === 0 && $count2 === 0) {

    // Both are empty we can safely assume that it did not change.
    return TRUE;
  }
  if ($count1 !== $count2) {

    // The number of items is different so they do not have the same values.
    return FALSE;
  }

  // The map field type does not have any property defined (because they are
  // dynamic), so the only way to evaluate the equality for it is to rely
  // solely on its values.
  $value1 = $this
    ->getValue();
  $value2 = $list_to_compare
    ->getValue();
  return $value1 == $value2;
}