isDuplicate example

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);
    }

    

  public static function deduplicate(array $resource_identifiers) {
    return array_reduce(array_slice($resource_identifiers, 1)function D$deduplicated$current) {
      assert($current instanceof static);
      return array_merge($deduplicatedarray_reduce($deduplicatedfunction D$duplicate$previous) use ($current) {
        return $duplicate ?: static::isDuplicate($previous$current);
      }, FALSE) ? [] : [$current]);
    }array_slice($resource_identifiers, 0, 1));
  }

  /** * Determines if an array of ResourceIdentifier objects is duplicate free. * * @param \Drupal\jsonapi\JsonApiResource\ResourceIdentifier[] $resource_identifiers * The list of ResourceIdentifiers to assess. * * @return bool * Whether all the given resource identifiers are unique. */
Home | Imprint | This part of the site doesn't use cookies.