This is a replicate of issue
#3502881for Mercury Editor
🐛
Other WYSIWYG fields incorrectly defaulting to “basic_html” Text Format for Non-Admin Users
Active
––––––––––––––––––
On our site, we have content types using a WYSIWYG fields that are not part of the Mercury Editor. These fields are configured to use a custom text format (e.g. 'basic_wysiwyg'). The out-of-the-box basic_html text format has been removed from the site entirely. While the admin (user 1) can save and edit these fields without issue, all other users encounter the following error when attempting to edit the node:
“This field has been disabled because you do not have sufficient permissions to edit it.”
Steps to Reproduce
1. Configure a WYSIWYG field on a content type to use a custom text format (e.g., basic_wysiwyg).
2. Remove the basic_html text format from the site.
3. Allow non-admin users to create and edit nodes for this content type.
4. As a non-admin user, save the node.
5. Attempt to edit the node again.
Expected Behaviour
The WYSIWYG field should retain the set text format (e.g., basic_wysiwyg) and remain editable for users with the required permissions.
Actual Behaviour
When a non-admin user edits the node, the WYSIWYG field is disabled, displaying the error:
“This field has been disabled because you do not have sufficient permissions to edit it.”
Upon inspection, the text format is incorrectly set to basic_html, causing the error.
Root Cause
The issue appears to stem from the getElementFormat()
method within the MercuryEditorInlineEditorFormattedText
class:
protected function getElementFormat(array $element): string {
return $element[0]['#format'] ?? 'basic_html';
}
Assumption of basic_html: This method defaults the text format to basic_html if no format is explicitly provided. However, this assumption is invalid if basic_html is not available on the site.
Failure to Save Allowed Formats: It seems that with the Mercury Editor enabled on the node, despite not being required for the field in question, the text format defined for the field during node creation is not correctly saved, resulting in the incorrect fallback.
Proposed Solution
Part of the solution should update the getElementFormat()
method to use the field’s allowed formats or an explicit default format, rather than assuming basic_html. If anything, the fallback should be plain_text.