if (!
$is_multiple) { throw new ConflictHttpException(sprintf('You can only DELETE from to-many relationships. %s is a to-one relationship.',
$related));
} // Compute the list of current values and remove the ones in the payload.
$original_resource_identifiers = ResourceIdentifier::
toResourceIdentifiersWithArityRequired($field_list);
$removed_resource_identifiers =
array_uintersect($resource_identifiers,
$original_resource_identifiers,
[ResourceIdentifier::
class, 'compare'
]);
$deltas_to_be_removed =
[];
foreach ($removed_resource_identifiers as $removed_resource_identifier) { foreach ($original_resource_identifiers as $delta =>
$existing_resource_identifier) { // Identify the field item deltas which should be removed.
if (ResourceIdentifier::
isDuplicate($removed_resource_identifier,
$existing_resource_identifier)) { $deltas_to_be_removed[] =
$delta;
} } } // Field item deltas are reset when an item is removed. This removes
// items in descending order so that the deltas yet to be removed will
// continue to exist.
rsort($deltas_to_be_removed);
foreach ($deltas_to_be_removed as $delta) { $field_list->
removeItem($delta);
}