Upgrade to 3.8.0

This commit is contained in:
Bastian Allgeier
2022-10-06 10:11:54 +02:00
parent a9ed4e45ca
commit 7d168aae58
332 changed files with 26337 additions and 21977 deletions

View File

@@ -7,6 +7,8 @@ use Kirby\Data\Data;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Form\Form;
use Kirby\Toolkit\Str;
use Kirby\Uuid\Identifiable;
use Kirby\Uuid\Uuid;
use Throwable;
/**
@@ -18,7 +20,7 @@ use Throwable;
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
*/
abstract class ModelWithContent extends Model
abstract class ModelWithContent extends Model implements Identifiable
{
/**
* The content
@@ -85,7 +87,7 @@ abstract class ModelWithContent extends Model
{
// single language support
if ($this->kirby()->multilang() === false) {
if (is_a($this->content, 'Kirby\Cms\Content') === true) {
if ($this->content instanceof Content) {
return $this->content;
}
@@ -95,7 +97,10 @@ abstract class ModelWithContent extends Model
// multi language support
} else {
// only fetch from cache for the default language
if ($languageCode === null && is_a($this->content, 'Kirby\Cms\Content') === true) {
if (
$languageCode === null &&
$this->content instanceof Content
) {
return $this->content;
}
@@ -135,21 +140,21 @@ abstract class ModelWithContent extends Model
if ($force === true) {
if (empty($languageCode) === false) {
return $directory . '/' . $filename . '.' . $languageCode . '.' . $extension;
} else {
return $directory . '/' . $filename . '.' . $extension;
}
return $directory . '/' . $filename . '.' . $extension;
}
// add and validate the language code in multi language mode
if ($this->kirby()->multilang() === true) {
if ($language = $this->kirby()->languageCode($languageCode)) {
return $directory . '/' . $filename . '.' . $language . '.' . $extension;
} else {
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}
} else {
return $directory . '/' . $filename . '.' . $extension;
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
}
return $directory . '/' . $filename . '.' . $extension;
}
/**
@@ -165,11 +170,11 @@ abstract class ModelWithContent extends Model
$files[] = $this->contentFile($code);
}
return $files;
} else {
return [
$this->contentFile()
];
}
return [
$this->contentFile()
];
}
/**
@@ -194,7 +199,7 @@ abstract class ModelWithContent extends Model
* @internal
* @return string|null
*/
public function contentFileDirectory(): ?string
public function contentFileDirectory(): string|null
{
return $this->root();
}
@@ -346,15 +351,15 @@ abstract class ModelWithContent extends Model
try {
$result = Str::query($query, [
'kirby' => $this->kirby(),
'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(),
'site' => $this instanceof Site ? $this : $this->site(),
'model' => $this,
static::CLASS_ALIAS => $this
]);
} catch (Throwable $e) {
} catch (Throwable) {
return null;
}
if ($expect !== null && is_a($result, $expect) !== true) {
if ($expect !== null && $result instanceof $expect === false) {
return null;
}
@@ -372,7 +377,7 @@ abstract class ModelWithContent extends Model
{
try {
return Data::read($this->contentFile($languageCode));
} catch (Throwable $e) {
} catch (Throwable) {
return [];
}
}
@@ -382,7 +387,7 @@ abstract class ModelWithContent extends Model
*
* @return string|null
*/
abstract public function root(): ?string;
abstract public function root(): string|null;
/**
* Stores the content on disk
@@ -397,9 +402,9 @@ abstract class ModelWithContent extends Model
{
if ($this->kirby()->multilang() === true) {
return $this->saveTranslation($data, $languageCode, $overwrite);
} else {
return $this->saveContent($data, $overwrite);
}
return $this->saveContent($data, $overwrite);
}
/**
@@ -514,10 +519,11 @@ abstract class ModelWithContent extends Model
*
* @param string|null $template Template string or `null` to use the model ID
* @param array $data
* @param string $fallback Fallback for tokens in the template that cannot be replaced
* @param string|null $fallback Fallback for tokens in the template that cannot be replaced
* (`null` to keep the original token)
* @return string
*/
public function toSafeString(string $template = null, array $data = [], string $fallback = ''): string
public function toSafeString(string $template = null, array $data = [], string|null $fallback = ''): string
{
return $this->toString($template, $data, $fallback, 'safeTemplate');
}
@@ -527,11 +533,12 @@ abstract class ModelWithContent extends Model
*
* @param string|null $template Template string or `null` to use the model ID
* @param array $data
* @param string $fallback Fallback for tokens in the template that cannot be replaced
* @param string|null $fallback Fallback for tokens in the template that cannot be replaced
* (`null` to keep the original token)
* @param string $handler For internal use
* @return string
*/
public function toString(string $template = null, array $data = [], string $fallback = '', string $handler = 'template'): string
public function toString(string $template = null, array $data = [], string|null $fallback = '', string $handler = 'template'): string
{
if ($template === null) {
return $this->id() ?? '';
@@ -543,7 +550,7 @@ abstract class ModelWithContent extends Model
$result = Str::$handler($template, array_replace([
'kirby' => $this->kirby(),
'site' => is_a($this, 'Kirby\Cms\Site') ? $this : $this->site(),
'site' => $this instanceof Site ? $this : $this->site(),
'model' => $this,
static::CLASS_ALIAS => $this,
], $data), ['fallback' => $fallback]);
@@ -617,16 +624,19 @@ abstract class ModelWithContent extends Model
$arguments = [static::CLASS_ALIAS => $this, 'values' => $form->data(), 'strings' => $form->strings(), 'languageCode' => $languageCode];
return $this->commit('update', $arguments, function ($model, $values, $strings, $languageCode) {
// save updated values
$model = $model->save($strings, $languageCode, true);
// update model in siblings collection
$model->siblings()->add($model);
return $model;
return $model->save($strings, $languageCode, true);
});
}
/**
* Returns the model's UUID
* @since 3.8.0
*/
public function uuid(): Uuid
{
return Uuid::for($this);
}
/**
* Low level data writer method
* to store the given data on disk or anywhere else
@@ -643,59 +653,4 @@ abstract class ModelWithContent extends Model
$this->contentFileData($data, $languageCode)
);
}
/**
* Deprecated!
*/
/**
* Returns the panel icon definition
*
* @deprecated 3.6.0 Use `->panel()->image()` instead
* @todo Remove in 3.8.0
*
* @internal
* @param array|null $params
* @return array|null
* @codeCoverageIgnore
*/
public function panelIcon(array $params = null): ?array
{
Helpers::deprecated('Cms\ModelWithContent::panelIcon() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->image() instead.');
return $this->panel()->image($params);
}
/**
* @deprecated 3.6.0 Use `->panel()->image()` instead
* @todo Remove in 3.8.0
*
* @internal
* @param string|array|false|null $settings
* @return array|null
* @codeCoverageIgnore
*/
public function panelImage($settings = null): ?array
{
Helpers::deprecated('Cms\ModelWithContent::panelImage() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->image() instead.');
return $this->panel()->image($settings);
}
/**
* Returns an array of all actions
* that can be performed in the Panel
* This also checks for the lock status
*
* @deprecated 3.6.0 Use `->panel()->options()` instead
* @todo Remove in 3.8.0
*
* @param array $unlock An array of options that will be force-unlocked
* @return array
* @codeCoverageIgnore
*/
public function panelOptions(array $unlock = []): array
{
Helpers::deprecated('Cms\ModelWithContent::panelOptions() has been deprecated and will be removed in Kirby 3.8.0. Use $model->panel()->options() instead.');
return $this->panel()->options($unlock);
}
}