From: Marcel Werk Date: Sat, 14 Dec 2024 13:40:51 +0000 (+0100) Subject: Change the definition of title columns X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6dd830ff083a9e9bd63e0786685465332036f01a;p=GitHub%2FWoltLab%2FWCF.git Change the definition of title columns --- diff --git a/wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php b/wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php index fcd41a4d21..8486986558 100644 --- a/wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php @@ -500,6 +500,28 @@ abstract class AbstractGridView EventHandler::getInstance()->fire($event); } + /** + * Validates the configuration of this grid view. + */ + protected function validate(): void + { + $titleColumn = null; + + foreach ($this->getColumns() as $column) { + if ($column->isTitleColumn()) { + if ($titleColumn !== null) { + throw new \InvalidArgumentException("More than one title column defined in grid view with id '{$this->getID()}'."); + } + + $titleColumn = $column; + } + } + + if ($titleColumn === null) { + throw new \InvalidArgumentException("Missing title column in grid view with id '{$this->getID()}'."); + } + } + /** * Returns the initialized event or null if there is no such event for this grid view. */ diff --git a/wcfsetup/install/files/lib/system/gridView/CronjobLogGridView.class.php b/wcfsetup/install/files/lib/system/gridView/CronjobLogGridView.class.php index 3c3c191a29..5a9e78e261 100644 --- a/wcfsetup/install/files/lib/system/gridView/CronjobLogGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/CronjobLogGridView.class.php @@ -14,7 +14,6 @@ use wcf\system\gridView\filter\TimeFilter; use wcf\system\gridView\renderer\DefaultColumnRenderer; use wcf\system\gridView\renderer\NumberColumnRenderer; use wcf\system\gridView\renderer\TimeColumnRenderer; -use wcf\system\gridView\renderer\TitleColumnRenderer; use wcf\system\WCF; use wcf\util\StringUtil; @@ -40,9 +39,10 @@ final class CronjobLogGridView extends DatabaseObjectListGridView GridViewColumn::for('cronjobID') ->label('wcf.acp.cronjob') ->sortable() + ->titleColumn() ->filter(new SelectFilter($availableCronjobs)) ->renderer([ - new class($availableCronjobs) extends TitleColumnRenderer { + new class($availableCronjobs) extends DefaultColumnRenderer { public function __construct(private readonly array $availableCronjobs) {} public function render(mixed $value, mixed $context = null): string diff --git a/wcfsetup/install/files/lib/system/gridView/DataSourceGridView.class.php b/wcfsetup/install/files/lib/system/gridView/DataSourceGridView.class.php index b606cab280..34a2ecaa9e 100644 --- a/wcfsetup/install/files/lib/system/gridView/DataSourceGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/DataSourceGridView.class.php @@ -63,6 +63,7 @@ abstract class DataSourceGridView extends AbstractGridView if (!isset($this->dataSource)) { $this->dataSource = $this->loadDataSource(); $this->applyFilters(); + $this->validate(); $this->fireInitializedEvent(); } diff --git a/wcfsetup/install/files/lib/system/gridView/DatabaseObjectListGridView.class.php b/wcfsetup/install/files/lib/system/gridView/DatabaseObjectListGridView.class.php index 28140d6891..55218b8cc0 100644 --- a/wcfsetup/install/files/lib/system/gridView/DatabaseObjectListGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/DatabaseObjectListGridView.class.php @@ -73,6 +73,7 @@ abstract class DatabaseObjectListGridView extends AbstractGridView '.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder(); } $this->applyFilters(); + $this->validate(); $this->fireInitializedEvent(); } diff --git a/wcfsetup/install/files/lib/system/gridView/ExceptionLogGridView.class.php b/wcfsetup/install/files/lib/system/gridView/ExceptionLogGridView.class.php index 13bf2f7298..8bf76a93a2 100644 --- a/wcfsetup/install/files/lib/system/gridView/ExceptionLogGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/ExceptionLogGridView.class.php @@ -8,7 +8,6 @@ use wcf\system\Regex; use wcf\system\gridView\filter\SelectFilter; use wcf\system\gridView\filter\TextFilter; use wcf\system\gridView\renderer\TimeColumnRenderer; -use wcf\system\gridView\renderer\TitleColumnRenderer; use wcf\system\WCF; use wcf\util\DirectoryUtil; use wcf\util\ExceptionLogUtil; @@ -31,7 +30,7 @@ final class ExceptionLogGridView extends DataSourceGridView GridViewColumn::for('message') ->label('wcf.acp.exceptionLog.exception.message') ->sortable() - ->renderer(new TitleColumnRenderer()), + ->titleColumn(), GridViewColumn::for('exceptionID') ->label('wcf.acp.exceptionLog.search.exceptionID') ->filter(new TextFilter()) diff --git a/wcfsetup/install/files/lib/system/gridView/GridViewColumn.class.php b/wcfsetup/install/files/lib/system/gridView/GridViewColumn.class.php index b80d13aa5a..cce1798024 100644 --- a/wcfsetup/install/files/lib/system/gridView/GridViewColumn.class.php +++ b/wcfsetup/install/files/lib/system/gridView/GridViewColumn.class.php @@ -7,7 +7,6 @@ use wcf\system\gridView\filter\IGridViewFilter; use wcf\system\gridView\renderer\DefaultColumnRenderer; use wcf\system\gridView\renderer\IColumnRenderer; use wcf\system\gridView\renderer\ILinkColumnRenderer; -use wcf\system\gridView\renderer\TitleColumnRenderer; use wcf\system\WCF; /** @@ -31,6 +30,7 @@ final class GridViewColumn private ?IGridViewFilter $filter = null; private bool $hidden = false; private bool $valueEncoding = true; + private bool $titleColumn = false; private function __construct(private readonly string $id) {} @@ -63,16 +63,24 @@ final class GridViewColumn */ public function getClasses(): string { + $classes = ''; + if ($this->getRenderers() === []) { - return self::getDefaultRenderer()->getClasses(); + $classes = self::getDefaultRenderer()->getClasses(); + } else { + $classes = \implode(' ', \array_map( + static function (IColumnRenderer $renderer) { + return $renderer->getClasses(); + }, + $this->getRenderers() + )); + } + + if ($this->isTitleColumn()) { + $classes .= ' gridView__column--title'; } - return \implode(' ', \array_map( - static function (IColumnRenderer $renderer) { - return $renderer->getClasses(); - }, - $this->getRenderers() - )); + return $classes; } /** @@ -185,17 +193,21 @@ final class GridViewColumn } /** - * Returns true if this column is a title column. + * Sets this column as the title column. */ - public function isTitleColumn(): bool + public function titleColumn(bool $titleColumn = true): static { - foreach ($this->getRenderers() as $renderer) { - if ($renderer instanceof TitleColumnRenderer) { - return true; - } - } + $this->titleColumn = $titleColumn; - return false; + return $this; + } + + /** + * Returns true if this column is the title column. + */ + public function isTitleColumn(): bool + { + return $this->titleColumn; } /** diff --git a/wcfsetup/install/files/lib/system/gridView/ModificationLogGridView.class.php b/wcfsetup/install/files/lib/system/gridView/ModificationLogGridView.class.php index e4fc88089e..a646b72445 100644 --- a/wcfsetup/install/files/lib/system/gridView/ModificationLogGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/ModificationLogGridView.class.php @@ -56,6 +56,7 @@ final class ModificationLogGridView extends DatabaseObjectListGridView ->filter(new TextFilter('modification_log.username')), GridViewColumn::for('action') ->label('wcf.acp.modificationLog.action') + ->titleColumn() ->renderer([ new class extends DefaultColumnRenderer { #[\Override] diff --git a/wcfsetup/install/files/lib/system/gridView/UserOptionGridView.class.php b/wcfsetup/install/files/lib/system/gridView/UserOptionGridView.class.php index 092228cc24..d4f32f3357 100644 --- a/wcfsetup/install/files/lib/system/gridView/UserOptionGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/UserOptionGridView.class.php @@ -13,7 +13,6 @@ use wcf\system\gridView\action\EditAction; use wcf\system\gridView\action\ToggleAction; use wcf\system\gridView\renderer\DefaultColumnRenderer; use wcf\system\gridView\renderer\NumberColumnRenderer; -use wcf\system\gridView\renderer\TitleColumnRenderer; use wcf\system\WCF; use wcf\util\StringUtil; @@ -37,8 +36,9 @@ final class UserOptionGridView extends DatabaseObjectListGridView GridViewColumn::for('optionName') ->label('wcf.global.name') ->sortable() + ->titleColumn() ->renderer([ - new class extends TitleColumnRenderer { + new class extends DefaultColumnRenderer { public function render(mixed $value, mixed $context = null): string { \assert($context instanceof UserOption); diff --git a/wcfsetup/install/files/lib/system/gridView/UserRankGridView.class.php b/wcfsetup/install/files/lib/system/gridView/UserRankGridView.class.php index a3e6256439..b588cfa783 100644 --- a/wcfsetup/install/files/lib/system/gridView/UserRankGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/UserRankGridView.class.php @@ -15,7 +15,6 @@ use wcf\system\gridView\filter\I18nTextFilter; use wcf\system\gridView\filter\SelectFilter; use wcf\system\gridView\renderer\DefaultColumnRenderer; use wcf\system\gridView\renderer\NumberColumnRenderer; -use wcf\system\gridView\renderer\TitleColumnRenderer; use wcf\system\WCF; use wcf\util\StringUtil; @@ -39,9 +38,10 @@ final class UserRankGridView extends DatabaseObjectListGridView GridViewColumn::for('rankTitle') ->label('wcf.acp.user.rank.title') ->sortable(true, 'rankTitleI18n') + ->titleColumn() ->filter(new I18nTextFilter()) ->renderer([ - new class extends TitleColumnRenderer { + new class extends DefaultColumnRenderer { public function render(mixed $value, mixed $context = null): string { \assert($context instanceof UserRank); diff --git a/wcfsetup/install/files/lib/system/gridView/renderer/TitleColumnRenderer.class.php b/wcfsetup/install/files/lib/system/gridView/renderer/TitleColumnRenderer.class.php deleted file mode 100644 index d120f58742..0000000000 --- a/wcfsetup/install/files/lib/system/gridView/renderer/TitleColumnRenderer.class.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @since 6.2 - */ -class TitleColumnRenderer extends DefaultColumnRenderer -{ - #[\Override] - public function getClasses(): string - { - return 'gridView__column--title'; - } -}