Feature : Toggle to prevent inline JS #75456
Open
+30
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
disableInlineScriptattribute to the Categories block that allows developers to prevent the injection of inline JavaScript when using the block in dropdown mode. This provides better control over the block's output, especially when using block variations or custom navigation implementations.Why?
With the growing use of block variations and custom block implementations, developers often need to use the Categories block as a primitive building block. Currently, when displaying terms as a dropdown, the block automatically injects an inline script tag that handles client-side navigation. This can be problematic when:
The current workaround of manually removing the inline script is cumbersome and unreliable. This PR provides a clean, supported way to disable the inline script injection.
How?
The implementation adds a new optional attribute
disableInlineScript(boolean, defaults tofalse) to maintain backward compatibility:block.json): Added the newdisableInlineScriptattribute with default valuefalseedit.js): Added a toggle control in the block inspector that appears when "Display as dropdown" is enabled, allowing users to disable inline scriptsindex.php): Modified the render function to check thedisableInlineScriptattribute before injecting the inline JavaScript. When the attribute istrue, the script tag is omitted from the outputThe changes are backward compatible - existing blocks will continue to work as before since the default value is
false.Testing Instructions
Basic Testing
<script>tag should be present after the</select>tagControl Test (Default Behavior)
<script>tag should be present after the<select>element, enabling client-side navigationBlock Variation Testing (Developer Scenario)
Additional Notes
falseensures existing blocks continue to work as beforedisplayAsDropdownis enabled