function UniqueFieldValueValidator::caseInsensitiveArrayIntersect

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php \Drupal\Core\Validation\Plugin\Validation\Constraint\UniqueFieldValueValidator::caseInsensitiveArrayIntersect()

Perform a case-insensitive array intersection, but keep original capitalization.

Parameters

array $orig_values: The original values to be returned.

array $comp_values: The values to intersect $orig_values with.

Return value

array Elements of $orig_values contained in $comp_values when ignoring capitalization.

1 call to UniqueFieldValueValidator::caseInsensitiveArrayIntersect()
UniqueFieldValueValidator::validate in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php, line 126

Class

UniqueFieldValueValidator
Validates that a field is unique for the given entity type.

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint

Code

private function caseInsensitiveArrayIntersect(array $orig_values, array $comp_values) : array {
    $lowercase_comp_values = array_map('strtolower', $comp_values);
    $intersect_map = array_map(fn(string $x) => in_array(strtolower($x), $lowercase_comp_values, TRUE) ? $x : NULL, $orig_values);
    return array_filter($intersect_map, function ($x) {
        return $x !== NULL;
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.