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

feat/3279 default block text #3283

Merged
merged 8 commits into from
Sep 5, 2024
13 changes: 13 additions & 0 deletions src/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ public function register_settings() {
'default' => true,
)
);

register_setting(
'stackable_editor_settings',
'stackable_text_default_block',
array(
'type' => 'boolean',
'description' => __( 'If this is enabled, the default block when adding a new block will be the Stackable Text block.', STACKABLE_I18N ),
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'default' => false,
)
);
}

public function sanitize_array_setting( $input ) {
Expand All @@ -174,6 +186,7 @@ public function add_settings( $settings ) {
$settings['stackable_auto_collapse_panels'] = get_option( 'stackable_auto_collapse_panels' );
$settings['stackable_enable_block_linking'] = get_option( 'stackable_enable_block_linking' );
$settings['stackable_enable_carousel_lazy_loading'] = get_option( 'stackable_enable_carousel_lazy_loading' );
$settings['stackable_text_default_block'] = get_option( 'stackable_text_default_block' );
return $settings;
}

Expand Down
9 changes: 9 additions & 0 deletions src/plugins/global-settings/editor-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import './block-defaults'
*/
import { useDeviceType } from '~stackable/hooks'
import { createRoot } from '~stackable/util'
import { settings } from 'stackable'

/** WordPress dependencies
*/
Expand All @@ -22,6 +23,7 @@ import { useEffect } from '@wordpress/element'
import { __ } from '@wordpress/i18n'
import { useSelect } from '@wordpress/data'
import domReady from '@wordpress/dom-ready'
import { setDefaultBlockName } from '@wordpress/blocks'

const GlobalSettingsLoader = () => {
const deviceType = useDeviceType()
Expand Down Expand Up @@ -64,4 +66,11 @@ domReady( () => {
document?.body?.appendChild( globalColorWrapper )
createRoot( globalTypographyWrapper ).render( <GlobalTypographyStyles /> )
createRoot( globalColorWrapper ).render( <GlobalColorStyles /> )

// Set the default block to stackable/text
if ( settings.stackable_text_default_block ) {
setTimeout( () => {
setDefaultBlockName( 'stackable/text' )
} )
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding it here in the global settings, you can create your own "default-text-block" plugin and register it using registerPlugin

} )
14 changes: 14 additions & 0 deletions src/welcome/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,20 @@ const EditorSettings = () => {
} }
help={ __( 'Disable this if you encounter layout or spacing issues when using images inside carousel-type blocks because of image lazy loading.', i18n ) }
/>
<AdminToggleSetting
label={ __( 'Stackable Text as Default Block', i18n ) }
value={ settings.stackable_text_default_block }
onChange={ value => {
setIsBusy( true )
const model = new models.Settings( { stackable_text_default_block: value } ) // eslint-disable-line camelcase
model.save().then( () => setIsBusy( false ) )
setSettings( {
...settings,
stackable_text_default_block: value, // eslint-disable-line camelcase
} )
} }
help={ __( 'If this is enabled, the default block when adding a new block will be the Stackable Text block.', i18n ) }
bfintal marked this conversation as resolved.
Show resolved Hide resolved
/>
{ isBusy &&
<div className="s-absolute-spinner">
<Spinner />
Expand Down
Loading