J3 Issue ?
avatar ReLater
ReLater
19 Apr 2019

Steps to reproduce the issue

  • Create a custom field for articles of type Media
  • Select a directory and enter an existing image name inside that directory as Default Value
    19-04-_2019_15-17-13
  • Save the field
  • Open an article and see:

19-04-_2019_15-19-32

  • The path is wrong. It should be images/banners/shop-ad.jpg

  • Don't change the media field and save the article.

  • See the article in frontend.

19-04-_2019_15-24-47

Expected result

  • Field resolves the directory path correctly.

Actual result

  • Directory path ignored and one have to select the media again (in any article).
avatar ReLater ReLater - open - 19 Apr 2019
avatar joomla-cms-bot joomla-cms-bot - change - 19 Apr 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 19 Apr 2019
avatar ReLater ReLater - change - 19 Apr 2019
Title
[com_fields] media field. Wrong defaul value.
[com_fields] Field type media. Wrong default value/path in article edit.
avatar ReLater ReLater - change - 19 Apr 2019
Title
[com_fields] media field. Wrong defaul value.
[com_fields] Field type media. Wrong default value/path in article edit.
avatar ReLater ReLater - edited - 19 Apr 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 19 Apr 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 19 Apr 2019
avatar ReLater ReLater - change - 19 Apr 2019
The description was changed
avatar ReLater ReLater - edited - 19 Apr 2019
avatar ReLater ReLater - change - 19 Apr 2019
The description was changed
avatar ReLater ReLater - edited - 19 Apr 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 19 Apr 2019
Status New Discussion
avatar infograf768
infograf768 - comment - 29 Apr 2019

I can't reproduce the issue
Screen Shot 2019-04-29 at 07 53 39

Screen Shot 2019-04-29 at 07 53 03

Screen Shot 2019-04-29 at 07 54 44

avatar infograf768
infograf768 - comment - 29 Apr 2019

Hmm
You are right.
If we do not select again the image when editing the article, the path is not added.

This means we have to enter the full path to the image in the Default Value

Screen Shot 2019-04-29 at 08 03 19

avatar infograf768
infograf768 - comment - 29 Apr 2019

I have been playing a bit further with this.
The default_value field is a textarea and is common to all custom fields.
Could not find an easy way to override the field type in this case.

The following patch could partly (see Note below) solve the issue, but only for the frontend display as it will not allow the preview of the default image when editing the article.

diff --git a/plugins/fields/media/tmpl/media.php b/plugins/fields/media/tmpl/media.php
index 1707e09..981093e 100644
--- a/plugins/fields/media/tmpl/media.php
+++ b/plugins/fields/media/tmpl/media.php
@@ -9,4 +9,6 @@
 defined('_JEXEC') or die;
 
+use Joomla\CMS\Component\ComponentHelper;
+
 if ($field->value == '')
 {
@@ -22,4 +24,8 @@
 
 $value  = (array) $field->value;
+
+$directory = $fieldParams->get('directory') ? $fieldParams->get('directory') . '/' : '';
+$imagePath = ComponentHelper::getParams('com_media')->get('image_path', 'images') . '/';
+
 $buffer = '';
 
@@ -31,4 +37,9 @@
 	}
 
+	if (!strpos($path, '/'))
+	{
+		$path = $imagePath . $directory . $path;
+	}
+
 	$buffer .= sprintf('<img src="%s"%s>',
 		htmlentities($path, ENT_COMPAT, 'UTF-8', true),

Note: I am using above the variable $imagePath.
For this plugin, it will always be images/ as the directory is defined in the xml.
This is an important limitation.
The plugin should be improved to let use the default "Path to Images Folder" defined in com_media configuration.

avatar ReLater
ReLater - comment - 29 Apr 2019

This means we have to enter the full path to the image in the Default Value

And in field type Imagelist we only have to enter the image name. That's at least inconsistent or zero UIX.

Back to field of type media:

Try this (two different directories). Now the setting Directory is completely useless:

29-04-_2019_10-05-53

Go into article. In field click Select or Clear and then Select. The media manager opens images/banners/ but not images/sampledata/fruitshop.

avatar infograf768
infograf768 - comment - 29 Apr 2019

And in field type Imagelist we only have to enter the image name

Is that working really?
I always get The default value is invalid.

avatar ReLater
ReLater - comment - 29 Apr 2019

I always get The default value is invalid.

I forgot to mention pr #24643

Maybe also of interest in this context: #23568

avatar ReLater ReLater - change - 13 Jun 2021
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2021-06-13 14:15:14
Closed_By ReLater
avatar ReLater ReLater - close - 13 Jun 2021

Add a Comment

Login with GitHub to post a comment