You are here

public function FieldComparatorManager::hasChanged in Conflict 8.2

Compares two field item lists.

Parameters

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

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

string $langcode: The language code of the entity translation being checked.

string $entity_type_id: The entity type ID.

string $bundle: The entity bundle ID.

string $field_type: The field type.

string $field_name: The field name.

Return value

bool TRUE, if the items have changed, FALSE otherwise.

Throws

\Exception An exception will be thrown if for some reason even the default field comparator has not been added to the field comparators list.

Overrides FieldComparatorManagerInterface::hasChanged

File

src/FieldComparatorManager.php, line 74

Class

FieldComparatorManager

Namespace

Drupal\conflict

Code

public function hasChanged(FieldItemListInterface $items_a, FieldItemListInterface $items_b, $langcode, $entity_type_id, $bundle, $field_type, $field_name) {

  // Iterate from the most specific to the most general comparator.
  foreach ($this
    ->getOrderedFieldComparators($entity_type_id, $bundle, $field_type, $field_name) as &$comparator) {

    /** @var \Drupal\conflict\FieldComparatorInterface $comparator */
    if (!is_object($comparator)) {
      $comparator = $this
        ->createInstance($comparator);
    }
    if ($comparator::isApplicable($items_a
      ->getFieldDefinition())) {
      $result = $comparator
        ->hasChanged($items_a, $items_b, $langcode, $entity_type_id, $bundle, $field_type, $field_name);
      if (is_bool($result)) {
        return $result;
      }
    }
  }
  return FALSE;
}