Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .tools/psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1863,9 +1863,6 @@
<InvalidArgument>
<code><![CDATA[['id' => $ArtSql->getValue('id'), 'startarticle' => '0', 'clang_id' => $clang]]]></code>
</InvalidArgument>
<InvalidArrayOffset>
<code><![CDATA[$templates[$templateKey]]]></code>
</InvalidArrayOffset>
<InvalidOperand>
<code><![CDATA[$fcat->getValue('path')]]></code>
<code><![CDATA[$tcat->getValue('path')]]></code>
Expand Down
Binary file modified .tools/visual-tests/screenshots/system_settings--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/system_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .tools/visual-tests/screenshots/system_settings_safemode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1302,10 +1302,8 @@ perm_options_linkmap[all_categories] = Alle Kategorien in der Linkmap anzeigen

system_setting_start_article_id = Startartikel
system_setting_notfound_article_id = Fehlerartikel
system_setting_default_template = Standardtemplate
system_setting_start_article_id_invalid = Ungültiger Startartikel!
system_setting_notfound_article_id_invalid = Ungültiger Fehlerartikel!
system_setting_default_template_invalid = Ungültiges Standardtemplate!

linkmap = Linkmap
linkmap_categories = Kategorien
Expand Down
2 changes: 0 additions & 2 deletions lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,8 @@ perm_options_linkmap[all_categories] = Show all categories in Linkmap

system_setting_start_article_id = Start article
system_setting_notfound_article_id = Not-found article
system_setting_default_template = Default template
system_setting_start_article_id_invalid = Invalid start article!
system_setting_notfound_article_id_invalid = Invalid not-found article!
system_setting_default_template_invalid = Invalid default template!

linkmap = Linkmap
linkmap_categories = Categories
Expand Down
30 changes: 0 additions & 30 deletions pages/system/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Redaxo\Core\Cache;
use Redaxo\Core\Content\Article;
use Redaxo\Core\Content\Template;
use Redaxo\Core\Core;
use Redaxo\Core\Database\Sql;
use Redaxo\Core\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -108,14 +107,6 @@
Core::setConfig($key, $value);
break;

case 'default_template':
$value = (string) $value;
if ('' !== $value && !Template::exists($value)) {
$error[] = I18n::msg('system_setting_default_template_invalid');
}
Core::setConfig('default_template', '' !== $value ? $value : null);
break;

case 'article_history':
case 'article_work_version':
$value = (bool) $value;
Expand Down Expand Up @@ -338,27 +329,6 @@
$field->setValue(Core::getConfig('notfound_article_id', 1));
$content .= $field->get();

$field = new SelectField();
$field->setAttribute('class', 'form-control selectpicker');
$field->setAttribute('name', 'settings[default_template]');
$field->setLabel(I18n::msg('system_setting_default_template'));
$select = $field->getSelect();
$select->setSize(1);
$defaultTemplate = Template::getDefaultKey();
if (null !== $defaultTemplate) {
$select->setSelected($defaultTemplate);
}

$templates = Template::getTemplatesForCategory(0);
if (empty($templates)) {
$select->addOption(I18n::msg('option_no_template'), '');
} else {
foreach ($templates as $key => $template) {
$select->addOption(I18n::translate($template->name), $key);
}
}
$content .= $field->get();

$field = new SelectField();
$field->setAttribute('class', 'form-control selectpicker');
$field->setAttribute('name', 'settings[article_history]');
Expand Down
16 changes: 8 additions & 8 deletions src/Content/CategoryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public static function addCategory($categoryId, array $data)
// $sql->setDebug();
$sql->setQuery('select clang_id,template from ' . Core::getTablePrefix() . 'article where id=? and startarticle=1', [$categoryId]);
for ($i = 0; $i < $sql->getRows(); $i++, $sql->next()) {
$startpageTemplates[(int) $sql->getValue('clang_id')] = $sql->getValue('template');
$template = (string) $sql->getValue('template');
if ('' !== $template) {
$startpageTemplates[(int) $sql->getValue('clang_id')] = $template;
}
}
}

Expand All @@ -78,15 +81,12 @@ public static function addCategory($categoryId, array $data)
// Kategorie in allen Sprachen anlegen
$AART = Sql::factory();
foreach (Language::getAllIds() as $key) {
$templateKey = Template::getDefaultKey();
if (isset($startpageTemplates[$key]) && '' != $startpageTemplates[$key]) {
$templateKey = $startpageTemplates[$key];
}
// Inherit the template from the start article of the respective language, otherwise use the default
$templateKey = $startpageTemplates[$key] ?? Template::getDefaultKey();

// Wenn Template nicht vorhanden, dann entweder erlaubtes nehmen
// oder leer setzen.
// Fall back to the first allowed template if the chosen one is not available in this category
if (null === $templateKey || !isset($templates[$templateKey])) {
$templateKey = count($templates) > 0 ? key($templates) : null;
$templateKey = array_key_first($templates);
}

$AART->setTable(Core::getTablePrefix() . 'article');
Expand Down
38 changes: 34 additions & 4 deletions src/Content/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,54 @@

namespace Redaxo\Core\Content;

use InvalidArgumentException;
use Redaxo\Core\ClassDiscovery;
use Redaxo\Core\Core;
use Redaxo\Core\Util\Type;

use function sprintf;

abstract class Template
{
/** @var array<string, self>|null */
private static ?array $instances = null;

/** @var class-string<self>|null */
private static ?string $defaultClass = null;

public function __construct(
/** Unique key, used as DB reference in rex_article.template. */
public readonly string $key,
public readonly string $name,
) {}

public static function getDefaultKey(): ?string
/**
* Sets the default template, used e.g. for new articles.
*
* Call this in your project's `boot()` method.
*
* @param class-string<self> $class
*/
final public static function setDefault(string $class): void
{
if (null === self::get($class)) {
throw new InvalidArgumentException(sprintf('"%s" is not a registered template.', $class));
}

self::$defaultClass = $class;
}

/**
* Returns the key of the default template.
*
* If no default has been set, the first available template is used.
* Returns `null` only when no templates exist at all.
*/
final public static function getDefaultKey(): ?string
{
return Type::nullOrString(Core::getConfig('default_template'));
if (null !== self::$defaultClass) {
return self::get(self::$defaultClass)?->key;
}

return array_key_first(self::getAll());
}

/**
Expand Down