Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings to enable visual or text editor for TinyMCE #6179

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
36 changes: 30 additions & 6 deletions classes/fields/wysiwyg.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,25 @@ public function options() {
'dependency' => true,
),
'editor_options' => array(
'label' => __( 'Editor Options', 'pods' ),
'type' => 'boolean_group',
'depends-on' => array( static::$type . '_editor' => 'tinymce' ),
'boolean_group' => array(
'label' => __( 'Editor Options', 'pods' ),
'type' => 'boolean_group',
'depends-on' => array( static::$type . '_editor' => 'tinymce' ),
'boolean_group' => array(
static::$type . '_media_buttons' => array(
'label' => __( 'Enable Media Buttons', 'pods' ),
'default' => 1,
'type' => 'boolean',
),
static::$type . '_tinymce' => array(
'label' => __( 'Enable TinyMCE (Visual)', 'pods' ),
'default' => 1,
'type' => 'boolean',
),
static::$type . '_quicktags' => array(
'label' => __( 'Enable Quicktags (Text)', 'pods' ),
'default' => 1,
'type' => 'boolean',
),
),
),
static::$type . '_editor_height' => array(
Expand Down Expand Up @@ -257,8 +267,22 @@ public function input( $name, $value = null, $options = null, $pod = null, $id =
} elseif ( 'tinymce' === pods_v( static::$type . '_editor', $options ) ) {
$field_type = 'tinymce';

// Enforce boolean.
$options[ static::$type . '_media_buttons' ] = filter_var( pods_v( static::$type . '_editor', $options, true ), FILTER_VALIDATE_BOOLEAN );
// Set defaults if they were not set before (for new options added since field was in use).
$options[ static::$type . '_tinymce' ] = pods_v( static::$type . '_tinymce', $options, true );
$options[ static::$type . '_quicktags' ] = pods_v( static::$type . '_quicktags', $options, true );

if ( '' === $options[ static::$type . '_tinymce' ] ) {
$options[ static::$type . '_tinymce' ] = true;
}

if ( '' === $options[ static::$type . '_quicktags' ] ) {
$options[ static::$type . '_quicktags' ] = true;
}

// Enforce booleans.
$options[ static::$type . '_media_buttons' ] = filter_var( pods_v( static::$type . '_media_buttons', $options, true ), FILTER_VALIDATE_BOOLEAN );
$options[ static::$type . '_tinymce' ] = filter_var( $options[ static::$type . '_tinymce' ], FILTER_VALIDATE_BOOLEAN );
$options[ static::$type . '_quicktags' ] = filter_var( $options[ static::$type . '_quicktags' ], FILTER_VALIDATE_BOOLEAN );

wp_tinymce_inline_scripts();
wp_enqueue_editor();
Expand Down
2 changes: 1 addition & 1 deletion ui/js/blocks/pods-blocks-api.min.asset.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"dependencies":["wp-api-fetch","wp-autop","wp-block-editor","wp-blocks","wp-components","wp-compose","wp-date","wp-element","wp-i18n","wp-keycodes","wp-server-side-render","wp-url"],"version":"1ae572d3f990891697f42359d4789570"}
{"dependencies":["wp-api-fetch","wp-autop","wp-block-editor","wp-blocks","wp-components","wp-compose","wp-date","wp-element","wp-i18n","wp-keycodes","wp-server-side-render","wp-url"],"version":"eee47e8051ea21b3ee6a152dd4851aad"}
1,270 changes: 1,269 additions & 1 deletion ui/js/blocks/pods-blocks-api.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/js/dfv/pods-dfv.min.asset.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"dependencies":["moment","wp-api-fetch","wp-autop","wp-components","wp-compose","wp-data","wp-element","wp-i18n","wp-keycodes","wp-plugins","wp-primitives","wp-url"],"version":"24a252ba15d83803f1b7826ab7b44b4c"}
{"dependencies":["moment","wp-api-fetch","wp-autop","wp-components","wp-compose","wp-data","wp-element","wp-i18n","wp-keycodes","wp-plugins","wp-primitives","wp-url"],"version":"c469aceb94e7980870ea6c5c1fdb8067"}
7,370 changes: 7,369 additions & 1 deletion ui/js/dfv/pods-dfv.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion ui/js/dfv/src/config/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,9 @@ export const FIELD_PROP_TYPE = {
wysiwyg_convert_chars: PropTypes.string,
wysiwyg_editor: PropTypes.string,
wysiwyg_editor_height: NUMBER_OR_NUMBER_AS_STRING,
wysiwyg_media_buttons: PropTypes.string,
wysiwyg_media_buttons: BOOLEAN_ALL_TYPES,
JoryHogeveen marked this conversation as resolved.
Show resolved Hide resolved
wysiwyg_tinymce: BOOLEAN_ALL_TYPES,
wysiwyg_quicktags: BOOLEAN_ALL_TYPES,
wysiwyg_oembed: PropTypes.string,
wysiwyg_repeatable: BOOLEAN_ALL_TYPES,
wysiwyg_wpautop: PropTypes.string,
Expand Down
4 changes: 4 additions & 0 deletions ui/js/dfv/src/fields/wysiwyg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const Wysiwyg = ( props ) => {
wysiwyg_editor: editor = 'tinymce',
wysiwyg_editor_height: editorHeight = 400,
wysiwyg_media_buttons: mediaButtons,
wysiwyg_tinymce: enableTinyMCE,
wysiwyg_quicktags: enableQuicktags,
} = fieldConfig;

if ( 'quill' === editor || 'cleditor' === editor ) {
Expand Down Expand Up @@ -73,6 +75,8 @@ const Wysiwyg = ( props ) => {
setValue={ setValue }
editorHeight={ parseInt( editorHeight, 10 ) }
mediaButtons={ toBool( mediaButtons ) }
enableQuicktags={ toBool( enableQuicktags ) }
enableTinyMCE={ toBool( enableTinyMCE ) }
onBlur={ () => setHasBlurred() }
/>
);
Expand Down
17 changes: 16 additions & 1 deletion ui/js/dfv/src/fields/wysiwyg/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const TinyMCE = ( {
setValue,
editorHeight,
mediaButtons,
enableTinyMCE,
enableQuicktags,
onBlur,
} ) => {
const fieldId = `pods-form-ui-${ name }`;
Expand Down Expand Up @@ -99,6 +101,17 @@ const TinyMCE = ( {
settings.toolbar4 = settings.toolbar4.replace( 'wp_add_media,', '' ).replace( ',wp_add_media', '' ).replace( 'wp_add_media', '' );
}

if ( ! enableTinyMCE && ! enableQuicktags ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to address other areas like in onSetup and the first useEffect perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically checking enableTinyMCE before calling other tinymce/editor specific functions elsewhere in this file

// Plain paragraph.
return;
}

if ( ! enableTinyMCE ) {
// Quicktags only.
window.quicktags( { ...wp.oldEditor.getDefaultSettings().quicktags, id: fieldId } );
return;
}

window.wp.oldEditor.initialize( fieldId, {
tinymce: {
...settings,
Expand All @@ -107,7 +120,7 @@ const TinyMCE = ( {
height: editorHeight,
},
mediaButtons,
quicktags: true,
quicktags: enableQuicktags,
} );
}

Expand Down Expand Up @@ -154,6 +167,8 @@ TinyMCE.propTypes = {
setValue: PropTypes.func.isRequired,
editorHeight: PropTypes.number,
mediaButtons: PropTypes.bool,
enableTinyMCE: PropTypes.bool,
enableQuicktags: PropTypes.bool,
onBlur: PropTypes.func.isRequired,
};

Expand Down