Skip to content

Commit 09f9374

Browse files
authored
Merge pull request #6302 from WoltLab/6.2-interaction-button
Allow the usage of the interaction context menu as a content interaction button
2 parents 5056380 + cf97c1d commit 09f9374

11 files changed

Lines changed: 132 additions & 71 deletions

com.woltlab.wcf/templates/shared_standaloneInteractionButton.tpl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
<div class="dropdown" id="{$containerID}">
2-
<button type="button" class="button dropdownToggle" aria-label="{lang}wcf.global.button.more{/lang}">
3-
{icon name='ellipsis-vertical'}
1+
<div class="dropdown {$cssClassName}" id="{$containerID}">
2+
<button
3+
type="button"
4+
class="button dropdownToggle {$buttonCssClassName}"
5+
{if !$label}aria-label="{lang}wcf.global.button.more{/lang}"{/if}
6+
>
7+
{icon name=$icon}
8+
{if $label}
9+
<span>{$label}</span>
10+
{/if}
411
</button>
512

613
<ul class="dropdownMenu">

wcfsetup/install/files/lib/acp/form/StyleEditForm.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use wcf\system\file\upload\UploadFile;
1313
use wcf\system\file\upload\UploadHandler;
1414
use wcf\system\interaction\admin\StyleInteractions;
15-
use wcf\system\interaction\StandaloneInteractionContextMenuView;
15+
use wcf\system\interaction\StandaloneInteractionContextMenuComponent;
1616
use wcf\system\language\I18nHandler;
1717
use wcf\system\request\LinkHandler;
1818
use wcf\system\style\StyleCompiler;
@@ -453,7 +453,7 @@ public function assignVariables()
453453
'style' => $this->style,
454454
'styleID' => $this->styleID,
455455
'isDarkMode' => $this->isDarkMode,
456-
'interactionContextMenu' => new StandaloneInteractionContextMenuView(
456+
'interactionContextMenu' => new StandaloneInteractionContextMenuComponent(
457457
new StyleInteractions(),
458458
$this->style,
459459
LinkHandler::getInstance()->getControllerLink(StyleListPage::class)

wcfsetup/install/files/lib/acp/form/UserRankEditForm.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use wcf\http\Helper;
99
use wcf\system\exception\IllegalLinkException;
1010
use wcf\system\interaction\admin\UserRankInteractions;
11-
use wcf\system\interaction\StandaloneInteractionContextMenuView;
11+
use wcf\system\interaction\StandaloneInteractionContextMenuComponent;
1212
use wcf\system\request\LinkHandler;
1313
use wcf\system\WCF;
1414

@@ -66,7 +66,7 @@ public function assignVariables()
6666
parent::assignVariables();
6767

6868
WCF::getTPL()->assign([
69-
'interactionContextMenu' => new StandaloneInteractionContextMenuView(
69+
'interactionContextMenu' => new StandaloneInteractionContextMenuComponent(
7070
new UserRankInteractions(),
7171
$this->formObject,
7272
LinkHandler::getInstance()->getControllerLink(UserRankListPage::class)

wcfsetup/install/files/lib/system/endpoint/controller/core/interactions/GetBulkContextMenuOptions.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use wcf\system\endpoint\IController;
1111
use wcf\system\endpoint\PostRequest;
1212
use wcf\system\exception\UserInputException;
13-
use wcf\system\interaction\bulk\BulkInteractionContextMenuView;
13+
use wcf\system\interaction\bulk\BulkInteractionContextMenuComponent;
1414
use wcf\system\interaction\bulk\IBulkInteractionProvider;
1515

1616
/**
@@ -42,10 +42,10 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
4242
$list->setObjectIDs($parameters->objectIDs);
4343
$list->readObjects();
4444

45-
$view = new BulkInteractionContextMenuView($provider);
45+
$component = new BulkInteractionContextMenuComponent($provider);
4646

4747
return new JsonResponse([
48-
'template' => $view->renderContextMenuOptions($list->getObjects()),
48+
'template' => $component->renderContextMenuOptions($list->getObjects()),
4949
]);
5050
}
5151
}

wcfsetup/install/files/lib/system/endpoint/controller/core/interactions/GetContextMenuOptions.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use wcf\system\endpoint\IController;
1212
use wcf\system\exception\UserInputException;
1313
use wcf\system\interaction\IInteractionProvider;
14-
use wcf\system\interaction\InteractionContextMenuView;
14+
use wcf\system\interaction\InteractionContextMenuComponent;
1515

1616
/**
1717
* Retrieves the options for an interaction context menu.
@@ -40,10 +40,10 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
4040
$object = new ($provider->getObjectClassName())($parameters->objectID);
4141
\assert($object instanceof DatabaseObject);
4242

43-
$view = new InteractionContextMenuView($provider);
43+
$contextMenu = new InteractionContextMenuComponent($provider);
4444

4545
return new JsonResponse([
46-
'template' => $view->renderContextMenuOptions($object),
46+
'template' => $contextMenu->renderContextMenuOptions($object),
4747
]);
4848
}
4949
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use wcf\system\interaction\bulk\IBulkInteractionProvider;
1212
use wcf\system\interaction\IInteraction;
1313
use wcf\system\interaction\IInteractionProvider;
14-
use wcf\system\interaction\InteractionContextMenuView;
14+
use wcf\system\interaction\InteractionContextMenuComponent;
1515
use wcf\system\request\LinkHandler;
1616
use wcf\system\WCF;
1717
use wcf\util\StringUtil;
@@ -64,7 +64,7 @@ abstract class AbstractGridView
6464
private string|int|null $objectIDFilter = null;
6565
private ?IInteractionProvider $interactionProvider = null;
6666
private ?IBulkInteractionProvider $bulkInteractionProvider = null;
67-
private InteractionContextMenuView $interactionContextMenuView;
67+
private InteractionContextMenuComponent $interactionContextMenuComponent;
6868

6969
/**
7070
* Adds a new column to the grid view.
@@ -308,17 +308,17 @@ public function renderColumn(GridViewColumn $column, DatabaseObject $row): strin
308308
/**
309309
* Returns the view of the interaction context menu.
310310
*/
311-
public function getInteractionContextMenuView(): InteractionContextMenuView
311+
public function getInteractionContextMenuComponent(): InteractionContextMenuComponent
312312
{
313313
if ($this->interactionProvider === null) {
314314
throw new \BadMethodCallException("Missing interaction provider.");
315315
}
316316

317-
if (!isset($this->interactionContextMenuView)) {
318-
$this->interactionContextMenuView = new InteractionContextMenuView($this->interactionProvider);
317+
if (!isset($this->interactionContextMenuComponent)) {
318+
$this->interactionContextMenuComponent = new InteractionContextMenuComponent($this->interactionProvider);
319319
}
320320

321-
return $this->interactionContextMenuView;
321+
return $this->interactionContextMenuComponent;
322322
}
323323

324324
/**
@@ -328,7 +328,7 @@ public function renderInteractionInitialization(): string
328328
{
329329
$code = '';
330330
if ($this->interactionProvider !== null) {
331-
$code = $this->getInteractionContextMenuView()->renderInitialization($this->getID() . '_table');
331+
$code = $this->getInteractionContextMenuComponent()->renderInitialization($this->getID() . '_table');
332332
}
333333

334334
if ($this->quickInteractions !== []) {
@@ -368,7 +368,7 @@ public function renderInteractionContextMenuButton(DatabaseObject $row): string
368368
return '';
369369
}
370370

371-
return $this->getInteractionContextMenuView()->renderButton($row);
371+
return $this->getInteractionContextMenuComponent()->renderButton($row);
372372
}
373373

374374
/**

wcfsetup/install/files/lib/system/interaction/InteractionContextMenuView.class.php renamed to wcfsetup/install/files/lib/system/interaction/InteractionContextMenuComponent.class.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
use wcf\data\DatabaseObject;
66
use wcf\system\WCF;
77

8-
class InteractionContextMenuView
8+
/**
9+
* Represents the component of an interaction content menu.
10+
*
11+
* @author Marcel Werk
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
15+
*/
16+
class InteractionContextMenuComponent
917
{
1018
public function __construct(
1119
protected readonly IInteractionProvider $provider
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace wcf\system\interaction;
4+
5+
use wcf\data\DatabaseObject;
6+
use wcf\system\WCF;
7+
8+
/**
9+
* Represents the component of a standalone button for an interaction content menu.
10+
*
11+
* @author Marcel Werk
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
15+
*/
16+
class StandaloneInteractionContextMenuComponent extends InteractionContextMenuComponent
17+
{
18+
public function __construct(
19+
IInteractionProvider $provider,
20+
protected readonly DatabaseObject $object,
21+
protected readonly string $redirectUrl,
22+
protected readonly string $label = '',
23+
protected readonly string $icon = 'ellipsis-vertical',
24+
protected readonly string $cssClassName = '',
25+
protected readonly string $buttonCssClassName = ''
26+
) {
27+
parent::__construct($provider);
28+
}
29+
30+
public function render(): string
31+
{
32+
$contextMenuOptions = $this->renderContextMenuOptions($this->object);
33+
if (!$contextMenuOptions) {
34+
return '';
35+
}
36+
37+
return WCF::getTPL()->render(
38+
'wcf',
39+
'shared_standaloneInteractionButton',
40+
[
41+
'contextMenuOptions' => $contextMenuOptions,
42+
'initializationCode' => $this->renderInitialization($this->getContainerID()),
43+
'containerID' => $this->getContainerID(),
44+
'providerClassName' => \get_class($this->provider),
45+
'objectID' => $this->object->getObjectID(),
46+
'redirectUrl' => $this->redirectUrl,
47+
'label' => $this->label,
48+
'icon' => $this->icon,
49+
'cssClassName' => $this->cssClassName,
50+
'buttonCssClassName' => $this->buttonCssClassName,
51+
],
52+
);
53+
}
54+
55+
public function getContainerID(): string
56+
{
57+
$classNamePieces = \explode('\\', \get_class($this->object));
58+
59+
return \implode('-', $classNamePieces) . '-' . $this->object->getObjectID();
60+
}
61+
62+
public static function forContentHeaderButton(
63+
IInteractionProvider $provider,
64+
DatabaseObject $object,
65+
string $redirectUrl,
66+
): self {
67+
return new self($provider, $object, $redirectUrl, icon: 'ellipsis-vertical');
68+
}
69+
70+
public static function forContentInteractionButton(
71+
IInteractionProvider $provider,
72+
DatabaseObject $object,
73+
string $redirectUrl,
74+
string $label,
75+
): self {
76+
return new self($provider, $object, $redirectUrl, $label, 'pencil', 'contentInteractionButton', 'small');
77+
}
78+
}

wcfsetup/install/files/lib/system/interaction/StandaloneInteractionContextMenuView.class.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

wcfsetup/install/files/lib/system/interaction/bulk/BulkInteractionContextMenuView.class.php renamed to wcfsetup/install/files/lib/system/interaction/bulk/BulkInteractionContextMenuComponent.class.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
use wcf\system\interaction\Divider;
77
use wcf\system\WCF;
88

9-
class BulkInteractionContextMenuView
9+
/**
10+
* Represents the component of an bulk interaction content menu.
11+
*
12+
* @author Olaf Braun
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 BulkInteractionContextMenuComponent
1018
{
1119
public function __construct(
1220
protected readonly IBulkInteractionProvider $provider

0 commit comments

Comments
 (0)