Upgrade to 3.9.6

This commit is contained in:
Bastian Allgeier
2023-07-27 12:08:43 +02:00
parent f76fbaa53e
commit 7928c28702
58 changed files with 930 additions and 148 deletions

View File

@@ -199,7 +199,7 @@ return [
'slug' => Field::slug([
'required' => true,
'preselect' => $select === 'slug',
'path' => $page->parent() ? '/' . $page->parent()->id() . '/' : '/',
'path' => $page->parent() ? '/' . $page->parent()->uri() . '/' : '/',
'disabled' => $permissions->can('changeSlug') === false,
'wizard' => [
'text' => I18n::translate('page.changeSlug.fromTitle'),

View File

@@ -135,18 +135,14 @@ return [
/**
* Add your own search engine
*
* @param \Kirby\Cms\App $kirby Kirby instance
* @param \Kirby\Cms\Collection $collection Collection of searchable models
* @param string $query
* @param mixed $params
* @return \Kirby\Cms\Collection|bool
*/
'search' => function (App $kirby, Collection $collection, string $query = null, $params = []) {
// empty search query
if (empty(trim($query ?? '')) === true) {
return $collection->limit(0);
}
'search' => function (
App $kirby,
Collection $collection,
string $query = '',
$params = []
): Collection|bool {
if (is_string($params) === true) {
$params = ['fields' => Str::split($params, '|')];
}
@@ -158,30 +154,42 @@ return [
'words' => false,
];
$options = array_merge($defaults, $params);
$collection = clone $collection;
$options = array_merge($defaults, $params);
$query = trim($query);
// empty or too short search query
if (Str::length($query) < $options['minlength']) {
return $collection->limit(0);
}
$words = preg_replace('/(\s)/u', ',', $query);
$words = Str::split($words, ',', $options['minlength']);
$exact = $options['words'] ? '(\b' . preg_quote($query) . '\b)' : preg_quote($query);
$query = Str::lower($query);
if (empty($options['stopwords']) === false) {
$words = array_diff($words, $options['stopwords']);
}
$words = A::map(
$words,
fn ($value) => $options['words'] ? '\b' . preg_quote($value) . '\b' : preg_quote($value)
);
// returns an empty collection if there is no search word
if (empty($words) === true) {
return $collection->limit(0);
}
$words = A::map(
$words,
fn ($value) => Str::wrap(preg_quote($value), $options['words'] ? '\b' : '')
);
$exact = preg_quote($query);
if ($options['words']) {
$exact = '(\b' . $exact . '\b)';
}
$query = Str::lower($query);
$preg = '!(' . implode('|', $words) . ')!i';
$scores = [];
$results = $collection->filter(function ($item) use ($query, $exact, $preg, $options, &$scores) {
$data = $item->content()->toArray();
$keys = array_keys($data);
@@ -193,10 +201,10 @@ return [
$keys[] = 'role';
} elseif ($item instanceof Page) {
// apply the default score for pages
$options['score'] = array_merge([
'id' => 64,
'title' => 64,
], $options['score']);
$options['score'] = array_merge(
['id' => 64, 'title' => 64],
$options['score']
);
}
if (empty($options['fields']) === false) {
@@ -242,6 +250,7 @@ return [
}
$scores[$item->id()] = $scoring;
return $scoring['hits'] > 0;
});

View File

@@ -8,7 +8,7 @@ return [
* Default number that will be saved when a new page/user/file is created
*/
'default' => function ($default = null) {
return $this->toNumber($default);
return $this->toNumber($default) ?? '';
},
/**
* The lowest allowed number
@@ -26,10 +26,10 @@ return [
* Allowed incremental steps between numbers (i.e `0.5`)
*/
'step' => function ($step = null) {
return $this->toNumber($step);
return $this->toNumber($step) ?? '';
},
'value' => function ($value = null) {
return $this->toNumber($value);
return $this->toNumber($value) ?? '';
}
],
'methods' => [

View File

@@ -53,9 +53,9 @@ if (Helpers::hasOverride('collection') === false) { // @codeCoverageIgnore
* @return \Kirby\Toolkit\Collection|null
* @todo 5.0 Add return type declaration
*/
function collection(string $name)
function collection(string $name, array $options = [])
{
return App::instance()->collection($name);
return App::instance()->collection($name, $options);
}
}

View File

@@ -34,9 +34,9 @@ return [
],
'computed' => [
'reports' => function () {
$reports = [];
$model = $this->model();
$value = fn ($value) => $value === null ? null : $model->toString($value);
$reports = [];
$model = $this->model();
$toString = fn ($value) => $value === null ? null : $model->toString($value);
foreach ($this->reports as $report) {
if (is_string($report) === true) {
@@ -47,14 +47,17 @@ return [
continue;
}
$info = $report['info'] ?? null;
$info = $report['info'] ?? null;
$label = $report['label'] ?? null;
$link = $report['link'] ?? null;
$value = $report['value'] ?? null;
$reports[] = [
'label' => I18n::translate($report['label'], $report['label']),
'value' => $value($report['value'] ?? null),
'info' => $value(I18n::translate($info, $info)),
'link' => $value($report['link'] ?? null),
'theme' => $value($report['theme'] ?? null)
'info' => $toString(I18n::translate($info, $info)),
'label' => $toString(I18n::translate($label, $label)),
'link' => $toString(I18n::translate($link, $link)),
'theme' => $toString($report['theme'] ?? null),
'value' => $toString(I18n::translate($value, $value))
];
}