- Issue created by @codebymikey
As part the 4.0 roadmap, if the aim is to support "Single field editing" in the future, then I think the editor needs to support cleaning up and detaching the Gutenberg editor from the field in case it's loaded dynamically via AJAX.
Something along the lines of this could be used as a jumping off point:
Drupal.editors.gutenberg.detach = function(element, format, trigger) {
let editor = element.nextElementSibling;
let reactRootContainer;
if (editor && editor.classList.contains('gutenberg__editor') && editor.hasOwnProperty('_reactRootContainer')) {
reactRootContainer = editor._reactRootContainer;
} else {
console.error('Could not detach Gutenberg editor', element);
return false;
}
if (reactRootContainer) {
if (trigger === 'serialize') {
// Update the underlying field value.
// @todo updateSourceElementValue();
} else {
// @todo unmount and revert back to a normal textarea field, as well as all other side-effects.
element.style.display = ''; // @todo this should've been hidden with a class instead.
reactRootContainer.unmount();
}
}
return true;
}
PR/issue forks.
N/A
TBD
Active
3.0
Code