-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathCopyReferenceTag.php
More file actions
45 lines (37 loc) · 1.13 KB
/
CopyReferenceTag.php
File metadata and controls
45 lines (37 loc) · 1.13 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
<?php
declare(strict_types=1);
namespace CraftCms\Cms\Asset\Actions;
use CraftCms\Cms\Element\Actions\ElementAction;
use CraftCms\Cms\Support\Facades\HtmlStack;
use RuntimeException;
use function CraftCms\Cms\t;
class CopyReferenceTag extends ElementAction
{
#[\Override]
public function getTriggerLabel(): string
{
return t('Copy reference tag');
}
public function getTriggerHtml(): ?string
{
$refHandle = $this->elementType::refHandle();
if ($refHandle === null) {
throw new RuntimeException("Element type \"$this->elementType\" doesn't have a reference handle.");
}
HtmlStack::jsWithVars(fn ($type, $refHandle) => <<<JS
(() => {
new Craft.ElementActionTrigger({
type: $type,
bulk: false,
activate: (selectedItems, elementIndex) => {
Craft.ui.createCopyTextPrompt({
label: Craft.t('app', 'Copy the reference tag'),
value: '{' + $refHandle + ':' + selectedItems.find('.element').data('id') + '}',
});
},
})
})();
JS, [static::class, $refHandle]);
return null;
}
}