Change the definition of title columns
authorMarcel Werk <burntime@woltlab.com>
Sat, 14 Dec 2024 13:40:51 +0000 (14:40 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 14 Dec 2024 13:40:51 +0000 (14:40 +0100)
wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php
wcfsetup/install/files/lib/system/gridView/CronjobLogGridView.class.php
wcfsetup/install/files/lib/system/gridView/DataSourceGridView.class.php
wcfsetup/install/files/lib/system/gridView/DatabaseObjectListGridView.class.php
wcfsetup/install/files/lib/system/gridView/ExceptionLogGridView.class.php
wcfsetup/install/files/lib/system/gridView/GridViewColumn.class.php
wcfsetup/install/files/lib/system/gridView/ModificationLogGridView.class.php
wcfsetup/install/files/lib/system/gridView/UserOptionGridView.class.php
wcfsetup/install/files/lib/system/gridView/UserRankGridView.class.php
wcfsetup/install/files/lib/system/gridView/renderer/TitleColumnRenderer.class.php [deleted file]

index fcd41a4d21a4d0cc1f4f9e2fe4c9380cad498158..8486986558447566c0849165647ea6b4796fb5bd 100644 (file)
@@ -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.
      */
index 3c3c191a29ff98549cc794f15a8a69682f6646e2..5a9e78e261defe5007417af9fba3f2f6fdba84a9 100644 (file)
@@ -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
index b606cab2802a12d0db0c36a65806a582b779f134..34a2ecaa9edb8fe76f7e4825f1e29477c8690c99 100644 (file)
@@ -63,6 +63,7 @@ abstract class DataSourceGridView extends AbstractGridView
         if (!isset($this->dataSource)) {
             $this->dataSource = $this->loadDataSource();
             $this->applyFilters();
+            $this->validate();
             $this->fireInitializedEvent();
         }
 
index 28140d6891a637d3b843c1cfb31e806e1f18db05..55218b8cc02e98ac7fcfb200015fc09001c4298f 100644 (file)
@@ -73,6 +73,7 @@ abstract class DatabaseObjectListGridView extends AbstractGridView
                 '.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder();
         }
         $this->applyFilters();
+        $this->validate();
         $this->fireInitializedEvent();
     }
 
index 13bf2f72980bf748cb0a79f80e467c85c55f209d..8bf76a93a2017ad63e550e249834a4fe2d24f417 100644 (file)
@@ -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())
index b80d13aa5aa54fa6da7cbdf50b32e74ac2874b1d..cce1798024714a6a458819b07f873e7682a40a13 100644 (file)
@@ -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;
     }
 
     /**
index e4fc88089e9795ac72e89e63bb068be772f07943..a646b724451032ee796a2867a1e6fce1e2b509e0 100644 (file)
@@ -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]
index 092228cc24a93c54a45496056ab30828c13a230f..d4f32f3357e7fca7299d06c447aa7d609aa9bec7 100644 (file)
@@ -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);
index a3e62564394202fff389fba308954561f1c36df5..b588cfa783e7a310dd5c6d342d550d8715be7cb2 100644 (file)
@@ -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 (file)
index d120f58..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-namespace wcf\system\gridView\renderer;
-
-/**
- * Formats the content of a column as a title.
- *
- * @author      Marcel Werk
- * @copyright   2001-2024 WoltLab GmbH
- * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @since       6.2
- */
-class TitleColumnRenderer extends DefaultColumnRenderer
-{
-    #[\Override]
-    public function getClasses(): string
-    {
-        return 'gridView__column--title';
-    }
-}