Skip to content

Commit 81221cd

Browse files
committed
1 parent 88cb70e commit 81221cd

File tree

7 files changed

+156
-37
lines changed

7 files changed

+156
-37
lines changed

com.woltlab.wcf/templates/shared_gridView.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@
112112
);
113113
});
114114
</script>
115-
{if $view->hasInteractions()}
116-
{unsafe:$view->renderInteractionInitialization()}
117-
{/if}
115+
{unsafe:$view->renderInteractionInitialization()}
118116
{if $view->hasBulkInteractions()}
119117
{unsafe:$view->renderBulkInteractionInitialization()}
120118
{/if}

wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract class AbstractGridView
5252
*/
5353
protected DatabaseObjectList $objectList;
5454

55-
private GridViewRowLink $rowLink;
55+
private IGridViewRowLink $rowLink;
5656
private int $rowsPerPage = 20;
5757
private string $baseUrl = '';
5858
private string $defaultSortField = '';
@@ -341,6 +341,11 @@ public function renderInteractionInitialization(): string
341341
));
342342
}
343343

344+
if (isset($this->rowLink)) {
345+
$code .= "\n";
346+
$code .= $this->rowLink->renderInitialization($this->getID() . '_table');
347+
}
348+
344349
return $code;
345350
}
346351

