Update Composer packages

This commit is contained in:
Paul Nicoué 2023-06-01 16:54:20 +02:00
parent 76a5c7ea8b
commit 9252d9ce90
32 changed files with 906 additions and 114 deletions

View file

@ -555,10 +555,8 @@ class App
/**
* Returns the default language object
*
* @return \Kirby\Cms\Language|null
*/
public function defaultLanguage()
public function defaultLanguage(): Language|null
{
return $this->defaultLanguage ??= $this->languages()->default();
}
@ -577,22 +575,21 @@ class App
/**
* Detect the preferred language from the visitor object
*
* @return \Kirby\Cms\Language
*/
public function detectedLanguage()
public function detectedLanguage(): Language|null
{
$languages = $this->languages();
$visitor = $this->visitor();
foreach ($visitor->acceptedLanguages() as $lang) {
if ($language = $languages->findBy('locale', $lang->locale(LC_ALL))) {
foreach ($visitor->acceptedLanguages() as $acceptedLang) {
$closure = fn ($language) => $language->locale(LC_ALL) === $acceptedLang->locale();
if ($language = $languages->filter($closure)?->first()) {
return $language;
}
}
foreach ($visitor->acceptedLanguages() as $lang) {
if ($language = $languages->findBy('code', $lang->code())) {
foreach ($visitor->acceptedLanguages() as $acceptedLang) {
if ($language = $languages->findBy('code', $acceptedLang->code())) {
return $language;
}
}

View file

@ -25,6 +25,13 @@ class Blocks extends Items
{
public const ITEM_CLASS = Block::class;
/**
* All registered blocks methods
*
* @var array
*/
public static $methods = [];
/**
* Return HTML when the collection is
* converted to a string

View file

@ -459,10 +459,19 @@ class Blueprint
// groups don't need all the crap
if ($type === 'group') {
$fields = $props['fields'];
if (isset($props['when']) === true) {
$fields = array_map(
fn ($field) => array_replace_recursive(['when' => $props['when']], $field),
$fields
);
}
return [
'fields' => $props['fields'],
'fields' => $fields,
'name' => $name,
'type' => $type,
'type' => $type
];
}

View file

@ -21,6 +21,13 @@ class Fieldsets extends Items
{
public const ITEM_CLASS = Fieldset::class;
/**
* All registered fieldsets methods
*
* @var array
*/
public static $methods = [];
protected static function createFieldsets($params)
{
$fieldsets = [];

View file

@ -172,15 +172,21 @@ class File extends ModelWithContent
* other content.
*
* @internal
* @param array $data
* @param string|null $languageCode
* @return array
*/
public function contentFileData(array $data, string $languageCode = null): array
{
return A::append($data, [
'template' => $data['template'] ?? $this->template(),
]);
public function contentFileData(
array $data,
string $languageCode = null
): array {
// only add the template in, if the $data array
// doesn't explicitly unsets it
if (
array_key_exists('template', $data) === false &&
$template = $this->template()
) {
$data['template'] = $template;
}
return $data;
}
/**

View file

@ -21,6 +21,13 @@ class Items extends Collection
protected Field|null $field;
/**
* All registered items methods
*
* @var array
*/
public static $methods = [];
/**
* @var array
*/

View file

@ -16,6 +16,13 @@ use Kirby\Filesystem\F;
*/
class Languages extends Collection
{
/**
* All registered languages methods
*
* @var array
*/
public static $methods = [];
/**
* Creates a new collection with the given language objects
*

View file

@ -15,4 +15,11 @@ namespace Kirby\Cms;
class LayoutColumns extends Items
{
public const ITEM_CLASS = LayoutColumn::class;
/**
* All registered layout columns methods
*
* @var array
*/
public static $methods = [];
}

View file

@ -20,6 +20,13 @@ class Layouts extends Items
{
public const ITEM_CLASS = Layout::class;
/**
* All registered layouts methods
*
* @var array
*/
public static $methods = [];
public static function factory(array $items = null, array $params = [])
{
$first = $items[0] ?? [];

View file

@ -536,29 +536,43 @@ trait PageActions
// create a temporary page object
$page = Page::factory($props);
// always create pages in the default language
if ($page->kirby()->multilang() === true) {
$languageCode = $page->kirby()->defaultLanguage()->code();
} else {
$languageCode = null;
}
// create a form for the page
$form = Form::for($page, ['values' => $props['content']]);
// use always default language to fill form with default values
$form = Form::for(
$page,
[
'language' => $languageCode,
'values' => $props['content']
]
);
// inject the content
$page = $page->clone(['content' => $form->strings(true)]);
// run the hooks and creation action
$page = $page->commit('create', ['page' => $page, 'input' => $props], function ($page, $props) {
// always create pages in the default language
if ($page->kirby()->multilang() === true) {
$languageCode = $page->kirby()->defaultLanguage()->code();
} else {
$languageCode = null;
$page = $page->commit(
'create',
[
'page' => $page,
'input' => $props
],
function ($page, $props) use ($languageCode) {
// write the content file
$page = $page->save($page->content()->toArray(), $languageCode);
// flush the parent cache to get children and drafts right
static::updateParentCollections($page, 'append');
return $page;
}
// write the content file
$page = $page->save($page->content()->toArray(), $languageCode);
// flush the parent cache to get children and drafts right
static::updateParentCollections($page, 'append');
return $page;
});
);
// publish the new page if a number is given
if (isset($props['num']) === true) {

View file

@ -18,6 +18,13 @@ namespace Kirby\Cms;
*/
class Roles extends Collection
{
/**
* All registered roles methods
*
* @var array
*/
public static $methods = [];
/**
* Returns a filtered list of all
* roles that can be created by the

View file

@ -20,6 +20,13 @@ use Kirby\Exception\InvalidArgumentException;
*/
class Structure extends Collection
{
/**
* All registered structure methods
*
* @var array
*/
public static $methods = [];
/**
* Creates a new Collection with the given objects
*

View file

@ -19,6 +19,13 @@ use Kirby\Filesystem\F;
*/
class Translations extends Collection
{
/**
* All registered translations methods
*
* @var array
*/
public static $methods = [];
/**
* @param string $code
* @return void