integer-net / magento2-global-custom-layout

integer-net/magento2-global-custom-layout

Module for Magento 2 that allows you to add global layout update files to be selected from admin, by using '0' instead of an entity_id

  • Willem Wigman
magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: Fail Security: Pass MIT

Integer_Net GlobalCustomLayout

Latest Version on Packagist
Software License
Build Status
Coverage Status
Quality Score

Allows you to add global layout update files to be selected from admin, by using 0 instead of a category_id / sku / url_path.

Compatible with Magento 2.3.4 and higher, since cms-page/product/category specific layouts where introduced in this version.

Purpose

In Magento 2.3.4, xml layout updates were removed from the Magento Admin, for security reasons.
Previously this textfield allowed you to add XML Layout updates to any given Category, Product or CMS Page.
After the update, this textfield is no longer available, but you can select custom layout updates which are defined in xml layout files in the filesystem.

After uploading/deploying selectable layout files onto your project's filesystem, these layouts can be selected from the admin under the Design section.
The field is called Custom Layout Update.

Usage:

Replace identifiers in selectable layouts with a 0 (zero).
Add layout file to themes/modules using:

  • catalog_category_view_selectable_0_<Layout Update Name>.xml for Categories
  • catalog_product_view_selectable_0_<Layout Update Name>.xml for Products
  • cms_page_view_selectable_0_<Layout Update Name>.xml for Cms pages

These files can go anywhere where you'd normally put layout files. For example:
app/design/frontend/[Theme_Vendor]/[Theme_Name]/Magento_Theme/layout/catalog_category_view_0_customchanges.xml

You can now select the layout update at any given Category/Product/Page, under Custom layout update field of Design.

More info on default behaviour of selectable layouts:
Magento DevDocs: Create cms-page/product/category-specific layouts

Installation

  1. Install via composer
    composer require integer-net/magento2-global-custom-layout
    
  2. Enable module
    bin/magento setup:upgrade
    

Configuration

Zero configuration needed.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

Magento Integration Tests

  1. Configure test database in dev/tests/integration/etc/install-config-mysql.php. Read more in the Magento docs.

  2. Copy Test/Integration/phpunit.xml.dist from the package to dev/tests/integration/phpunit.xml in your Magento installation.

  3. In that directory, run

    ../../../vendor/bin/phpunit
    

Contributing

Please see CONTRIBUTING for details.

Known issues

  1. Does not work with the homepage (cms_index_index). But hey, it doesn't in the default Magento implementation either.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog
and this project adheres to Semantic Versioning.

1.0.0 - 2020-04-27

Added

  • Plugins for category, product and page layouts that allow custom layout files to be loaded with a global identifier
    (0). E.g. catalog_category_view_selectable_0_.xml for Categories.

1.1.0 - 2020-05-02

Added

  • Adds frontend test coverage for global custom layout updates
  • Fixes #7 where layout handles were not merged in Product and Page Plugins' afterFetchAvailableFiles() method.

1.1.1 - 2020-05-08

Added

  • Adds module registration test (registration.php coverage)
  • Adds travis config for tags/releases

1.1.2 - 2020-05-11

Added

  • Updates travis, magento 2.4-dev now requires elasticsearch
  • Adds return type declaration (void) to setUp() functions, now needed for magento 2.4
Versions
Version Stability QA Status Compatibility Released
1.1.2 stable Fail Magento 2.4.7-2.4.9 Details 2020-05-11 19:31:21
1.1.1 stable Not tested Not yet tested Details 2020-05-08 13:04:15
1.1.0 stable Not tested Not yet tested Details 2020-05-05 09:32:41
1.0.0 stable Not tested Not yet tested Details 2020-04-27 14:19:34

Requires 4

Package Constraint
magento/framework >=102.0.4
magento/module-catalog >=103.0.4
magento/module-cms >=103.0.4
php >=7.1.0

Requires-dev 1

Package Constraint
magento/magento-coding-standard @dev

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — a phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Warning 29 29 warnings (ruleset: Magento2) — 20 auto-fixable with phpcbf
PHPMD Warning 4 4 rule violations (IfStatementAssignment:4)
Cpd Warning 1 1 duplicated chunk spanning 68 total lines (min-lines=5, min-tokens=70)
Composer validate Info 4 valid; 4 advisory notes (composer validate --strict)

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 8 8
2.4.8 8 8
2.4.9 8 8

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 Error Error
2.4.9 Error not tested

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
MIT
Authors

More from integer-net

View vendor
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.