diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf0b6791..de6e63544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - `text`, `url`, `hidden`, `commalist`: 2048 - `text` (multiline), `textarea`: 65536 3. [](#bugfix) - * Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218). + * Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218) * Fix for multi-lang issues with Security Report # v1.7.31 diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index 186c60abc..9c5b16c31 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -147,6 +147,10 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface */ public function search(string $search, $properties = null, array $options = null) { + $directory = $this->getFlexDirectory(); + $properties = $directory->getSearchProperties($properties); + $options = $directory->getSearchOptions($options); + $matching = $this->call('search', [$search, $properties, $options]); $matching = array_filter($matching); diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index f96633b31..b9df07597 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -170,6 +170,44 @@ class FlexDirectory implements FlexDirectoryInterface return null === $name ? $this->config : $this->config->get($name, $default); } + /** + * @param string|string[]|null + * @return array + */ + public function getSearchProperties($properties = null): array + { + if (null !== $properties) { + return (array)$properties; + } + + $properties = $this->getConfig('data.search.fields'); + if (!$properties) { + $fields = $this->getConfig('admin.views.list.fields') ?? $this->getConfig('admin.list.fields', []); + foreach ($fields as $property => $value) { + if (!empty($value['link'])) { + $properties[] = $property; + } + } + } + + return $properties; + } + + /** + * @param array|null $options + * @return array + */ + public function getSearchOptions(array $options = null): array + { + if (empty($options['merge'])) { + return $options ?? (array)$this->getConfig('data.search.options'); + } + + unset($options['merge']); + + return $options + (array)$this->getConfig('data.search.options'); + } + /** * @param string|null $name * @param array $options diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 54438af51..d02065fb7 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -162,6 +162,10 @@ class FlexIndex extends ObjectIndex implements FlexIndexInterface */ public function search(string $search, $properties = null, array $options = null) { + $directory = $this->getFlexDirectory(); + $properties = $directory->getSearchProperties($properties); + $options = $directory->getSearchOptions($options); + return $this->__call('search', [$search, $properties, $options]); } diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index afc656c04..3808b2c64 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -287,17 +287,9 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface */ public function search(string $search, $properties = null, array $options = null): float { - $properties = (array)($properties ?? $this->getFlexDirectory()->getConfig('data.search.fields')); - if (!$properties) { - $fields = $this->getFlexDirectory()->getConfig('admin.views.list.fields') ?? $this->getFlexDirectory()->getConfig('admin.list.fields', []); - foreach ($fields as $property => $value) { - if (!empty($value['link'])) { - $properties[] = $property; - } - } - } - - $options = $options ?? (array)$this->getFlexDirectory()->getConfig('data.search.options'); + $directory = $this->getFlexDirectory(); + $properties = $directory->getSearchProperties($properties); + $options = $directory->getSearchOptions($options); $weight = 0; foreach ($properties as $property) {