mirror of
https://github.com/getgrav/grav.git
synced 2026-03-15 17:11:02 +01:00
Added FlexCollection::getDistinctValues() to get all the assigned values from the field
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* Added support for overriding configuration by using environment variables
|
||||
* Use PHP 7.4 serialization (the old `Serializable` methods are now final and cannot be overridden)
|
||||
* Enabled `ETag` setting by default for 304 responses
|
||||
* Added `FlexCollection::getDistinctValues()` to get all the assigned values from the field
|
||||
1. [](#improved)
|
||||
* Make it possible to use an absolute path when loading a blueprint
|
||||
* Make serialize methods final in `ContentBlock`, `AbstractFile`, `FormTrait`, `ObjectCollectionTrait` and `ObjectTrait`
|
||||
|
||||
@@ -71,6 +71,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
|
||||
'isAuthorized' => 'session',
|
||||
'search' => true,
|
||||
'sort' => true,
|
||||
'getDistinctValues' => true
|
||||
];
|
||||
}
|
||||
|
||||
@@ -272,6 +273,33 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the values in property.
|
||||
*
|
||||
* Supports either single scalar values or array of scalar values.
|
||||
*
|
||||
* @param string $property Object property to be used to make groups.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return array
|
||||
*/
|
||||
public function getDistinctValues(string $property, string $separator = null): array
|
||||
{
|
||||
$list = [];
|
||||
|
||||
/** @var FlexObjectInterface $element */
|
||||
foreach ($this->getIterator() as $element) {
|
||||
$value = (array)$element->getNestedProperty($property, null, $separator);
|
||||
foreach ($value as $v) {
|
||||
if (is_scalar($v)) {
|
||||
$t = gettype($v) . (string)$v;
|
||||
$list[$t] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see FlexCollectionInterface::withKeyField()
|
||||
|
||||
Reference in New Issue
Block a user