Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default {
bubbles: true,
cancelable: false,
detail: {
type: this.item.type,
path: this.item.path,
thumb: this.item.thumb,
fileType: this.item.mime_type ? this.item.mime_type : false,
Expand All @@ -142,7 +143,10 @@ export default {
new CustomEvent('onMediaFileSelected', {
bubbles: true,
cancelable: false,
detail: {},
detail: {
type: this.item.type,
path: this.item.path,
},
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,31 @@ export default {
* @param event
*/
onClick(event) {
const path = false;
const data = {
path,
path: this.item.path,
type: this.item.type,
thumb: false,
fileType: this.item.mime_type ? this.item.mime_type : false,
extension: this.item.extension ? this.item.extension : false,
};

if (this.item.type === 'file') {
data.path = this.item.path;
data.thumb = this.item.thumb ? this.item.thumb : false;
data.width = this.item.width ? this.item.width : 0;
data.height = this.item.height ? this.item.height : 0;

window.parent.document.dispatchEvent(
new CustomEvent(
'onMediaFileSelected',
{
bubbles: true,
cancelable: false,
detail: data,
},
),
);
}

window.parent.document.dispatchEvent(
new CustomEvent(
'onMediaFileSelected',
{
bubbles: true,
cancelable: false,
detail: data,
},
),
);

// Handle clicks when the item was not selected
if (!this.isSelected()) {
// Unselect all other selected items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class JoomlaFieldMedia extends HTMLElement {
}

static get observedAttributes() {
return ['type', 'base-path', 'root-folder', 'url', 'modal-title', 'modal-width', 'modal-height', 'input', 'button-select', 'button-clear', 'preview', 'preview-width', 'preview-height'];
return ['base-path', 'root-folder', 'url', 'modal-title', 'modal-width', 'modal-height', 'input', 'button-select', 'button-clear', 'preview', 'preview-width', 'preview-height'];
}

get type() { return this.getAttribute('type'); }
get types() { return this.getAttribute('types') || ''; }

set type(value) { this.setAttribute('type', value); }
set types(value) { this.setAttribute('types', value); }

get basePath() { return this.getAttribute('base-path'); }

Expand Down Expand Up @@ -175,7 +175,12 @@ class JoomlaFieldMedia extends HTMLElement {

async modalClose() {
try {
await Joomla.getMedia(Joomla.selectedMediaFile, this.inputElement, this);
const item = Joomla.selectedMediaFile;
if (item && item.type === 'dir' && this.types.includes('directories')) {
this.setValue(item.path);
} else {
await Joomla.getMedia(Joomla.selectedMediaFile, this.inputElement, this);
}
} catch (err) {
Joomla.renderMessages({
error: [Joomla.Text._('JLIB_APPLICATION_ERROR_SERVER')],
Expand Down
6 changes: 4 additions & 2 deletions layouts/joomla/form/field/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
* @var integer $size The size text
* @var string $value The value text
* @var string $src The path and filename of the image
* @var array $mediaTypes The supported media types for the Media Manager
* @var string $mediaTypes The ids of supported media types for the Media Manager
* @var array $mediaTypeNames The names of supported media types for the Media Manager
* @var array $imagesExt The supported extensions for images
* @var array $audiosExt The supported extensions for audios
* @var array $videosExt The supported extensions for videos
Expand Down Expand Up @@ -155,7 +156,8 @@
}

?>
<joomla-field-media class="field-media-wrapper" type="image" <?php // @TODO add this attribute to the field in order to use it for all media types ?>
<joomla-field-media class="field-media-wrapper"
types="<?php echo $this->escape(implode(',', $mediaTypeNames)); ?>"
base-path="<?php echo $this->escape(Uri::root()); ?>"
root-folder="<?php echo $this->escape(ComponentHelper::getParams('com_media')->get('file_path', 'images')); ?>"
url="<?php echo $url; ?>"
Expand Down
4 changes: 4 additions & 0 deletions libraries/src/Form/Field/MediaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ public function getLayoutData()
array_map(
function ($mediaType) use (&$types, &$imagesAllowedExt, &$audiosAllowedExt, &$videosAllowedExt, &$documentsAllowedExt, $imagesExt, $audiosExt, $videosExt, $documentsExt) {
switch ($mediaType) {
case 'directories':
$types[] = '-1';
break;
case 'images':
$types[] = '0';
$imagesAllowedExt = $imagesExt;
Expand Down Expand Up @@ -417,6 +420,7 @@ function ($mediaType) use (&$types, &$imagesAllowedExt, &$audiosAllowedExt, &$vi
'previewHeight' => $this->previewHeight,
'previewWidth' => $this->previewWidth,
'mediaTypes' => implode(',', $types),
'mediaTypeNames' => $mediaTypes,
'imagesExt' => $imagesExt,
'audiosExt' => $audiosExt,
'videosExt' => $videosExt,
Expand Down
8 changes: 3 additions & 5 deletions plugins/fields/media/params/media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
<fieldset name="fieldparams">
<field
name="directory"
type="folderlist"
type="media"
label="PLG_FIELDS_MEDIA_PARAMS_DIRECTORY_LABEL"
directory="images"
hide_none="true"
recursive="true"
validate="options"
preview="false"
types="directories"
/>

<field
Expand Down