My goal is simple, I'd like to use the LinkControl element on an admin page rendered by my plugin. Using the LinkControl on the BlockEditor page is quite easy the issue is doing it without being inside the Edit/Save functions of a custom block.
These are the steps I did:
- On the php of my custom admin page I included the scripts:
['wp-blocks', 'wp-block-editor', 'wp-element']
- I also included my script
admin.js
using thewp_enqueue_scripts
- Inside main.js I have:
wp.element.render(
wp.element.createElement( wp.blockEditor.__experimentalLinkControl,{
onChange:function(value){console. Debug(value);},
showSuggestions:true,
value:{url:'test'}
} ),
document.getElementById( 'my_linkcontrol' )
);
The LinkControl shows but doesn't suggest any entries when you write something. I assume it has something to do with block editor settings: __experimentalFetchLinkSuggestions
Update:As explained on this git issue LinkControl calls a function specified on the editor-block settings to fetch the suggestions (that's why <LinkControl />
works on a custom block edit.js) :
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
initializeEditor( id, settings ) {
settings.__experimentalFetchLinkSuggestions = ( search, searchOptions )
=> fetchLinkSuggestions( search, searchOptions, settings );
This is called when intatiating the block-editor but I can't do that with my code. How can I specify editor settings if I'm not loading the editor, only <LinkControl />
like this