Field.php in Helper 8
File
src/Field.php
View source
<?php
namespace Drupal\helper;
use Drupal\Core\Field\FieldItemListInterface;
class Field {
public static function getDuplicateValues(FieldItemListInterface $items, $property = NULL) {
$values = [];
foreach ($items as $delta => $item) {
if (!isset($property)) {
$property = $item::mainPropertyName();
}
if (isset($item->{$property})) {
$values[] = (string) $item->{$property};
}
}
$value_counts = array_count_values($values);
$duplicates = array_filter($value_counts, function ($count) {
return $count > 1;
});
return array_keys($duplicates);
}
}
Classes
Name |
Description |
Field |
Provides helpers for working with field values. |