Skip to content

Add a head.additional block to adminhtml layout #28389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

gsomoza
Copy link

@gsomoza gsomoza commented May 27, 2020

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.

Description (*)

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.

Manual testing scenarios (*)

  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_Theme::html/copyright.phtml"/>
    </referenceBlock>
</page>
  1. You should see the copyright text rendered within any admin page's <head> area.

(which is invalid HTML but should work as a quick test)

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)

Resolved issues:

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

@m2-assistant
Copy link

m2-assistant bot commented May 27, 2020

Hi @gsomoza. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@gsomoza
Copy link
Author

gsomoza commented May 27, 2020

Note1: this probably shouldn't have the Area: Frontend label.
Note2: assuming you're interested in this PR let me know if you'd like a backport for 2.3.x (although as you can probably see it's quite trivial).

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@ihor-sviziev ihor-sviziev self-assigned this Jun 19, 2020
@ihor-sviziev ihor-sviziev added the Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. label Jun 19, 2020
@ihor-sviziev ihor-sviziev added Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests improvement labels Jun 22, 2020
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7718 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@gsomoza thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@gsomoza
Copy link
Author

gsomoza commented Jun 22, 2020

Done!

@engcom-Alfa
Copy link
Contributor

@magento create issue

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Manual testing scenario:

  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;

Before: ✖️ no copyright text in the <head>

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

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

2020-07-16_11-21

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Sep 14, 2020

@sidolov could you explain why this PR was moved to "pending review" without any comment? Were the additional tests executed? What their result?Can I approve it?

@sidolov
Copy link
Contributor

sidolov commented Sep 14, 2020

@ihor-sviziev I don't see any reason to hold it, I agree with @naydav, additional cases should be verified but we can do that on the QA stage.

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7718 has been created to process this Pull Request

@engcom-Echo engcom-Echo removed their assignment Oct 2, 2020
@engcom-Alfa engcom-Alfa added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Oct 2, 2020
@engcom-Alfa engcom-Alfa removed their assignment Oct 5, 2020
@engcom-Alfa
Copy link
Contributor

Dev experience is required for testing this PR. Please note that Manual testing has not been performed.

@engcom-Foxtrot engcom-Foxtrot self-assigned this Oct 5, 2020
@engcom-Foxtrot
Copy link
Contributor

@magento run all tests

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7718 has been created to process this Pull Request

@m2-assistant
Copy link

m2-assistant bot commented Oct 7, 2020

Hi @gsomoza, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Component: Backend improvement Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Issue] Add a head.additional block to adminhtml layout
10 participants