Skip to content

[4.0] Fix tinymce template #1730

@jgerman-bot

Description

@jgerman-bot

New language relevant PR in upstream repo: joomla/joomla-cms#33130 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/language/en-GB/plg_editors_tinymce.ini b/administrator/language/en-GB/plg_editors_tinymce.ini
index fec5dea6d4033..8f7b66c613a57 100644
--- a/administrator/language/en-GB/plg_editors_tinymce.ini
+++ b/administrator/language/en-GB/plg_editors_tinymce.ini
@@ -20,6 +20,8 @@ PLG_TINY_FIELD_ADVLIST_LABEL="Advanced List"
 PLG_TINY_FIELD_CONTEXTMENU_LABEL="Context Menu"
 PLG_TINY_FIELD_CSS_DESC="By default the Plugin looks for an editor.css file. If it can't find one in the default template CSS folder, it loads the editor.css file from the system template."
 PLG_TINY_FIELD_CSS_LABEL="Template CSS Classes"
+PLG_TINY_FIELD_CUSTOM_CONTENT_TEMPLATE_PATH_DESC="A directory named \"tinymce\" in your site template."
+PLG_TINY_FIELD_CUSTOM_CONTENT_TEMPLATE_PATH_LABEL="Content Template Directory"
 PLG_TINY_FIELD_CUSTOM_CSS_DESC="Optional CSS file that will override the standard editor.css file. Enter a file name to point to a file in the CSS folder of the default template (for example, templates/cassiopeia/css/). Or enter a full URL path to the custom CSS file. If you enter a value in this field, this file will be used instead of the editor.css file."
 PLG_TINY_FIELD_CUSTOM_CSS_LABEL="Custom CSS Classes"
 PLG_TINY_FIELD_CUSTOM_PATH_LABEL="Images Directory"
diff --git a/plugins/editors/tinymce/forms/setoptions.xml b/plugins/editors/tinymce/forms/setoptions.xml
index f60ee558d5781..e8433b2bc78c8 100644
--- a/plugins/editors/tinymce/forms/setoptions.xml
+++ b/plugins/editors/tinymce/forms/setoptions.xml
@@ -68,6 +68,19 @@
 			showon="drag_drop:1"
 		/>
 
+		<field
+			name="content_template_path"
+			type="folderlist"
+			label="PLG_TINY_FIELD_CUSTOM_CONTENT_TEMPLATE_PATH_LABEL"
+			description="PLG_TINY_FIELD_CUSTOM_CONTENT_TEMPLATE_PATH_DESC"
+			directory="/templates"
+			hide_none="true"
+			recursive="true"
+			exclude="system"
+			default=""
+			folderFilter="^tinymce"
+		/>
+
 		<field
 			name="entity_encoding"
 			type="list"
@@ -293,7 +306,6 @@
 			label="PLG_TINY_FIELD_CUSTOMBUTTON_LABEL"
 		/>
 
-
 		<field
 			name="external_plugins"
 			type="subform"
@@ -321,5 +333,4 @@
 		</field>
 
 	</fieldset>
-
 </form>
diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php
index bed8e972cf80a..19d35b1989b03 100644
--- a/plugins/editors/tinymce/tinymce.php
+++ b/plugins/editors/tinymce/tinymce.php
@@ -470,32 +470,41 @@ public function onDisplay(
 
 		if (!empty($allButtons['template']))
 		{
-			foreach (glob(JPATH_ROOT . '/media/vendor/tinymce/templates/*.html') as $filename)
+			// Do we have a custom content_template_path
+			$template_path = $levelParams->get('content_template_path');
+			$template_path = $template_path ? '/templates/' . $template_path : '/media/vendor/tinymce/templates';
+
+			foreach (glob(JPATH_ROOT . $template_path . '/*.{html,txt}', GLOB_BRACE) as $filepath)
 			{
-				$filename = basename($filename, '.html');
+				$fileinfo      = pathinfo($filepath);
+				$filename      = $fileinfo['filename'];
+				$full_filename = $fileinfo['basename'];
 
-				if ($filename !== 'index')
+				if ($filename === 'index')
 				{
-					$lang        = Factory::getLanguage();
-					$title       = $filename;
-					$description = ' ';
+					continue;
+				}
 
-					if ($lang->hasKey('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_TITLE'))
-					{
-						$title = Text::_('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_TITLE');
-					}
+				$lang        = Factory::getLanguage();
+				$title       = $filename;
+				$title_upper = strtoupper($filename);
+				$description = ' ';
 
-					if ($lang->hasKey('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_DESC'))
-					{
-						$description = Text::_('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_DESC');
-					}
+				if ($lang->hasKey('PLG_TINY_TEMPLATE_' . $title_upper . '_TITLE'))
+				{
+					$title = Text::_('PLG_TINY_TEMPLATE_' . $title_upper . '_TITLE');
+				}
 
-					$templates[] = array(
-						'title' => $title,
-						'description' => $description,
-						'url' => Uri::root(true) . '/media/vendor/tinymce/templates/' . $filename . '.html',
-					);
+				if ($lang->hasKey('PLG_TINY_TEMPLATE_' . $title_upper . '_DESC'))
+				{
+					$description = Text::_('PLG_TINY_TEMPLATE_' . $title_upper . '_DESC');
 				}
+
+				$templates[] = array(
+					'title' => $title,
+					'description' => $description,
+					'url' => Uri::root(true) . $template_path . '/' . $full_filename,
+				);
 			}
 		}
 
diff --git a/templates/cassiopeia/html/tinymce/index.html b/templates/cassiopeia/html/tinymce/index.html
new file mode 100644
index 0000000000000..2efb97f319a35
--- /dev/null
+++ b/templates/cassiopeia/html/tinymce/index.html
@@ -0,0 +1 @@
+<!DOCTYPE html><title></title>
diff --git a/templates/cassiopeia/templateDetails.xml b/templates/cassiopeia/templateDetails.xml
index 2aeeb09b0593f..869ac8a802725 100644
--- a/templates/cassiopeia/templateDetails.xml
+++ b/templates/cassiopeia/templateDetails.xml
@@ -18,6 +18,7 @@
 		<filename>template_thumbnail.png</filename>
 		<folder>css</folder>
 		<folder>html</folder>
+		<folder>html/tinymce</folder>
 		<folder>images</folder>
 		<folder>js</folder>
 		<folder>scss</folder>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions