1

Is it possible to use PHP class constants as values in the config.xml file?

For example, if we have this config.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <custommodule>
            <settings>
                <is_active>1</is_active>
                <mode>MODE</mode>
                <send_notification_email>0</send_notification_email>
            </settings>
        </custommodule>
    </default>
</config>

I would like to use a PHP class constant to output the value for the "mode". Is there a way to achieve this?

-1

This should be possible using PHPs constant method.

Something like this:

$configValue = $this->scopeConfig->getValue(
   'custommodule/settings/mode',
   ScopeInterface::SCOPE_STORE
);

$constantValue = constant($configValue);
1
  • I think the OP is asking how to use an existing class constant as the value in the XML. Ie something like <mode>Vendor\MyModule\Model\MyModel::MODE_VALUE</mode>, which for the record, doesn't work. – Dom Oct 31 '20 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.