Skip to content

Commit 787e071

Browse files
committed
feat: add an option in Stackable setting to use unrestricted link control
1 parent 3154353 commit 787e071

4 files changed

Lines changed: 61 additions & 7 deletions

File tree

‎src/components/link-control/editor.scss‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.stk-link-control__input {
22
// Adjust width to ensure reset button is visible.
33
width: calc(100% - 32px);
4+
min-width: 0;
45

56
> .block-editor-link-control {
67
min-width: auto;
@@ -29,6 +30,20 @@
2930

3031
}
3132

33+
> .block-editor-url-input {
34+
min-width: 0;
35+
width: 100%;
36+
37+
.components-base-control {
38+
min-width: 0;
39+
width: 100%;
40+
}
41+
42+
.components-base-control__field {
43+
margin: 0;
44+
}
45+
}
46+
3247
.block-editor-url-input__input {
3348
margin: 0 !important;
3449
width: 100% !important;

‎src/components/link-control/index.js‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* External dependencies
33
*/
4+
import { settings } from 'stackable'
45
import classnames from 'classnames'
56

67
/**
78
* WordPress dependencies
89
*/
910
import {
11+
URLInput,
1012
__experimentalLinkControl as _LinkControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis
1113
} from '@wordpress/block-editor'
1214
import { BaseControl as _BaseControl } from '@wordpress/components'
@@ -25,6 +27,7 @@ const LinkControl = props => {
2527
const [ propsToPass, controlProps ] = extractControlProps( props )
2628
const {
2729
isDynamic,
30+
showSuggestions,
2831
...inputProps
2932
} = propsToPass
3033

@@ -33,6 +36,8 @@ const LinkControl = props => {
3336

3437
const dynamicContentProps = useDynamicContentControlProps( { value, onChange } )
3538

39+
const useUnrestrictedURLInput = !! settings.stackable_enable_unrestricted_url_input
40+
3641
const classNames = classnames( [
3742
'stk-link-control',
3843
props.className,
@@ -48,13 +53,22 @@ const LinkControl = props => {
4853
{ ...dynamicContentProps }
4954
>
5055
<div className="stk-link-control__input">
51-
<_LinkControl
52-
{ ...inputProps }
53-
value={ { url: value } }
54-
onChange={ ( { url } ) => onChange( url ) }
55-
settings={ [] } // The Url only.
56-
forceIsEditingLink={ ! value }
57-
/>
56+
{ useUnrestrictedURLInput ? (
57+
<URLInput
58+
{ ...inputProps }
59+
value={ value }
60+
onChange={ onChange }
61+
disableSuggestions={ ! showSuggestions }
62+
/>
63+
) : (
64+
<_LinkControl
65+
{ ...inputProps }
66+
value={ { url: value } }
67+
onChange={ ( { url } ) => onChange( url ) }
68+
settings={ [] } // The Url only.
69+
forceIsEditingLink={ ! value }
70+
/>
71+
) }
5872
</div>
5973
</DynamicContentControl>
6074
<ResetButton

‎src/editor-settings.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ public function register_settings() {
159159
)
160160
);
161161

162+
register_setting(
163+
'stackable_editor_settings',
164+
'stackable_enable_unrestricted_url_input',
165+
array(
166+
'type' => 'boolean',
167+
'description' => __( 'Uses the legacy URL input in Stackable link controls, allowing shortcodes and other dynamic URL values.', STACKABLE_I18N ),
168+
'sanitize_callback' => 'rest_sanitize_boolean',
169+
'show_in_rest' => true,
170+
'default' => false,
171+
)
172+
);
173+
162174
register_setting(
163175
'stackable_editor_settings',
164176
'stackable_help_tooltip_disabled',
@@ -311,6 +323,7 @@ public function add_settings( $settings ) {
311323
$settings['stackable_auto_collapse_panels'] = get_option( 'stackable_auto_collapse_panels' );
312324
$settings['stackable_enable_global_settings'] = get_option( 'stackable_enable_global_settings' );
313325
$settings['stackable_enable_block_linking'] = get_option( 'stackable_enable_block_linking' );
326+
$settings['stackable_enable_unrestricted_url_input'] = get_option( 'stackable_enable_unrestricted_url_input' );
314327
$settings['stackable_enable_text_highlight'] = get_option( 'stackable_enable_text_highlight' );
315328
$settings['stackable_enable_dynamic_content'] = get_option( 'stackable_enable_dynamic_content' );
316329
$settings['stackable_enable_copy_paste_styles'] = get_option( 'stackable_enable_copy_paste_styles' );

‎src/welcome/admin.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const SEARCH_TREE = [
9999
__( 'Stackable Settings', i18n ),
100100
__( 'Use Size Presets by Default', i18n ),
101101
__( 'Block Linking (Beta)', i18n ),
102+
__( 'Use Unrestricted URL Input', i18n ),
102103
],
103104
},
104105
{
@@ -788,6 +789,17 @@ const EditorSettings = props => {
788789
</>
789790
}
790791
/>
792+
<AdminToggleSetting
793+
label={ __( 'Use Unrestricted URL Input', i18n ) }
794+
searchedSettings={ editor.children }
795+
value={ settings.stackable_enable_unrestricted_url_input }
796+
onChange={ value => {
797+
handleSettingsChange( { stackable_enable_unrestricted_url_input: value } ) // eslint-disable-line camelcase
798+
} }
799+
help={ __( 'Uses the legacy URL field in all Stackable link controls. Enable this for shortcodes, template tokens, or other dynamic URL values. This disables Gutenberg URL validation.', i18n ) }
800+
disabled={ __( 'Use Gutenberg URL input', i18n ) }
801+
enabled={ __( 'Use unrestricted URL input', i18n ) }
802+
/>
791803
</div>
792804
}
793805
{ ( toolbar.children === null || toolbar.children.length > 0 ) &&

0 commit comments

Comments
 (0)