-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathDownloadAssetFile.php
More file actions
54 lines (47 loc) · 1.34 KB
/
DownloadAssetFile.php
File metadata and controls
54 lines (47 loc) · 1.34 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
<?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 DownloadAssetFile extends ElementAction
{
#[\Override]
public function getTriggerLabel(): string
{
return t('Download');
}
public function getTriggerHtml(): ?string
{
HtmlStack::jsWithVars(fn ($type) => <<<JS
(() => {
new Craft.ElementActionTrigger({
type: $type,
activate: (selectedItems, elementIndex) => {
var \$form = Craft.createForm().appendTo(Garnish.\$bod);
$(Craft.getCsrfInput()).appendTo(\$form);
$('<input/>', {
type: 'hidden',
name: 'action',
value: 'assets/download-asset'
}).appendTo(\$form);
selectedItems.each(function() {
$('<input/>', {
type: 'hidden',
name: 'assetId[]',
value: $(this).data('id')
}).appendTo(\$form);
});
$('<input/>', {
type: 'submit',
value: 'Submit',
}).appendTo(\$form);
\$form.submit();
\$form.remove();
},
});
})();
JS, [static::class]);
return null;
}
}