MapFieldItemList.php 877 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Drupal\Core\Field;
  3. /**
  4. * Defines a item list class for map fields.
  5. */
  6. class MapFieldItemList extends FieldItemList {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public function equals(FieldItemListInterface $list_to_compare) {
  11. $count1 = count($this);
  12. $count2 = count($list_to_compare);
  13. if ($count1 === 0 && $count2 === 0) {
  14. // Both are empty we can safely assume that it did not change.
  15. return TRUE;
  16. }
  17. if ($count1 !== $count2) {
  18. // The number of items is different so they do not have the same values.
  19. return FALSE;
  20. }
  21. // The map field type does not have any property defined (because they are
  22. // dynamic), so the only way to evaluate the equality for it is to rely
  23. // solely on its values.
  24. $value1 = $this->getValue();
  25. $value2 = $list_to_compare->getValue();
  26. return $value1 == $value2;
  27. }
  28. }