Skip to content

Commit d3c333c

Browse files
authored
[5.4] TinyMCE default folder for uploads (#45956)
Fix default upload folder to be same as Media "Path to Images Folder" option.
1 parent 92b4591 commit d3c333c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

plugins/editors/tinymce/src/PluginTraits/DisplayTrait.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
namespace Joomla\Plugin\Editors\TinyMCE\PluginTraits;
1212

13+
use Joomla\CMS\Component\ComponentHelper;
1314
use Joomla\CMS\Filter\InputFilter;
1415
use Joomla\CMS\Language\Text;
1516
use Joomla\CMS\Layout\LayoutHelper;
1617
use Joomla\CMS\Session\Session;
1718
use Joomla\CMS\Uri\Uri;
19+
use Joomla\Component\Media\Administrator\Exception\ProviderAccountNotFoundException;
1820
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;
1921
use Joomla\Registry\Registry;
2022

@@ -327,14 +329,29 @@ public function display(string $name, string $content = '', array $attributes =
327329
$wa->useScript('plg_editors_tinymce.jdragndrop');
328330
$plugins[] = 'jdragndrop';
329331
$uploadUrl = Uri::base(true) . '/index.php?option=com_media&format=json&url=1&task=api.files';
330-
$uploadPath = $levelParams->get('path', '');
332+
$uploadPath = $levelParams->get('path', ComponentHelper::getParams('com_media')->get('image_path', 'images'));
331333

332334
// Make sure the path is full, and contain the media adapter in it.
333335
$mediaHelper = new class () {
334336
use ProviderManagerHelperTrait;
335337

336338
public function prepareTinyMCEUploadPath(string $path): string
337339
{
340+
// Check for the path includes the adapter
341+
if (!str_contains($path, ':')) {
342+
try {
343+
/*
344+
* We got old folder name without adapter eg "images".
345+
* Look whether the adapter exists for this folder, otherwise everything will fallback to default.
346+
*/
347+
$this->getAdapter('local-' . $path);
348+
// Adapter exists, update the path
349+
$path = 'local-' . $path . ':/';
350+
} catch (ProviderAccountNotFoundException) {
351+
// Nothing found
352+
}
353+
}
354+
338355
$result = $this->resolveAdapterAndPath($path);
339356

340357
return implode(':', $result);

0 commit comments

Comments
 (0)