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.
*/
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;
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
if (!isset($this->dataSource)) {
$this->dataSource = $this->loadDataSource();
$this->applyFilters();
+ $this->validate();
$this->fireInitializedEvent();
}
'.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder();
}
$this->applyFilters();
+ $this->validate();
$this->fireInitializedEvent();
}
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;
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())
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;
/**
private ?IGridViewFilter $filter = null;
private bool $hidden = false;
private bool $valueEncoding = true;
+ private bool $titleColumn = false;
private function __construct(private readonly string $id) {}
*/
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;
}
/**
}
/**
- * 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;
}
/**
->filter(new TextFilter('modification_log.username')),
GridViewColumn::for('action')
->label('wcf.acp.modificationLog.action')
+ ->titleColumn()
->renderer([
new class extends DefaultColumnRenderer {
#[\Override]
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;
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);
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;
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);
+++ /dev/null
-<?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';
- }
-}