• Resolved 1benk1

    (@1benk1)


    Hello,
    I have built an custom gutenberg block and using the URLInput class from wp.editor for searching posts.

    But in my custom block I need the id instead the url of the selected post.
    Ok, my first thought was to override the method selectLink in this way:

    const { PlainText, URLInput } = wp.editor;
    
    URLInput.selectLink = function( post ) {
    	this.props.onChange( post.id, post );
    	this.setState( {
    		selectedSuggestion: null,
    		showSuggestions: false,
    	} );
    }

    Unfortunately still the url is taken ??
    For testing the rest of my code I have modified the file wp-includes/js/dist/editor.min.js and replaced post.url with post.id within the orginal method and everything works fine.

    Can anyone give me some hint?

    Best regards,
    Ben

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter 1benk1

    (@1benk1)

    I solved the problem and change the onChange within <URLInput>:

    <URLInput
    	value={ url }
    	onChange={ ( value, post ) => {
    			setAttributes( { url: value } );
    			if ( post && post.hasOwnProperty( 'id' ) ) {
    				setAttributes( { id: post.id } );
    			}
    		}
    	}
    />

    Because in case of select a link, the second argument is defined and containts the id ??

Viewing 1 replies (of 1 total)
  • The topic ‘How to override a method of editor.js within custom block?’ is closed to new replies.