Skip to content

Commit

Permalink
Added open_media action
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers committed Aug 25, 2023
1 parent 748a91c commit 951de1e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions blocks/button.block
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ fields:
type: iconpicker
==
<?php
use System\Classes\MediaLibrary;

function onStart()
{
$this->controller->addJs(Url::asset('/plugins/winter/blocks/assets/dist/js/blocks.js'), 'Winter.Blocks');
Expand All @@ -48,6 +50,14 @@ function onStart()
foreach ($data['actions'] as &$config) {
$action = $config['_group'] ?? '';
unset($config['_group']);

switch ($action) {
case 'open_media':
$config['href'] = MediaLibrary::url($config['media_file']);
$action = 'open_url';
break;
}

$config = [
'data' => $config,
'action' => $action,
Expand Down
5 changes: 5 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
'target_self' => 'Same tab',
'target_blank' => 'New tab',
],
'open_media' => [
'name' => 'Download Media File',
'description' => 'Download the provided file from the Media Library',
'media_file' => 'File',
],
],
'tabs' => [
'display' => 'Display',
Expand Down
20 changes: 20 additions & 0 deletions meta/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,23 @@ open_url:
options:
_self: winter.blocks::lang.actions.open_url.target_self
_blank: winter.blocks::lang.actions.open_url.target_blank
open_media:
name: winter.blocks::lang.actions.open_media.name
description: winter.blocks::lang.actions.open_media.description
icon: icon-file
fields:
_title:
label: winter.blocks::lang.actions.open_media.name
type: section
media_file:
label: winter.blocks::lang.actions.open_media.media_file
type: mediafinder
span: left
mode: file
target:
label: winter.blocks::lang.actions.open_url.target
type: balloon-selector
span: right
options:
_self: winter.blocks::lang.actions.open_url.target_self
_blank: winter.blocks::lang.actions.open_url.target_blank

0 comments on commit 951de1e

Please sign in to comment.