Update Composer packages
This commit is contained in:
parent
0320235f6c
commit
a8b68fb61b
378 changed files with 28466 additions and 28852 deletions
|
@ -7,6 +7,9 @@ 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 Kirby\Uuid\Uuids;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
|
@ -18,7 +21,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,35 +88,39 @@ 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;
|
||||
}
|
||||
|
||||
// don't normalize field keys (already handled by the `Data` class)
|
||||
return $this->content = new Content($this->readContent(), $this, false);
|
||||
|
||||
// multi language support
|
||||
} else {
|
||||
// only fetch from cache for the default language
|
||||
if ($languageCode === null && is_a($this->content, 'Kirby\Cms\Content') === true) {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
// get the translation by code
|
||||
if ($translation = $this->translation($languageCode)) {
|
||||
// don't normalize field keys (already handled by the `ContentTranslation` class)
|
||||
$content = new Content($translation->content(), $this, false);
|
||||
} else {
|
||||
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
|
||||
}
|
||||
|
||||
// only store the content for the current language
|
||||
if ($languageCode === null) {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
// get the targeted language
|
||||
$language = $this->kirby()->language($languageCode);
|
||||
|
||||
// stop if the language does not exist
|
||||
if ($language === null) {
|
||||
throw new InvalidArgumentException('Invalid language: ' . $languageCode);
|
||||
}
|
||||
|
||||
// only fetch from cache for the current language
|
||||
if ($languageCode === null && $this->content instanceof Content) {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
// get the translation by code
|
||||
$translation = $this->translation($language->code());
|
||||
|
||||
// don't normalize field keys (already handled by the `ContentTranslation` class)
|
||||
$content = new Content($translation->content(), $this, false);
|
||||
|
||||
// only store the content for the current language
|
||||
if ($languageCode === null) {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,21 +142,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 +172,11 @@ abstract class ModelWithContent extends Model
|
|||
$files[] = $this->contentFile($code);
|
||||
}
|
||||
return $files;
|
||||
} else {
|
||||
return [
|
||||
$this->contentFile()
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
$this->contentFile()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +201,7 @@ abstract class ModelWithContent extends Model
|
|||
* @internal
|
||||
* @return string|null
|
||||
*/
|
||||
public function contentFileDirectory(): ?string
|
||||
public function contentFileDirectory(): string|null
|
||||
{
|
||||
return $this->root();
|
||||
}
|
||||
|
@ -346,15 +353,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;
|
||||
}
|
||||
|
||||
|
@ -370,11 +377,16 @@ abstract class ModelWithContent extends Model
|
|||
*/
|
||||
public function readContent(string $languageCode = null): array
|
||||
{
|
||||
try {
|
||||
return Data::read($this->contentFile($languageCode));
|
||||
} catch (Throwable $e) {
|
||||
$file = $this->contentFile($languageCode);
|
||||
|
||||
// only if the content file really does not exist, it's ok
|
||||
// to return empty content. Otherwise this could lead to
|
||||
// content loss in case of file reading issues
|
||||
if (file_exists($file) === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Data::read($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -382,7 +394,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 +409,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -457,6 +469,11 @@ abstract class ModelWithContent extends Model
|
|||
}
|
||||
}
|
||||
|
||||
// remove UUID for non-default languages
|
||||
if (Uuids::enabled() === true && isset($content['uuid']) === true) {
|
||||
$content['uuid'] = null;
|
||||
}
|
||||
|
||||
// merge the translation with the new data
|
||||
$translation->update($content, true);
|
||||
}
|
||||
|
@ -514,10 +531,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 +545,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 +562,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]);
|
||||
|
@ -560,7 +579,11 @@ abstract class ModelWithContent extends Model
|
|||
*/
|
||||
public function translation(string $languageCode = null)
|
||||
{
|
||||
return $this->translations()->find($languageCode ?? $this->kirby()->language()->code());
|
||||
if ($language = $this->kirby()->language($languageCode)) {
|
||||
return $this->translations()->find($language->code());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -617,16 +640,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|null
|
||||
{
|
||||
return Uuid::for($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level data writer method
|
||||
* to store the given data on disk or anywhere else
|
||||
|
@ -643,59 +669,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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue