You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
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:
29
29
30
30
* A loader.
31
-
* An XSD schema.
32
-
* Any other classes required for your new type to work.
31
+
* An XSD schema file.
33
32
* 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.
34
34
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.
If new modules have a `search.xml` file, they will be merged with your file when it loads.
52
37
53
-
*`$defaultScope`. Defines the configuration scope to be read by default. The default value for this parameter is global scope.
38
+
### Examples of use
54
39
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:
56
41
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`
58
45
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.
@@ -83,12 +70,35 @@ The following example from the Magento_Sales module's [di.xml]({{ site.mage2blob
83
70
</type>
84
71
</config>
85
72
```
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
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.
90
101
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.
92
102
93
103
## Validate a configuration type {#config-files-validate}
94
104
@@ -115,4 +125,5 @@ Your IDE can validate your configuration files at both runtime and during develo
After configuration files are merged, the resulting document contains all nodes from the original files.
52
52
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
+
53
56
## Configuration types, objects, and interfaces {#config-files-classes}
54
57
55
58
The following sections provide information about configuration types, their corresponding configuration objects, and interfaces you can use to work with the objects:
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).
117
122
118
123
`Magento\Framework\Config` provides the following interfaces:
0 commit comments