Skip to content

Commit

Permalink
Merge pull request #6225 from getkirby/release/4.1.0
Browse files Browse the repository at this point in the history
4.1.0
  • Loading branch information
bastianallgeier authored Jan 30, 2024
2 parents a537a4d + 8e96a5c commit 2965c31
Show file tree
Hide file tree
Showing 766 changed files with 11,840 additions and 7,118 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
# tests
.codecov.yml export-ignore
.php-cs-fixer.dist.php export-ignore
phpbench.json export-ignore
phpmd.xml.dist export-ignore
phpunit.xml.dist export-ignore
psalm.xml.dist export-ignore
bench/ export-ignore
tests/ export-ignore

# panel
Expand Down
20 changes: 15 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
A clear and concise description of the PR.
Use this section for review hints, explanations or discussion points/todos.
Make sure to point your PR to the relevant develop branches, e.g.
`develop-patch`, `develop-minor` or `v5/develop`
Add relevant release notes: Features, Enhancements, Fixes, Deprecated.
Reference issues from the `kirby` repo or ideas from `feedback.getkirby.com`.
Always mention whether your PR introduces breaking changes.
Expand All @@ -17,6 +20,14 @@ How to contribute: https://contribute.getkirby.com



## Docs
<!--
Add any notes that help to document the feature/changes. Doesn't need
to be your best writing, just a few words and/or code snipptets.
-->



## Ready?
<!--
If you can help to check off the following tasks, that'd be great.
Expand All @@ -25,15 +36,14 @@ If not, don't worry - we will take care of it.
More details: https://contribute.getkirby.com
-->

- [ ] Unit tests for fixed bug/feature
- [ ] In-code documentation (wherever needed)
- [ ] Unit tests for fixed bug/feature
- [ ] Tests and checks all pass


### For review team
<!--
<!--
We will take care of the following before merging the PR.
-->

- [ ] Add changes to release notes draft in Notion
- [ ] Add to [website docs release checklist](https://github.com/getkirby/getkirby.com/pulls) (if needed)
- [ ] Add lab and/or sandbox examples (wherever helpful)
- [ ] Add changes & docs to release notes draft in Notion
4 changes: 2 additions & 2 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
extensions: ${{ env.extensions }}
ini-values: ${{ env.ini }}
coverage: pcov
tools: phpunit:9.5.26, psalm:5.15.0
tools: phpunit:10.5.5, psalm:5.15.0

- name: Setup problem matchers
run: |
Expand All @@ -119,7 +119,7 @@ jobs:

- name: Run tests
if: always() && steps.finishPrepare.outcome == 'success'
run: phpunit --coverage-clover ${{ github.workspace }}/clover.xml
run: phpunit --fail-on-skipped --coverage-clover ${{ github.workspace }}/clover.xml

- name: Statically analyze using Psalm
if: always() && steps.finishPrepare.outcome == 'success'
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
/.idea

# tests
.phpunit.result.cache
.phpbench
.phpunit.cache
/tests/coverage
/tests/tmp

# ignore all the vendor cruft
/vendor/**/.*
Expand Down
3 changes: 3 additions & 0 deletions bench/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "The Kirby core",
"license": "proprietary",
"type": "kirby-cms",
"version": "4.0.3",
"version": "4.1.0",
"keywords": [
"kirby",
"cms",
Expand Down Expand Up @@ -99,15 +99,17 @@
"analyze:composer": "composer validate --strict --no-check-version --no-check-all",
"analyze:phpmd": "phpmd . ansi phpmd.xml.dist --exclude 'dependencies/*,tests/*,vendor/*'",
"analyze:psalm": "psalm",
"bench": "phpbench run --report=aggregate --ref baseline",
"bench:baseline": "phpbench run --report=aggregate --tag baseline",
"build": "./scripts/build",
"ci": [
"@fix",
"@analyze",
"@test"
],
"fix": "php-cs-fixer fix",
"test": "phpunit --stderr",
"test:coverage": "XDEBUG_MODE=coverage phpunit --stderr --coverage-html=tests/coverage",
"test": "phpunit",
"test:coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=tests/coverage",
"zip": "composer archive --format=zip --file=dist"
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions config/aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
'kirby\cms\kirbytag' => 'Kirby\Text\KirbyTag',
'kirby\cms\kirbytags' => 'Kirby\Text\KirbyTags',
'kirby\cms\template' => 'Kirby\Template\Template',
'kirby\form\options' => 'Kirby\Options\Options',
'kirby\form\optionsapi' => 'Kirby\Options\OptionsApi',
'kirby\form\optionsquery' => 'Kirby\Options\OptionsQuery',
'kirby\form\options' => 'Kirby\Option\Options',
'kirby\form\optionsapi' => 'Kirby\Option\OptionsApi',
'kirby\form\optionsquery' => 'Kirby\Option\OptionsQuery',
'kirby\toolkit\dir' => 'Kirby\Filesystem\Dir',
'kirby\toolkit\f' => 'Kirby\Filesystem\F',
'kirby\toolkit\file' => 'Kirby\Filesystem\File',
Expand Down
1 change: 1 addition & 0 deletions config/areas/site/dialogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Kirby\Panel\Field;
use Kirby\Panel\PageCreateDialog;
use Kirby\Panel\Panel;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
use Kirby\Uuid\Uuids;
Expand Down
2 changes: 1 addition & 1 deletion config/areas/system/dialogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'license' => [
'code' => $license->code($obfuscated),
'icon' => $status->icon(),
'info' => $status->info($license->renewal('Y-m-d')),
'info' => $status->info($license->renewal('Y-m-d', 'date')),
'theme' => $status->theme(),
'type' => $license->label(),
],
Expand Down
77 changes: 62 additions & 15 deletions config/fields/color.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use Kirby\Exception\InvalidArgumentException;
use Kirby\Field\FieldOptions;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\Str;

return [
Expand Down Expand Up @@ -52,42 +54,87 @@
return Str::lower($this->default);
},
'options' => function (): array {
return A::map(array_keys($this->options), fn ($key) => [
'value' => $this->options[$key],
'text' => is_string($key) ? $key : null
// resolve options to support manual arrays
// alongside api and query options
$props = FieldOptions::polyfill($this->props);
$options = FieldOptions::factory([
'text' => '{{ item.value }}',
'value' => '{{ item.key }}',
...$props['options']
]);

$options = $options->render($this->model());

if (empty($options) === true) {
return [];
}

$options = match (true) {
// simple array of values
// or value=text (from Options class)
is_numeric($options[0]['value']) ||
$options[0]['value'] === $options[0]['text']
=> A::map($options, fn ($option) => [
'value' => $option['text']
]),

// deprecated: name => value, flipping
// TODO: start throwing in warning in v5
$this->isColor($options[0]['text'])
=> A::map($options, fn ($option) => [
'value' => $option['text'],
// ensure that any HTML in the new text is escaped
'text' => Escape::html($option['value'])
]),

default
=> A::map($options, fn ($option) => [
'value' => $option['value'],
'text' => $option['text']
]),
};

return $options;
}
],
'methods' => [
'isColor' => function (string $value): bool {
return
$this->isHex($value) ||
$this->isRgb($value) ||
$this->isHsl($value);
},
'isHex' => function (string $value): bool {
return preg_match('/^#([\da-f]{3,4}){1,2}$/i', $value) === 1;
},
'isHsl' => function (string $value): bool {
return preg_match('/^hsla?\(\s*(\d{1,3}\.?\d*)(deg|rad|grad|turn)?(?:,|\s)+(\d{1,3})%(?:,|\s)+(\d{1,3})%(?:,|\s|\/)*(\d*(?:\.\d+)?)(%?)\s*\)?$/i', $value) === 1;
},
'isRgb' => function (string $value): bool {
return preg_match('/^rgba?\(\s*(\d{1,3})(%?)(?:,|\s)+(\d{1,3})(%?)(?:,|\s)+(\d{1,3})(%?)(?:,|\s|\/)*(\d*(?:\.\d+)?)(%?)\s*\)?$/i', $value) === 1;
},
],
'validations' => [
'color' => function ($value) {
if (empty($value) === true) {
return true;
}

if (
$this->format === 'hex' &&
preg_match('/^#([\da-f]{3,4}){1,2}$/i', $value) !== 1
) {
if ($this->format === 'hex' && $this->isHex($value) === false) {
throw new InvalidArgumentException([
'key' => 'validation.color',
'data' => ['format' => 'hex']
]);
}

if (
$this->format === 'rgb' &&
preg_match('/^rgba?\(\s*(\d{1,3})(%?)(?:,|\s)+(\d{1,3})(%?)(?:,|\s)+(\d{1,3})(%?)(?:,|\s|\/)*(\d*(?:\.\d+)?)(%?)\s*\)?$/i', $value) !== 1
) {
if ($this->format === 'rgb' && $this->isRgb($value) === false) {
throw new InvalidArgumentException([
'key' => 'validation.color',
'data' => ['format' => 'rgb']
]);
}

if (
$this->format === 'hsl' &&
preg_match('/^hsla?\(\s*(\d{1,3}\.?\d*)(deg|rad|grad|turn)?(?:,|\s)+(\d{1,3})%(?:,|\s)+(\d{1,3})%(?:,|\s|\/)*(\d*(?:\.\d+)?)(%?)\s*\)?$/i', $value) !== 1
) {
if ($this->format === 'hsl' && $this->isHsl($value) === false) {
throw new InvalidArgumentException([
'key' => 'validation.color',
'data' => ['format' => 'hsl']
Expand Down
2 changes: 1 addition & 1 deletion config/fields/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
},
'form' => function (array $values = []) {
return new Form([
'fields' => $this->attrs['fields'],
'fields' => $this->attrs['fields'] ?? [],
'values' => $values,
'model' => $this->model
]);
Expand Down
2 changes: 1 addition & 1 deletion config/methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
try {
return Structure::factory(
Data::decode($field->value, 'yaml'),
['parent' => $field->parent()]
['parent' => $field->parent(), 'field' => $field]
);
} catch (Exception) {
$message = 'Invalid structure data for "' . $field->key() . '" field';
Expand Down
20 changes: 12 additions & 8 deletions config/sections/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'parent' => function () {
return $this->parentModel();
},
'files' => function () {
'models' => function () {
if ($this->query !== null) {
$files = $this->parent->query($this->query, Files::class) ?? new Files([]);
} else {
Expand Down Expand Up @@ -99,14 +99,17 @@

return $files;
},
'files' => function () {
return $this->models;
},
'data' => function () {
$data = [];

// the drag text needs to be absolute when the files come from
// a different parent model
$dragTextAbsolute = $this->model->is($this->parent) === false;

foreach ($this->files as $file) {
foreach ($this->models as $file) {
$panel = $file->panel();

$item = [
Expand Down Expand Up @@ -137,7 +140,7 @@
return $data;
},
'total' => function () {
return $this->files->pagination()->total();
return $this->models->pagination()->total();
},
'errors' => function () {
$errors = [];
Expand Down Expand Up @@ -191,13 +194,14 @@
'multiple' => $multiple,
'max' => $max,
'api' => $this->parent->apiUrl(true) . '/files',
'attributes' => array_filter([
'attributes' => [
// TODO: an edge issue that needs to be solved:
// if multiple users load the same section at the same time
// and upload a file, uploaded files have the same sort number
// if multiple users load the same section
// at the same time and upload a file,
// uploaded files have the same sort number
'sort' => $this->sortable === true ? $this->total + 1 : null,
'template' => $template
])
]
];
}
],
Expand All @@ -208,7 +212,7 @@
'options' => [
'accept' => $this->accept,
'apiUrl' => $this->parent->apiUrl(true),
'columns' => $this->columns,
'columns' => $this->columnsWithTypes(),
'empty' => $this->empty,
'headline' => $this->headline,
'help' => $this->help,
Expand Down
25 changes: 23 additions & 2 deletions config/sections/mixins/layout.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Kirby\Cms\ModelWithContent;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;

Expand Down Expand Up @@ -28,7 +29,7 @@
],
'computed' => [
'columns' => function () {
$columns = [];
$columns = [];

if ($this->layout !== 'table') {
return [];
Expand Down Expand Up @@ -94,7 +95,27 @@
},
],
'methods' => [
'columnsValues' => function (array $item, $model) {
'columnsWithTypes' => function () {
$columns = $this->columns;

// add the type to the columns for the table layout
if ($this->layout === 'table') {
$blueprint = $this->models->first()?->blueprint();

if ($blueprint === null) {
return $columns;
}

foreach ($columns as $columnName => $column) {
if ($id = $column['id'] ?? null) {
$columns[$columnName]['type'] ??= $blueprint->field($id)['type'] ?? null;
}
}
}

return $columns;
},
'columnsValues' => function (array $item, ModelWithContent $model) {
$item['title'] = [
// override toSafeString() coming from `$item`
// because the table cells don't use v-html
Expand Down
Loading

0 comments on commit 2965c31

Please sign in to comment.