@@ -634,7 +639,7 @@ public function getParameters(): array
634639
/**
635640
* Adds the given row link to the grid view.
636641
*/
637-
public function addRowLink(GridViewRowLink $rowLink): void
642+
public function addRowLink(IGridViewRowLink $rowLink): void
638643
{
639644
$this->rowLink = $rowLink;
640645
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace wcf\system\gridView;
4+
5+
use wcf\data\DatabaseObject;
6+
7+
/**
8+
* Provides an abstract implementation of a grid view row link.
9+
*
10+
* @author Marcel Werk
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @since 6.2
14+
*/
15+
abstract class AbstractGridViewRowLink implements IGridViewRowLink
16+
{
17+
public function __construct(
18+
protected readonly ?\Closure $isAvailableCallback = null,
19+
) {}
20+
21+
#[\Override]
22+
public function renderInitialization(string $containerId): ?string
23+
{
24+
return null;
25+
}
26+
27+
#[\Override]
28+
public function isAvailable(DatabaseObject $row): bool
29+
{
30+
if ($this->isAvailableCallback === null) {
31+
return true;
32+
}
33+
34+
return ($this->isAvailableCallback)($row);
35+
}
36+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace wcf\system\gridView;
4+
5+
use wcf\data\DatabaseObject;
6+
use wcf\system\interaction\InteractionEffect;
7+
use wcf\util\StringUtil;
8+
9+
/**
10+
* Represents a row link that opens a form builder dialog.
11+
*
12+
* @author Marcel Werk
13+
* @copyright 2001-2025 WoltLab GmbH
14+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15+
* @since 6.2
16+
*/
17+
class FormBuilderDialogGridViewRowLink extends AbstractGridViewRowLink
18+
{
19+
public function __construct(
20+
private readonly string $identifier,
21+
private readonly string $endpoint,
22+
private readonly InteractionEffect $interactionEffect = InteractionEffect::ReloadItem,
23+
?\Closure $isAvailableCallback = null,
24+
) {
25+
parent::__construct($isAvailableCallback);
26+
}
27+
28+
#[\Override]
29+
public function render(mixed $value, DatabaseObject $row, bool $isPrimaryColumn = false): string
30+
{
31+
$identifier = StringUtil::encodeJS($this->identifier);
32+
$endpoint = StringUtil::encodeHTML(
33+
\sprintf($this->endpoint, $row->getObjectID())
34+
);
35+
$tabindex = $isPrimaryColumn ? '0' : '-1';
36+
37+
return <<<HTML
38+
<button
39+
type="button"
40+
data-interaction="{$identifier}"
41+
data-endpoint="{$endpoint}"
42+
data-interaction-effect="{$this->interactionEffect->toString()}"
43+
class="gridView__rowLink"
44+
tabindex="{$tabindex}"
45+
>
46+
{$value}
47+
</button>
48+
HTML;
49+
}
50+
51+
#[\Override]
52+
public function renderInitialization(string $containerId): ?string
53+
{
54+
$identifier = StringUtil::encodeJS($this->identifier);
55+
$containerId = StringUtil::encodeJS($containerId);
56+
57+
return <<<HTML
58+
<script data-relocate="true">
59+
require(['WoltLabSuite/Core/Component/Interaction/FormBuilderDialog'], ({ setup }) => {
60+
setup('{$identifier}', document.getElementById('{$containerId}'));
61+
});
62+
</script>
63+
HTML;
64+
}
65+
}

wcfsetup/install/files/lib/system/gridView/GridViewRowLink.class.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
use wcf\util\StringUtil;
1010

1111
/**
12-
* Represents a row link of a grid view.
12+
* Represents a row link in a grid view that uses a link.
1313
*
1414
* @author Marcel Werk
15-
* @copyright 2001-2024 WoltLab GmbH
15+
* @copyright 2001-2025 WoltLab GmbH
1616
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1717
* @since 6.2
1818
*/
19-
class GridViewRowLink
19+
class GridViewRowLink extends AbstractGridViewRowLink
2020
{
2121
/**
2222
* @param array<string, mixed> $parameters
@@ -26,12 +26,12 @@ public function __construct(
2626
private readonly array $parameters = [],
2727
private readonly string $cssClass = '',
2828
private readonly bool $isLinkableObject = false,
29-
private readonly ?\Closure $isAvailableCallback = null
30-
) {}
29+
?\Closure $isAvailableCallback = null
30+
) {
31+
parent::__construct($isAvailableCallback);
32+
}
3133

32-
/**
33-
* Renders the row link.
34-
*/
34+
#[\Override]
3535
public function render(mixed $value, DatabaseObject $row, bool $isPrimaryColumn = false): string
3636
{
3737
$href = '';
@@ -79,13 +79,4 @@ private function getLink(DatabaseObject $object): string
7979

8080
throw new \BadMethodCallException("GridViewRowLink expects object to be an implementation of ILinkableObject.");
8181
}
82-
83-
public function isAvailable(DatabaseObject $row): bool
84-
{
85-
if ($this->isAvailableCallback === null) {
86-
return true;
87-
}
88-
89-
return ($this->isAvailableCallback)($row);
90-
}
9182
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace wcf\system\gridView;
4+
5+
use wcf\data\DatabaseObject;
6+
7+
/**
8+
* Represents a row link of a grid view.
9+
*
10+
* @author Marcel Werk
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @since 6.2
14+
*/
15+
interface IGridViewRowLink
16+
{
17+
/**
18+
* Renders the row link.
19+
*/
20+
public function render(mixed $value, DatabaseObject $row, bool $isPrimaryColumn = false): string;
21+
22+
/**
23+
* Renders the initialization code for this row link.
24+
*/
25+
public function renderInitialization(string $containerId): ?string;
26+
27+
/**
28+
* Returns true if the row link is available for the given row.
29+
*/
30+
public function isAvailable(DatabaseObject $row): bool;
31+
}

wcfsetup/install/files/lib/system/gridView/admin/LanguageItemGridView.class.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
use wcf\data\language\category\LanguageCategoryList;
99
use wcf\data\language\item\LanguageItem;
1010
use wcf\data\language\item\LanguageItemList;
11-
use wcf\data\language\Language;
1211
use wcf\data\language\LanguageList;
1312
use wcf\event\gridView\admin\LanguageItemGridViewInitialized;
1413
use wcf\system\gridView\AbstractGridView;
14+
use wcf\system\gridView\FormBuilderDialogGridViewRowLink;
1515
use wcf\system\gridView\GridViewColumn;
1616
use wcf\system\gridView\renderer\AbstractColumnRenderer;
1717
use wcf\system\gridView\renderer\TruncatedTextColumnRenderer;
1818
use wcf\system\interaction\admin\LanguageItemInteractions;
19-
use wcf\system\interaction\Divider;
20-
use wcf\system\interaction\FormBuilderDialogInteraction;
2119
use wcf\system\request\LinkHandler;
2220
use wcf\system\view\filter\BooleanFilter;
2321
use wcf\system\view\filter\SelectFilter;
@@ -127,19 +125,14 @@ public function applyFilter(DatabaseObjectList $list, string $value): void
127125
},
128126
new BooleanFilter('isCustomLanguageItem', 'wcf.acp.language.item.isCustomLanguageItem'),
129127
]);
130-
$provider = new LanguageItemInteractions();
131-
$provider->addInteractions([
132-
new Divider(),
133-
new FormBuilderDialogInteraction(
134-
'edit',
135-
LinkHandler::getInstance()->getControllerLink(
136-
LanguageItemEditAction::class,
137-
['id' => '%s']
138-
),
139-
'wcf.global.button.edit'
128+
$this->setInteractionProvider(new LanguageItemInteractions());
129+
$this->addRowLink(new FormBuilderDialogGridViewRowLink(
130+
'edit',
131+
LinkHandler::getInstance()->getControllerLink(
132+
LanguageItemEditAction::class,
133+
['id' => '%s']
140134
)
141-
]);
142-
$this->setInteractionProvider($provider);
135+
));
143136
$this->setDefaultSortField('languageItem');
144137
}
145138

0 commit comments

Comments
 (0)