-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathCopyUrl.php
More file actions
40 lines (33 loc) · 946 Bytes
/
CopyUrl.php
File metadata and controls
40 lines (33 loc) · 946 Bytes
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
<?php
declare(strict_types=1);
namespace CraftCms\Cms\Asset\Actions;
use CraftCms\Cms\Element\Actions\ElementAction;
use CraftCms\Cms\Support\Facades\HtmlStack;
use function CraftCms\Cms\t;
class CopyUrl extends ElementAction
{
#[\Override]
public function getTriggerLabel(): string
{
return t('Copy URL');
}
public function getTriggerHtml(): ?string
{
HtmlStack::jsWithVars(fn ($type) => <<<JS
(() => {
new Craft.ElementActionTrigger({
type: $type,
bulk: false,
validateSelection: (selectedItems, elementIndex) => !!selectedItems.find('.element').data('url'),
activate: (selectedItems, elementIndex) => {
Craft.ui.createCopyTextPrompt({
label: Craft.t('app', 'Copy the URL'),
value: selectedItems.find('.element').data('url'),
});
},
})
})();
JS, [static::class]);
return null;
}
}