Collecting XML Theme Files in Magento 2

Jun 27, 2017213Denis 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

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:

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

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.

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/*

Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Igor

2 Comments

Post a new comment

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