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