avstudnitz / AvS_ScopeHint2

Magento 2 module for displaying additional information in configuration
157 stars 33 forks source link

\AvS\ScopeHint\Plugin\ConfigFieldPlugin::afterGetComment may get Phrase instead of string #20

Closed dot319 closed 2 years ago

dot319 commented 3 years ago

\AvS\ScopeHint\Plugin\ConfigFieldPlugin::afterGetComment is currently assuming that $result is a string. Actually, it may be a string or a /Magento/Framework/Phrase. Can you update the codebase so that the method returns a Phrase if it receives a phrase? Currently this module is breaking our admin panel, since in \Magento\SharedCatalog\Block\Adminhtml\System\Config\WebsiteRestriction\IsActive::prepareComment the method getText() is called on the result of this method, throwing an error because it's converted from a Phrase to a string in the plugin.

dot319 commented 3 years ago

For example, the following resolves the issue for me:

public function afterGetComment(Subject $subject, $result)
{
    if ($result instanceof \Magento\Framework\Phrase) {
        $phrase = $result;
        $result = $phrase->getText();
        $arguments = $phrase->getArguments();
    }

    if (strlen(trim($result))) {
        $result .= '<br />';
    }
    $result .= __('Path: <code>%1</code>', $this->getPath($subject));

    if (isset($phrase)) {
        $result = new \Magento\Framework\Phrase(
            $result,
            $arguments
        );
    }

    return $result;
}