diff --git a/layouts/joomla/form/field/media.php b/layouts/joomla/form/field/media.php index f21b26b09fda2..4a6e75e364ef7 100644 --- a/layouts/joomla/form/field/media.php +++ b/layouts/joomla/form/field/media.php @@ -11,6 +11,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Helper\MediaHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; @@ -73,12 +74,19 @@ } // Pre fill the contents of the popover -if ($showPreview) { - if ($value && file_exists(JPATH_ROOT . '/' . $value)) { +if ($showPreview) +{ + $cleanValue = MediaHelper::getCleanMediaFieldValue($value); + + if ($cleanValue && file_exists(JPATH_ROOT . '/' . $cleanValue)) + { $src = Uri::root() . $value; - } else { + } + else + { $src = ''; } + $width = $previewWidth; $height = $previewHeight; $style = ''; diff --git a/libraries/src/Helper/MediaHelper.php b/libraries/src/Helper/MediaHelper.php index 57873e9f25c19..3425f9eb4b08c 100644 --- a/libraries/src/Helper/MediaHelper.php +++ b/libraries/src/Helper/MediaHelper.php @@ -464,4 +464,25 @@ public static function isValidLocalDirectory($directory) return false; } + + /** + * Helper method get clean data for value stores in a Media form field by removing adapter information + * from the value if available (in this case, the value will have this format: + * images/headers/blue-flower.jpg#joomlaImage://local-images/headers/blue-flower.jpg?width=700&height=180) + * + * @param string $value + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public static function getCleanMediaFieldValue($value) + { + if ($pos = strpos($value, '#')) + { + return substr($value, 0, $pos); + } + + return $value; + } }