diff --git a/src/Cms/Find.php b/src/Cms/Find.php index f7a6983d38..aab3879462 100644 --- a/src/Cms/Find.php +++ b/src/Cms/Find.php @@ -176,7 +176,7 @@ public static function user(string|null $id = null): User|null return $user; } - throw new NotFoundException([ + throw new NotFoundException( key: 'user.notFound', data: ['name' => $id] ); diff --git a/src/Cms/Language.php b/src/Cms/Language.php index 54fddf0045..94fb197865 100644 --- a/src/Cms/Language.php +++ b/src/Cms/Language.php @@ -6,6 +6,7 @@ use Kirby\Exception\Exception; use Kirby\Exception\InvalidArgumentException; use Kirby\Exception\NotFoundException; +use Kirby\Exception\PermissionException; use Kirby\Filesystem\F; use Kirby\Toolkit\Locale; use Kirby\Toolkit\Str; @@ -591,62 +592,62 @@ public function update(array|null $props = null): static throw new PermissionException(key: 'language.update.permission'); } - $kirby = App::instance(); - - // don't change the language code - unset($props['code']); - - // make sure the slug is nice and clean - $props['slug'] = Str::slug($props['slug'] ?? null); - - // trigger before hook - $language = $kirby->apply( - 'language.update:before', - [ - 'language' => $this, - 'input' => $props - ], - 'language' - ); - - // updated language object - $language = $language->clone($props); - - if (isset($props['translations']) === true) { - $language->translations = $props['translations']; - } - - // validate the language rules after before hook was applied - LanguageRules::update($language, $this); - - // if language just got promoted to be the new default languageā€¦ - if ($this->isDefault() === false && $language->isDefault() === true) { - // convert the current default to a non-default language - $previous = $kirby->defaultLanguage()?->clone(['default' => false])->save(); - $kirby->languages(false)->set($previous->code(), $previous); - - foreach ($kirby->models() as $model) { - $model->storage()->touchLanguage($this); - } - } - - $language = $language->save(); - - // make sure the language is also updated in the languages collection - $kirby->languages(false)->set($language->code(), $language); - - // trigger after hook - $language = $kirby->apply( - 'language.update:after', - [ - 'newLanguage' => $language, - 'oldLanguage' => $this, - 'input' => $props - ], - 'newLanguage' - ); - - return $language; + $kirby = App::instance(); + + // don't change the language code + unset($props['code']); + + // make sure the slug is nice and clean + $props['slug'] = Str::slug($props['slug'] ?? null); + + // trigger before hook + $language = $kirby->apply( + 'language.update:before', + [ + 'language' => $this, + 'input' => $props + ], + 'language' + ); + + // updated language object + $language = $language->clone($props); + + if (isset($props['translations']) === true) { + $language->translations = $props['translations']; + } + + // validate the language rules after before hook was applied + LanguageRules::update($language, $this); + + // if language just got promoted to be the new default languageā€¦ + if ($this->isDefault() === false && $language->isDefault() === true) { + // convert the current default to a non-default language + $previous = $kirby->defaultLanguage()?->clone(['default' => false])->save(); + $kirby->languages(false)->set($previous->code(), $previous); + + foreach ($kirby->models() as $model) { + $model->storage()->touchLanguage($this); + } + } + + $language = $language->save(); + + // make sure the language is also updated in the languages collection + $kirby->languages(false)->set($language->code(), $language); + + // trigger after hook + $language = $kirby->apply( + 'language.update:after', + [ + 'newLanguage' => $language, + 'oldLanguage' => $this, + 'input' => $props + ], + 'newLanguage' + ); + + return $language; } /**