Upgrade to 3.1.2

This commit is contained in:
Bastian Allgeier
2019-04-09 14:34:12 +02:00
parent 852a14595e
commit eb29ef6d6c
58 changed files with 535 additions and 258 deletions

View File

@@ -2,6 +2,7 @@
namespace Kirby\Cms;
use Kirby\Data\Data;
use Kirby\Exception\DuplicateException;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
@@ -9,6 +10,7 @@ use Kirby\Exception\LogicException;
use Kirby\Exception\PermissionException;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;
use Throwable;
/**
* The `$language` object represents
@@ -318,7 +320,11 @@ class Language extends Model
*/
public function pattern(): string
{
return $this->url;
if (empty($this->url) === true) {
return $this->code;
}
return trim($this->url, '/');
}
/**
@@ -339,13 +345,27 @@ class Language extends Model
*/
public function save(): self
{
$data = $this->toArray();
try {
$existingData = Data::read($this->root());
} catch (Throwable $e) {
$existingData = [];
}
unset($data['url']);
$props = [
'code' => $this->code(),
'default' => $this->isDefault(),
'direction' => $this->direction(),
'locale' => $this->locale(),
'name' => $this->name(),
'translations' => $this->translations(),
'url' => $this->url,
];
$export = '<?php' . PHP_EOL . PHP_EOL . 'return ' . var_export($data, true) . ';';
$data = array_merge($existingData, $props);
F::write($this->root(), $export);
ksort($data);
Data::write($this->root(), $data);
return $this;
}
@@ -416,7 +436,7 @@ class Language extends Model
*/
protected function setUrl(string $url = null): self
{
$this->url = $url !== null ? trim($url, '/') : $this->code;
$this->url = $url;
return $this;
}
@@ -455,7 +475,7 @@ class Language extends Model
*/
public function url(): string
{
return Url::to($this->url);
return Url::to($this->pattern());
}
/**