Description
This issue is automatically created based on existing pull request: #28389: Add a head.additional block to adminhtml layout
Module developers are currently able to add external JS files to the admin area's <head>
section, but adding inline scripts is not as straightforward as it is in the Frontend area because the admin layout doesn't define the head.additional
block. In fact, I couldn't find a way to add inline scripts to the head in a way that's not "hackish" and remains compatible with other modules. The mechanism to do this easily is simply missing.
This PR addresses the mechanism issue: once this block is added \Magento\Framework\View\Result\Page
will make sure all head.additional
child blocks are rendered, mirroring the functionality in the Frontend area.
Preconditions: (*)
This PR simply adds a head.additional
block of type \Magento\Framework\View\Element\Text\ListText
to the Adminhtml's default
layout (via magento2/module-base
).
Related Pull Requests
None
Fixed Issues (if relevant)
I couldn't find any.
Steps to reproduce (*)
- Create a module that adds the following layout update in the adminhtml area:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="head.additional">
<block class="Magento\Framework\View\Element\Template" name="test"
template="Magento_Backend::page/copyright.phtml"/>
</referenceBlock>
</page>
- Run:
php bin/magento cache:clean
; - Go to Admin and view page source;
Actual Result: ✖️ no copyright text in the <head>
Expected Result: ✔️ The copyright text rendered within any admin page's area
Other / Reasoning
Why a ListText
block?
- Because a
container
renders its children within a tag, and we don't want that insidehead
. - Because in the Frontend area this is done with a
Template
block with acontainer.phtml
template is used, but that template doesn't exist in the adminhtml area. - Because
ListText
simply gets the job done exactly as it's supposed to and without any side-effects.
Backwards Compatibility
This change adds a new block to an existing layout and therefore shouldn't break backwards compatibility with any existing code.
Automated tests?
I'd be happy to create them if you really think it's necessary but I'll need a bit of guidance. However, I also doubt this is the kind of things we're testing, because existing tests for \Magento\Framework\View\Result\Page
and \Magento\Framework\View\Result\Page
would essentially cover most (if not all) requirements for this functionality.
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- All automated tests passed successfully (all builds are green)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status