diff --git a/modules/backend/formwidgets/RichEditor.php b/modules/backend/formwidgets/RichEditor.php index 0adbbc8f8..0949ced02 100644 --- a/modules/backend/formwidgets/RichEditor.php +++ b/modules/backend/formwidgets/RichEditor.php @@ -106,6 +106,7 @@ class RichEditor extends FormWidgetBase $this->vars['imageStyles'] = EditorSetting::getConfiguredStyles('html_style_image'); $this->vars['linkStyles'] = EditorSetting::getConfiguredStyles('html_style_link'); $this->vars['paragraphStyles'] = EditorSetting::getConfiguredStyles('html_style_paragraph'); + $this->vars['paragraphFormats'] = EditorSetting::getConfiguredFormats('html_paragraph_formats'); $this->vars['tableStyles'] = EditorSetting::getConfiguredStyles('html_style_table'); $this->vars['tableCellStyles'] = EditorSetting::getConfiguredStyles('html_style_table_cell'); } diff --git a/modules/backend/formwidgets/richeditor/assets/js/richeditor.js b/modules/backend/formwidgets/richeditor/assets/js/richeditor.js index 0fcb1227c..230ff8f85 100755 --- a/modules/backend/formwidgets/richeditor/assets/js/richeditor.js +++ b/modules/backend/formwidgets/richeditor/assets/js/richeditor.js @@ -50,6 +50,7 @@ imageStyles: null, linkStyles: null, paragraphStyles: null, + paragraphFormat: null, tableStyles: null, tableCellStyles: null, aceVendorPath: '/', @@ -115,6 +116,17 @@ 'oc-text-uppercase': 'Uppercase' } + froalaOptions.paragraphFormat = this.options.paragraphFormat + ? this.options.paragraphFormat + : { + 'N': 'Normal', + 'H1': 'Heading 1', + 'H2': 'Heading 2', + 'H3': 'Heading 3', + 'H4': 'Heading 4', + 'PRE': 'Code' + } + froalaOptions.tableStyles = this.options.tableStyles ? this.options.tableStyles : { diff --git a/modules/backend/formwidgets/richeditor/partials/_richeditor.htm b/modules/backend/formwidgets/richeditor/partials/_richeditor.htm index d9cf3af79..3457a34f5 100755 --- a/modules/backend/formwidgets/richeditor/partials/_richeditor.htm +++ b/modules/backend/formwidgets/richeditor/partials/_richeditor.htm @@ -19,6 +19,7 @@ data-image-styles="" data-link-styles="" data-paragraph-styles="" + data-paragraph-format="" data-table-styles="" data-table-cell-styles="" data-links-handler="getEventHandler('onLoadPageLinksForm') ?>" diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index b173798ef..368664c63 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -406,6 +406,7 @@ return [ 'label' => 'Label', 'class_name' => 'Class name', 'markup_tags' => 'Markup Tags', + 'markup_tag' => 'Markup Tag', 'allowed_empty_tags' => 'Allowed empty tags', 'allowed_empty_tags_comment' => 'The list of tags that are not removed when they have no content inside.', 'allowed_tags' => 'Allowed tags', @@ -416,6 +417,7 @@ return [ 'remove_tags_comment' => 'The list of tags that are removed together with their content.', 'line_breaker_tags' => 'Line breaker tags', 'line_breaker_tags_comment' => 'The list of tags that are used to place a line breaker element between.', + 'toolbar_options' => 'Toolbar Options', 'toolbar_buttons' => 'Toolbar Buttons', 'toolbar_buttons_comment' => 'The Toolbar Buttons to be displayed in the Rich Editor by default.', 'toolbar_buttons_preset' => 'Insert a preset toolbar button configuration:', @@ -424,6 +426,8 @@ return [ 'minimal' => 'Minimal', 'full' => 'Full', ], + 'paragraph_formats' => 'Paragraph Formats', + 'paragraph_formats_comment' => 'The options that will appear in the Paragraph Format dropdown.', ], 'tooltips' => [ 'preview_website' => 'Preview the website', diff --git a/modules/backend/models/EditorSetting.php b/modules/backend/models/EditorSetting.php index 56983fffa..b44081b16 100644 --- a/modules/backend/models/EditorSetting.php +++ b/modules/backend/models/EditorSetting.php @@ -76,6 +76,15 @@ class EditorSetting extends Model 'oc-cell-thick-border' => 'Thick Border', ]; + protected $defaultHtmlParagraphFormats = [ + 'N' => 'Normal', + 'H1' => 'Heading 1', + 'H2' => 'Heading 2', + 'H3' => 'Heading 3', + 'H4' => 'Heading 4', + 'PRE' => 'Code', + ]; + /** * Editor toolbar presets for Froala. */ @@ -113,6 +122,15 @@ class EditorSetting extends Model $this->html_style_paragraph = $this->makeStylesForTable($this->defaultHtmlStyleParagraph); $this->html_style_table = $this->makeStylesForTable($this->defaultHtmlStyleTable); $this->html_style_table_cell = $this->makeStylesForTable($this->defaultHtmlStyleTableCell); + $this->html_paragraph_formats = $this->makeFormatsForTable($this->defaultHtmlParagraphFormats); + } + + public function afterFetch() + { + if (!isset($this->value['html_paragraph_formats'])) { + $this->html_paragraph_formats = $this->makeFormatsForTable($this->defaultHtmlParagraphFormats); + $this->save(); + } } public function afterSave() @@ -129,11 +147,48 @@ class EditorSetting extends Model }); } + protected function makeFormatsForTable($arr) + { + $count = 0; + + return array_build($arr, function ($key, $value) use (&$count) { + return [$count++, ['format_label' => $value, 'format_tag' => $key]]; + }); + } + /** - * Same as getConfigured but uses special style structure. + * Same as getConfigured but uses a special structure for styles. * @return mixed */ public static function getConfiguredStyles($key, $default = null) + { + return static::getConfiguredArray($key, $default, function ($key, $value) { + if (array_has($value, ['class_name', 'class_label'])) { + return [ + array_get($value, 'class_name'), + array_get($value, 'class_label') + ]; + } + }); + } + + /** + * Same as getConfigured but uses a special structure for paragraph formats. + * @return mixed + */ + public static function getConfiguredFormats($key, $default = null) + { + return static::getConfiguredArray($key, $default, function ($key, $value) { + if (array_has($value, ['format_tag', 'format_label'])) { + return [ + array_get($value, 'format_tag'), + array_get($value, 'format_label') + ]; + } + }); + } + + protected static function getConfiguredArray($key, $default = null, $callback = null) { $instance = static::instance(); @@ -141,15 +196,8 @@ class EditorSetting extends Model $defaultValue = $instance->getDefaultValue($key); - if (is_array($value)) { - $value = array_filter(array_build($value, function ($key, $value) { - if (array_has($value, ['class_name', 'class_label'])) { - return [ - array_get($value, 'class_name'), - array_get($value, 'class_label') - ]; - } - })); + if (is_array($value) && is_callable($callback)) { + $value = array_filter(array_build($value, $callback)); } return $value != $defaultValue ? $value : $default; diff --git a/modules/backend/models/editorsetting/fields.yaml b/modules/backend/models/editorsetting/fields.yaml index 49424f694..627651951 100644 --- a/modules/backend/models/editorsetting/fields.yaml +++ b/modules/backend/models/editorsetting/fields.yaml @@ -106,16 +106,28 @@ tabs: size: small span: auto + html_paragraph_formats: + label: backend::lang.editor.paragraph_formats + comment: backend::lang.editor.paragraph_formats_comment + tab: backend::lang.editor.toolbar_options + type: datatable + span: right + columns: + format_tag: + title: backend::lang.editor.markup_tag + format_label: + title: backend::lang.editor.label + html_toolbar_buttons: label: backend::lang.editor.toolbar_buttons comment: backend::lang.editor.toolbar_buttons_comment - tab: backend::lang.editor.toolbar_buttons + tab: backend::lang.editor.toolbar_options type: textarea span: left _html_toolbar_buttons_presets: label: backend::lang.editor.toolbar_buttons_preset - tab: backend::lang.editor.toolbar_buttons + tab: backend::lang.editor.toolbar_options type: partial path: ~/modules/backend/models/editorsetting/_toolbar_presets.htm span: left