magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

System.xml comment model not allowed by the validation schema

Open tzyganu opened this issue 12 years ago • 4 comments

I'm trying to add a dynamic comment on a system.xml file.
In magento 1 this was possible by adding this on the field definion

<comment>
    <model>[module]/field_comment</model><!-- this made it dynamic -->
</comment>

and creating the model class [Namespace]_[Module]_Model_Field_Comment that contains a public method getCommentText.
In Magento 2 this is not possible anymore because of the validation schema Magento/Backend/etc/system_file.xsd. In this schema the comment node has the type type="xs:string".
The odd think is that in the code that generates the form the case of a comment model is handled
Magento\Backend\Model\Config\Structure\Element\Field::getComment looks like this:

public function getComment($currentValue = '')
{
    $comment = '';
    if (isset($this->_data['comment'])) {
        if (is_array($this->_data['comment'])) {
            if (isset($this->_data['comment']['model'])) {
                $model = $this->_commentFactory->create($this->_data['comment']['model']);
                $comment = $model->getCommentText($currentValue);
            }
        } else {
            $comment = parent::getComment();
        }
    }
    return $comment;
}

So I guess you can bring back this functionality just by changing the type of the comment node.
Please bring it back. Even if it doesn't sound like much, I've used this a few times to present important messages for the admins directly in the configuration area.

tzyganu avatar Nov 25 '14 08:11 tzyganu

@tzyganu, thank you for your request! We will consider the change you requested and will get back to you once we have a response.

verklov avatar Dec 01 '14 17:12 verklov

Internal ticket: MAGETWO-31251

vpelipenko avatar Jan 29 '15 13:01 vpelipenko

I see that this was merged in the develop branch. Thanks. I will close the issue.

tzyganu avatar Mar 16 '16 07:03 tzyganu

is there any way to create field programically?

i want to add each payment one fee text box.

sunilit42 avatar Apr 08 '16 08:04 sunilit42