-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathBulkFormBuilderDialogInteraction.class.php
More file actions
72 lines (64 loc) · 2.25 KB
/
BulkFormBuilderDialogInteraction.class.php
File metadata and controls
72 lines (64 loc) · 2.25 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
<?php
namespace wcf\system\interaction\bulk;
use wcf\data\DatabaseObject;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\JSON;
use wcf\util\StringUtil;
/**
* Represents a bulk interaction that calls a form builder action.
*
* @author Olaf Braun
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
class BulkFormBuilderDialogInteraction extends AbstractBulkInteraction
{
public function __construct(
string $identifier,
protected readonly string $controller,
protected readonly string | \Closure $languageItem,
?\Closure $isAvailableCallback = null
) {
parent::__construct($identifier, $isAvailableCallback);
}
#[\Override]
public function render(array $objects): string
{
$identifier = StringUtil::encodeJS($this->getIdentifier());
$label = WCF::getLanguage()->get($this->languageItem) . ' (' . \count($objects) . ')';
$objectIDs = \array_values(\array_map(fn(DatabaseObject $object) => $object->getObjectID(), $objects));
$endpoint = StringUtil::encodeHTML(
LinkHandler::getInstance()->getControllerLink($this->controller, [
'ids' => $objectIDs
])
);
$jsonObjectIDs = StringUtil::encodeHTML(
JSON::encode($objectIDs)
);
return <<<HTML
<button
type="button"
data-bulk-interaction="{$identifier}"
data-endpoint="{$endpoint}"
data-object-ids="{$jsonObjectIDs}"
>
{$label}
</button>
HTML;
}
#[\Override]
public function renderInitialization(string $containerId): ?string
{
$identifier = StringUtil::encodeJS($this->getIdentifier());
$containerId = StringUtil::encodeJS($containerId);
return <<<HTML
<script data-relocate="true">
require(['WoltLabSuite/Core/Component/Interaction/Bulk/FormBuilderDialog'], ({ setup }) => {
setup('{$identifier}', document.getElementById('{$containerId}'));
});
</script>
HTML;
}
}