Skip to content

Commit f385871

Browse files
authored
[6.0] Add custom classes to the class dropdown in the image dialog in TinyMCE (joomla#45676)
* Added option to define image classes * Making phpcs happy
1 parent ef50957 commit f385871

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

administrator/language/en-GB/plg_editors_tinymce.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ PLG_TINY_FIELD_EXTERNALPLUGINS_NAME_LABEL="Plugin Name"
4242
PLG_TINY_FIELD_EXTERNALPLUGINS_PATH_LABEL="Path"
4343
PLG_TINY_FIELD_HTMLHEIGHT_LABEL="HTML Height"
4444
PLG_TINY_FIELD_HTMLWIDTH_LABEL="HTML Width"
45+
PLG_TINY_FIELD_IMG_CLASS_LIST_LABEL="Class List"
46+
PLG_TINY_FIELD_IMG_CLASS_NAME_LABEL="Name"
47+
PLG_TINY_FIELD_IMG_CLASS_NO_CLASS="No Class Selected"
48+
PLG_TINY_FIELD_IMG_CLASSES_LIST_DESC="Add classes to the image class dropdown in the image dialog."
49+
PLG_TINY_FIELD_IMG_CLASSES_LIST_LABEL="Image Classes List"
4550
PLG_TINY_FIELD_LABEL_ADVANCEDPARAMS="Advanced"
4651
PLG_TINY_FIELD_LANGCODE_LABEL="Language Code"
4752
PLG_TINY_FIELD_LANGSELECT_LABEL="Automatic Language Selection"

plugins/editors/tinymce/forms/setoptions.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,5 +445,34 @@
445445
/>
446446
</form>
447447
</field>
448+
449+
<field
450+
name="img_classes_list"
451+
type="subform"
452+
label="PLG_TINY_FIELD_IMG_CLASSES_LIST_LABEL"
453+
description="PLG_TINY_FIELD_IMG_CLASSES_LIST_DESC"
454+
layout="joomla.form.field.subform.repeatable-table"
455+
required="false"
456+
multiple="true">
457+
<form>
458+
<field
459+
name="img_class_name"
460+
type="text"
461+
label="PLG_TINY_FIELD_IMG_CLASS_NAME_LABEL"
462+
required="true"
463+
filter="string"
464+
default=""
465+
/>
466+
<field
467+
name="img_class_list"
468+
type="text"
469+
label="PLG_TINY_FIELD_IMG_CLASS_LIST_LABEL"
470+
required="true"
471+
filter="string"
472+
validate="CssIdentifier"
473+
default=""
474+
/>
475+
</form>
476+
</field>
448477
</fieldset>
449478
</form>

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,27 @@ public function prepareTinyMCEUploadPath(string $path): string
410410
}
411411
}
412412

413+
// Set the default classes for the image class dropdown
414+
$imgClasses = [
415+
['title' => TEXT::_('PLG_TINY_FIELD_IMG_CLASS_NO_CLASS'), 'value' => ''],
416+
['title' => 'None', 'value' => 'float-none'],
417+
['title' => 'Left', 'value' => 'float-start'],
418+
['title' => 'Right', 'value' => 'float-end'],
419+
['title' => 'Center', 'value' => 'mx-auto d-block'],
420+
];
421+
422+
// Load the image classes list
423+
if (isset($extraOptions->img_classes_list) && $extraOptions->img_classes_list) {
424+
$imgClassesList = $extraOptions->img_classes_list;
425+
426+
if ($imgClassesList) {
427+
// Create an array for the image classes
428+
foreach ($imgClassesList as $imgClassList) {
429+
array_push($imgClasses, ['title' => $imgClassList->img_class_name, 'value' => $imgClassList->img_class_list]);
430+
}
431+
}
432+
}
433+
413434
// Build the final options set
414435
$scriptOptions = array_merge(
415436
$scriptOptions,
@@ -476,12 +497,7 @@ public function prepareTinyMCEUploadPath(string $path): string
476497
'a11y_advanced_options' => true,
477498
'image_advtab' => (bool) $levelParams->get('image_advtab', false),
478499
'image_title' => true,
479-
'image_class_list' => [
480-
['title' => 'None', 'value' => 'float-none'],
481-
['title' => 'Left', 'value' => 'float-start'],
482-
['title' => 'Right', 'value' => 'float-end'],
483-
['title' => 'Center', 'value' => 'mx-auto d-block'],
484-
],
500+
'image_class_list' => $imgClasses,
485501

486502
// Drag and drop specific
487503
'dndEnabled' => $dragdrop,

0 commit comments

Comments
 (0)