Skip to content

Commit 88077f2

Browse files
committed
Download action
- added action `Download` - actions can defined custom HTML through Latte block in `fileManagerControl.latte` - added translations
1 parent 1a149e1 commit 88077f2

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

src/Action/DownloadAction.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SixtyEightPublishers\FileBundle\Action;
6+
7+
use SixtyEightPublishers\FileBundle\Entity\FileInterface;
8+
use SixtyEightPublishers\FileBundle\Storage\DataStorageInterface;
9+
use SixtyEightPublishers\FileBundle\Exception\InvalidStateException;
10+
11+
final class DownloadAction implements ActionInterface
12+
{
13+
/** @var string|NULL */
14+
protected $label;
15+
16+
/**
17+
* @param string $label
18+
*/
19+
public function __construct(?string $label = NULL)
20+
{
21+
$this->label = $label;
22+
}
23+
24+
/**
25+
* {@inheritDoc}
26+
*/
27+
public function getName(): string
28+
{
29+
return 'download';
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
35+
public function getLabel(): string
36+
{
37+
return $this->label ?? $this->getName();
38+
}
39+
40+
/**
41+
* {@inheritDoc}
42+
*/
43+
public function isImplemented(DataStorageInterface $storage): bool
44+
{
45+
return TRUE;
46+
}
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
public function isApplicableOnFile(FileInterface $file, DataStorageInterface $dataStorage): bool
52+
{
53+
return TRUE;
54+
}
55+
56+
/**
57+
* {@inheritDoc}
58+
*/
59+
public function run(DataStorageInterface $dataStorage, FileInterface $file): void
60+
{
61+
throw new InvalidStateException(sprintf(
62+
'The action of type %s can\'t be called server side.',
63+
self::class
64+
));
65+
}
66+
}

src/Control/FileManager/templates/fileManagerControl.latte

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@
3939

4040
<div n:block="#actions" n:if="count($actions)" class="file-manager-actions position-absolute text-right right-0 top-0">
4141
<div class="dropdown">
42-
<span n:block="#actions_button" class="dropdown-ellipses dropdown-toggle btbtn-secondary btn-sm bg-white" id="file-actions-{$uniqueId}-{$file->getId()}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
43-
<i n:block="#actions_button_icon" class="fa fa-bars"></i>
44-
</span>
42+
<span n:block="#actions_button" class="dropdown-ellipses dropdown-toggle btbtn-secondary btn-sm bg-white" id="file-actions-{$uniqueId}-{$file->getId()}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
43+
<i n:block="#actions_button_icon" class="fa fa-bars"></i>
44+
</span>
4545
<div n:block="#actions_menu" class="dropdown-menu dropdown-menu-right" aria-labelledby="file-actions-{$uniqueId}-{$file->getId()}">
46-
<a n:foreach="$actions as $action" n:href="doAction!, actionName => $action->getName(), id => (string) $file->getId()" class="dropdown-item ajax">{_'action.' . $action->getLabel()}</a>
46+
{foreach $actions as $action}
47+
{ifset block action_type_ . $action->getName()}
48+
{include block action_type_ . $action->getName(), $action, $file}
49+
{else}
50+
<a n:href="doAction!, actionName => $action->getName(), id => (string) $file->getId()" class="dropdown-item ajax">{_'action.' . $action->getLabel()}</a>
51+
{/ifset}
52+
{/foreach}
4753
</div>
4854
</div>
4955
</div>
@@ -79,3 +85,10 @@
7985
{/foreach}
8086
</div>
8187
</div>
88+
89+
{define action_type_download, $action, $file}
90+
{var $isImage = interface_exists('SixtyEightPublishers\ImageStorage\FileInfoInterface') && $file->getSource() instanceof SixtyEightPublishers\ImageStorage\FileInfoInterface}
91+
{var $source = $isImage ? $file->getSource()->withModifiers([original => TRUE]) : $file->getSource()}
92+
93+
<a href="{$source->link()}" target="_blank" class="dropdown-item" data-file-manager-download="{$file->getMetadata(SixtyEightPublishers\FileBundle\ResourceMetadata\MetadataName::NAME, '')}">{_'action.' . $action->getLabel()}</a>
94+
{/define}

src/translations/SixtyEightPublishers_FileBundle_Control_FileManager_FileManagerControl.cs.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ action:
4141
delete: Odstranit
4242
rotate_left: Otočit vlevo
4343
rotate_right: Otočit vpravo
44+
download: Stáhnout

src/translations/SixtyEightPublishers_FileBundle_Control_FileManager_FileManagerControl.en.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ action:
4040
delete: Delete
4141
rotate_left: Rotate left
4242
rotate_right: Rotate right
43+
download: Download

0 commit comments

Comments
 (0)