1. Documentation
In order to use the functionality follow these steps:
- create adminhtml/system.xml file in the Magento module
- reference or create some section and group of the system config
- add field with the all the required nodes. Add following sub-node to the field<comment model=“ModelFQN” … />
- create ModelFQN which implements Magento\Config\Model\Config\CommentInterface.
Return string out ofgetCommentText()
which will show up in the comment section.
Example:
system.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="dev">
<group id="debug">
<field id="graphql_enabled" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Sample</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment model="Magento\Sample\Model\Comment" />
</field>
</group>
</section>
</system>
</config>
Model:
namespace Magento\Sample\Model;
use \Magento\Config\Model\Config\CommentInterface;
class Comment implements CommentInterface
{
public function getCommentText($elementValue) //the method has to be named getCommentText
{
//do some calculations here
return $elementValue . 'Some string based on the calculations';
}
}
2. Usage
The core modules never use it.
3. Availability
The system.xml
schema allows the model
attribute since Magento 2.1.0.
https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Config/etc/system.xsd#L453-L466
https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Config/etc/system.xsd#L345-L348
It is not available in the Magento 2.0.x versions (even in the latest Magento 2.0.14)
https://github.com/magento/magento2/blob/2.0.14/app/code/Magento/Config/etc/system.xsd#L132-L132
4. Implementation
It is possible because of the Magento\Config\Model\Config\Structure\Element\Field::getComment()
implementation:
https://github.com/magento/magento2/pull/2626