Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit cdcb4c7

Browse files
author
Raul E Watson
committed
#3361 New Configuration Type Topic
1 parent e86cc0f commit cdcb4c7

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

src/guides/v2.3/config-guide/config/config-create.md

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,29 @@ Your new `events.xml` is automatically collected from your module and merged wit
2121

2222
To create new configuration type, you must add at minimum:
2323

24-
* [XML](https://glossary.magento.com/xml) configuration files
25-
* [XSD](https://glossary.magento.com/xsd) validation schema
2624
* A loader
25+
* [XSD](https://glossary.magento.com/xsd) validation schema
26+
* [XML](https://glossary.magento.com/xml) configuration files
2727

2828
For example, to introduce an [adapter](https://glossary.magento.com/adapter) for a new search server that enables extensions to configure how its entities are indexed in that server, create:
2929

3030
* A loader.
31-
* An XSD schema.
32-
* Any other classes required for your new type to work.
31+
* An XSD schema file.
3332
* An appropriately named configuration file. For example, `search.xml`. This file is read and validated against your schema.
33+
* Any other classes required for your new type to work.
3434

35-
If other modules have a `search.xml` file, they are merged with your file when it loads.
36-
37-
To create a new configuration type, extend the `\Magento\Framework\Config\ReaderInterface`, which is [Magento\Framework\Config\Reader\Filesystem]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Reader/Filesystem.php) to provide the following parameters:
38-
39-
* `$fileResolver`. Implements [\Magento\Framework\Config\FileResolverInterface]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/FileResolverInterface.php). This parameter lists the files containing the configurations of your custom type.
40-
* `$converter`. Implements [\Magento\Framework\Config\ConverterInterface]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/ConverterInterface.php). This parameter converts the XML into the internal array representation of the configurations.
41-
* `$schemaLocator`. Implements [\Magento\Framework\Config\SchemaLocatorInterface]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/SchemaLocatorInterface.php). This parameter provides the full path to file(s) containing schema(s) for validation of the individual and merged configuration files.
42-
* `$validationState`. Implements [\Magento\Framework\Config\ValidationStateInterface]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/ValidationStateInterface.php). This parameter defines whether a configuration file should be validated.
43-
* `$fileName`. Name of a configuration file. The Reader looks for the file names specified by this parameter in modules' `etc` directories.
44-
* `$idAttributes`. Array of node attribute IDs.
45-
46-
For example, to merge the XML files:
47-
48-
array(
49-
'</path/to/node>' => '<identifierAttributeName>',
50-
'</path/to/other/node>' => '<identifierAttributeName>',
51-
}
35+
{:.bs-callout-info}
36+
If new modules have a `search.xml` file, they will be merged with your file when it loads.
5237

53-
* `$defaultScope`. Defines the configuration scope to be read by default. The default value for this parameter is global scope.
38+
### Examples of use
5439

55-
After you customize `ReaderInterface`, you can use it to collect, merge, validate, and convert the configuration files to an internal array representation.
40+
To create a new configuration type:
5641

57-
### Examples of use
42+
1. Create your XSD file
43+
2. Create your XML file
44+
3. Define your configuration object in your `di.xml`
5845

59-
The following example from the Magento_Sales module's [di.xml]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Sales/etc/di.xml) illustrates how to create a configuration object.
46+
The following example from the Magento_Sales module's [di.xml]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Sales/etc/di.xml) illustrates how a configuration object should look like.
6047

6148
```xml
6249
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -83,12 +70,35 @@ The following example from the Magento_Sales module's [di.xml]({{ site.mage2blob
8370
</type>
8471
</config>
8572
```
73+
* The first type node sets the Reader's filename, associated `Converter` and `SchemaLocator` classes.
74+
* Then, the `pdfConfigDataStorage` virtual type node attaches the reader class to an instance of [Magento\Framework\Config\Data]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Data.php).
75+
* And finally, the last type node attaches that config data virtual type to the [Magento\Sales\Model\Order\Pdf\Config]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Sales/Model/Order/Pdf/Config.php) class, which is used for actually reading values in from those [pdf.xml]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Sales/etc/pdf.xml) files.
76+
77+
78+
3. Define a reader by extending [Magento\Framework\Config\Reader\Filesystem]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Reader/Filesystem.php) class to provide the following parameters:
79+
80+
{:.bs-callout-info}
81+
You can also implement `ReaderInterface` to create your own version of the reader. For reference see [Magento_Analytics config reader]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Analytics/ReportXml/Config/Reader.php)
82+
83+
```php
84+
namespace Vendor\ModuleName\Model\Config;
85+
86+
class Reader extends \Magento\Framework\Config\Reader\Filesystem
87+
{
88+
/**
89+
* List of identifier attributes for merging
90+
*
91+
* @var array
92+
*/
93+
protected $_idAttributes = [
94+
'</path/to/node_in_your_xml_file>' => '<identifierAttributeName>',
95+
'</path/to/other/node_in_your_xml_file>' => '<identifierAttributeName>',
96+
];
97+
}
98+
```
8699

87-
The first type node sets the Reader's filename, associated `Converter` and `SchemaLocator` classes.
88-
89-
Then, the `pdfConfigDataStorage` virtual type attaches that reader class to an instance of [Magento\Framework\Config\Data]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Data.php).
100+
After define your reader, you can use it to collect, merge, validate, and convert the configuration files to an internal array representation.
90101

91-
And finally, the last type attaches that config data virtual type to the [Magento\Sales\Model\Order\Pdf\Config]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Sales/Model/Order/Pdf/Config.php) class, which is used for actually reading values in from those [pdf.xml]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Sales/etc/pdf.xml) files.
92102

93103
## Validate a configuration type {#config-files-validate}
94104

@@ -115,4 +125,5 @@ Your IDE can validate your configuration files at both runtime and during develo
115125
Related topics
116126

117127
* [Module configuration files]({{ page.baseurl }}/config-guide/config/config-php.html)
128+
* [Configuration file merge]({{ page.baseurl }}/guides/v2.3/config-guide/config/config-files.html#config-files-load-merge-merge)
118129
* [Magento's deployment configuration]({{ page.baseurl }}/config-guide/config/config-php.html)

src/guides/v2.3/config-guide/config/config-files.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Magento's merge algorithm follows:
5050

5151
After configuration files are merged, the resulting document contains all nodes from the original files.
5252

53+
{:.bs-callout-info}
54+
Note that you can use [\Magento\Framework\Config\Reader\Filesystem]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Reader/Filesystem.php) class for debugging and understanding the logic behind [configuration files loader]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Reader/Filesystem.php#L125) and [merge configs]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config/Reader/Filesystem.php#L144) process.
55+
5356
## Configuration types, objects, and interfaces {#config-files-classes}
5457

5558
The following sections provide information about configuration types, their corresponding configuration objects, and interfaces you can use to work with the objects:
@@ -113,7 +116,9 @@ Configuration file|Description|Stage|Configuration object
113116

114117
### Configuration interfaces {#config-files-classes-int}
115118

116-
You can interact with configuration files using interfaces under [Magento\Framework\Config]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config). You can also use these interfaces if you create new configuration types.
119+
You can interact with configuration files using interfaces under [Magento\Framework\Config]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Config).
120+
121+
You can also use these interfaces if you [create new configuration types]({{ page.baseurl }}/config-guide/config/config-create.html#config-files-extend-create-create).
117122

118123
`Magento\Framework\Config` provides the following interfaces:
119124

0 commit comments

Comments
 (0)