Get Free Audit

Collecting XML Theme Files in Magento 2

Jun 27, 2017

1335 Denis Natalevich

Collecting XML Theme Files in Magento 2

In order to get onto the issue, let’s have a look at the method loadFileLayoutUpdatesXml() of the class Magento\Framework\View\Model\Layout\Merge.



As for me, I use Magento 2.1.7, so in the picture, we can see the variable $theme that contains theme data. In my case, there are data concerning default theme “Magento Luma”.

Collecting XML theme files in Magento 2__1


Igor Dragun

Partner With Us

Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

On the stage, we get all XML files with the help of the method getFiles placed in the class \lib\internal\Magento\Framework\View\Layout\File\Collector\Aggregated. Let’s have a closer look at the method to comprehend how it works.


Here we create a list where pathways should be added to XML files. As before, it’s not clear where Magento finds XML files. Let’s define what is the method getFiles of the class /lib/internal/Magento/Framework/View/File/Collector/Decorator/ModuleDependency makes:


As you can see, the method is considered as significant and simple. So we should learn one more method getFiles of the class /lib/internal/Magento/Framework/View/File/Collector/Decorator/ModuleOutput:

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor


magento development services

Magento 2 Development

Take your online store to the next level with BelVG Magento 2 Development

Visit the page

As it is mentioned in the code, from the list of all modules we leave only active. Let’s continue reviewing the method getFiles of the class Magento/Framework/View/File/Collector/Base:


Here we can find something interesting. Let’s learn how XML files are collected:


Where:

$area – frontend
$this->subDir – ui_componen/
$filePath – etc/definition.xml

First of all, we get the XML file of the pathway “view/base/ui_componen/etc/definition.xml”. Then it’s necessary to get the XML file of the pathway “view/frontend/ui_componen/etc/definition.xml”.

The method collectFilesWithContext of the class Magento\Framework\Component\DirSearch gets the list of files in the definite directory back. Even a needed file can be given back, as in our case. As a result, we have “view/base/ui_component/etc/definition.xml” file in $sharedFiles array. While $themeFiles array is empty, as the file has not been created on the way. Therefore, we get a file where all UI components have a base declaration.

magento webdesign

Magento Webdesign

Take your online store to the next level with BelVG Magento webdesign

Visit the page

It’s high time to return to the method _loadFileLayoutUpdatesXml we started with. The following line is in it:


Since we know the whole pathway consisting of some getFiles methods, let’s jump of Magento/Framework/View/File/Collector/Base::getFiles

Now we get XML of not a definite XML file, but all XML files in the directory “view/base/layout/”.

Let’s have a look at the screenshots and define what is contained in $sharedFiles:

Collecting XML theme files in Magento 2__2

As a result, we get XML files of the directory “view/frontend/layout/”. Let’s look at the second screenshot and define what is contained in $themeFiles:

Collecting XML theme files in Magento 2__3

We have all xml files of the theme. Let’s summarize which files we’ve got for further processing:

  • <Magento_Theme_module_dir>/view/base/ui_component/etc/definition.xml
  • <Magento_Theme_module_dir>/view/frontend/ui_component/etc/definition.xml
  • <Magento_Theme_module_dir>/view/base/layout/*
  • <Magento_Theme_module_dir>/view/frontend/layout/*
magento custom development

Magento Custom Development

Take your online store to the next level with BelVG Magento Custom Development

Visit the page
Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

2 Comments

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *