protected static function EntityResource::relationshipArityIsAffected in JSON:API 8
Checks whether relationship arity is affected.
Parameters
\Drupal\Core\Field\EntityReferenceFieldItemListInterface $old: The old (stored) entity references.
\Drupal\Core\Field\EntityReferenceFieldItemListInterface $new: The new (updated) entity references.
Return value
bool Whether entities already being referenced now have additional references.
See also
\Drupal\jsonapi\Normalizer\Value\RelationshipNormalizerValue::ensureUniqueResourceIdentifierObjects()
1 call to EntityResource::relationshipArityIsAffected()
- EntityResource::createRelationship in src/
Controller/ EntityResource.php - Adds a relationship to a to-many relationship.
File
- src/
Controller/ EntityResource.php, line 636
Class
- EntityResource
- Process all entity requests.
Namespace
Drupal\jsonapi\ControllerCode
protected static function relationshipArityIsAffected(EntityReferenceFieldItemListInterface $old, EntityReferenceFieldItemListInterface $new) {
$old_targets = static::toTargets($old);
$new_targets = static::toTargets($new);
$relationship_count_changed = count($old_targets) !== count($new_targets);
$existing_relationships_updated = !empty(array_unique(array_intersect($old_targets, $new_targets)));
return $relationship_count_changed && $existing_relationships_updated;
}