Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Magento 2 (almost) all arguments listed in xml files have an attribute xsi:type that determine how the value of the argument is iterpreted.
For example, in di.xml file of the backend module there is this:

<argument name="scopeType" xsi:type="const">Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT</argument>

this means that the value of the argument scopeType is the value of the constant Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT

or this one

<argument name="template" xsi:type="string">Magento_Theme::root.phtml</argument>

this means that the value of the argument template is the string Magento_Theme::root.phtml.

What are all the possible values of this xsi:type attribute?

share|improve this question
up vote 4 down vote accepted

I've found all types by checking <xs:extension base="argumentType" in *.xsd files.

lib/internal/Magento/Framework/Data/etc/argument/types.xsd, these are base types:

  • "array"
  • "string"
  • "boolean"
  • "object"
  • "configurableObject"
  • "number"
  • "null"

lib/internal/Magento/Framework/ObjectManager/etc/config.xsd, can be found in di.xml files:

  • "object"
  • "init_parameter"
  • "const"

lib/internal/Magento/Framework/View/Layout/etc/elements.xsd, can be found in layout *.xml files:

  • "options"
  • "url"
  • "helper"

Magento/Ui/etc/ui_components.xsd, can be found in UI components' *.xml files:

  • "constant"
  • "url"
share|improve this answer

According to my researches, here is what I've found:

The argument interpreter is created in the lib\internal\Magento\Framework\App\ObjectManagerFactory.php :

protected function createArgumentInterpreter(
    \Magento\Framework\Stdlib\BooleanUtils $booleanUtils
) {
    $constInterpreter = new \Magento\Framework\Data\Argument\Interpreter\Constant();
    $result = new \Magento\Framework\Data\Argument\Interpreter\Composite(
        [
            'boolean' => new \Magento\Framework\Data\Argument\Interpreter\Boolean($booleanUtils),
            'string' => new \Magento\Framework\Data\Argument\Interpreter\StringUtils($booleanUtils),
            'number' => new \Magento\Framework\Data\Argument\Interpreter\Number(),
            'null' => new \Magento\Framework\Data\Argument\Interpreter\NullType(),
            'object' => new \Magento\Framework\Data\Argument\Interpreter\DataObject($booleanUtils),
            'const' => $constInterpreter,
            'init_parameter' => new \Magento\Framework\App\Arguments\ArgumentInterpreter($constInterpreter),
        ],
        \Magento\Framework\ObjectManager\Config\Reader\Dom::TYPE_ATTRIBUTE
    );
    // Add interpreters that reference the composite
    $result->addInterpreter('array', new \Magento\Framework\Data\Argument\Interpreter\ArrayType($result));
    return $result;
}

In this code, you can clearly see that different interpreters are used based on the type attribute of the argument \Magento\Framework\ObjectManager\Config\Reader\Dom::TYPE_ATTRIBUTE:

  • boolean => \Magento\Framework\Data\Argument\Interpreter\Boolean
  • string => \Magento\Framework\Data\Argument\Interpreter\StringUtils
  • number => \Magento\Framework\Data\Argument\Interpreter\Number
  • null => \Magento\Framework\Data\Argument\Interpreter\NullType
  • object => \Magento\Framework\Data\Argument\Interpreter\DataObject
  • const => \Magento\Framework\Data\Argument\Interpreter\Constant
  • init_parameter => \Magento\Framework\App\Arguments\ArgumentInterpreter (note that this one takes the \Magento\Framework\Data\Argument\Interpreter\Constant as parameter and not the constructor parameter)

Also an extra interpreter is added on the fly to handle array types:

  • array => \Magento\Framework\Data\Argument\Interpreter\ArrayType

Note: it seems like the init_parameter type is only used in the app\code\Magento\Store\etc\di.xml to initiate some constants:

<argument name="xFrameOpt" xsi:type="init_parameter">Magento\Framework\App\Response\XFrameOptPlugin::DEPLOYMENT_CONFIG_X_FRAME_OPT</argument>
...
<argument name="isCustomEntryPoint" xsi:type="init_parameter">Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM</argument>
...
<argument name="runMode" xsi:type="init_parameter">Magento\Store\Model\StoreManager::PARAM_RUN_TYPE</argument>
<argument name="scopeCode" xsi:type="init_parameter">Magento\Store\Model\StoreManager::PARAM_RUN_CODE</argument>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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