Skip to content

[Issue] Add a head.additional block to adminhtml layout #29165

Closed
@m2-assistant

Description

@m2-assistant

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 (*)

  1. 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>
  1. Run: php bin/magento cache:clean;
  2. Go to Admin and view page source;

Actual Result: ✖️ no copyright text in the <head>

Screenshot from 2020-07-16 11-19-05

Expected Result: ✔️ The copyright text rendered within any admin page's area

2020-07-16_11-21

Other / Reasoning

Why a ListText block?

  1. Because a container renders its children within a tag, and we don't want that inside head.
  2. Because in the Frontend area this is done with a Template block with a container.phtml template is used, but that template doesn't exist in the adminhtml area.
  3. 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

Component: BackendFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P3May be fixed according to the position in the backlog.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions