-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathEditImage.php
More file actions
47 lines (37 loc) · 1.08 KB
/
EditImage.php
File metadata and controls
47 lines (37 loc) · 1.08 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
<?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 EditImage extends ElementAction
{
public string $label;
public function __construct(array|object $config = [])
{
parent::__construct($config);
$this->label ??= t('Edit Image');
}
#[\Override]
public function getTriggerLabel(): string
{
return $this->label;
}
public function getTriggerHtml(): ?string
{
HtmlStack::jsWithVars(fn ($type) => <<<JS
(() => {
new Craft.ElementActionTrigger({
type: $type,
bulk: false,
validateSelection: (selectedItems, elementIndex) => Garnish.hasAttr(selectedItems.find('.element'), 'data-editable-image'),
activate: (selectedItems, elementIndex) => {
const \$element = selectedItems.find('.element:first');
new Craft.AssetImageEditor(\$element.data('id'));
},
});
})();
JS, [static::class]);
return null;
}
}