How to use the @wordpress/editor.cleanForSlug function in @wordpress/editor

To help you get started, we’ve selected a few @wordpress/editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / block-library / src / template-part / edit / placeholder.js View on Github external
const onChooseOrCreate = useCallback( async () => {
		const nextAttributes = { slug, theme };
		if ( postId !== undefined && postId !== null ) {
			// Existing template part found.
			nextAttributes.postId = postId;
		} else {
			// Create a new template part.
			try {
				const cleanSlug = cleanForSlug( slug );
				const templatePart = await saveEntityRecord(
					'postType',
					'wp_template_part',
					{
						title: cleanSlug,
						status: 'publish',
						slug: cleanSlug,
						meta: { theme },
					}
				);
				nextAttributes.postId = templatePart.id;
			} catch ( err ) {
				setHelp( __( 'Error adding template.' ) );
			}
		}
		setAttributes( nextAttributes );
github WordPress / gutenberg / packages / edit-site / src / components / add-template / index.js View on Github external
}, [ slug, onRequestClose ] );
	return (
		! slugs.loading &&
		isOpen && (
			
				<div>
					
					<button disabled="{">
						{ __( 'Add' ) }
					</button>
				</div>
			
		)
	);
}
github Yoast / wordpress-seo / js / src / structured-data-blocks / inner-blocks / step / Step.js View on Github external
setTitle( title ) {
		this.props.setAttributes( {
			title,
			id: cleanForSlug( title ),
		} );
	}
github WordPress / gutenberg / packages / block-library / src / post-title / edit.js View on Github external
onChange={ ( value ) => {
					setTitle( value );
					setSlug( cleanForSlug( value ) );
				} }
				allowedFormats={ [] }
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / post-link / index.js View on Github external
isOpened,
	onTogglePanel,
	isEditable,
	postLink,
	permalinkParts,
	editPermalink,
	forceEmptyField,
	setState,
	postTitle,
	postSlug,
	postID,
	postTypeLabel,
} ) {
	const { prefix, suffix } = permalinkParts;
	let prefixElement, postNameElement, suffixElement;
	const currentSlug = safeDecodeURIComponent( postSlug ) || cleanForSlug( postTitle ) || postID;
	if ( isEditable ) {
		prefixElement = prefix &amp;&amp; (
			<span>{ prefix }</span>
		);
		postNameElement = currentSlug &amp;&amp; (
			<span>{ currentSlug }</span>
		);
		suffixElement = suffix &amp;&amp; (
			<span>{ suffix }</span>
		);
	}

	return (
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / post-link / index.js View on Github external
onBlur={ ( event ) => {
							editPermalink( cleanForSlug( event.target.value ) );
							if ( forceEmptyField ) {
								setState( {
									forceEmptyField: false,
								} );
							}
						} }
					/>
github WordPress / gutenberg / packages / block-library / src / template-part / edit / placeholder.js View on Github external
const setSlug = useCallback( ( nextSlug ) => {
		_setSlug( nextSlug );
		setHelp( cleanForSlug( nextSlug ) );
	}, [] );
github Yoast / wordpress-seo / js / src / structured-data-blocks / inner-blocks / question / Question.js View on Github external
setTitle( title ) {
		this.props.setAttributes( {
			title,
			id: cleanForSlug( title ),
		} );
	}
github WordPress / gutenberg / packages / edit-site / src / components / add-template / index.js View on Github external
const add = useCallback( async () => {
		_setSlug( '' );
		const cleanSlug = cleanForSlug( slug );

		try {
			const template = await saveEntityRecord( 'postType', 'wp_template', {
				title: cleanSlug,
				status: 'publish',
				slug: cleanSlug,
			} );
			onAddTemplateId( template.id );
			onRequestClose();
		} catch ( err ) {
			setHelp( __( 'Error adding template.' ) );
		}
	}, [ slug, onRequestClose ] );
	return (
github WordPress / gutenberg / packages / edit-site / src / components / add-template / index.js View on Github external
( nextSlug ) => {
			_setSlug( nextSlug );
			const cleanSlug = cleanForSlug( nextSlug );
			setHelp(
				slugs[ cleanSlug ] ?
					__( 'Template already exists, edit it instead.' ) :
					cleanSlug
			);
		},
		[ slugs ]