0

I am not able to add store view selection in system.xml I am only able to add in the ui form field component:

When I tried to add in system.xml it gives the error:

1 exception(s):
Exception #0 (Exception): Warning: htmlspecialchars() expects parameter 1 to be string, 
array given in
.../vendor/magento/framework/Data/Form/Element/AbstractElement.php on line 287

system.xml:

<field id="store_view" translate="label" type="multiselect" sortOrder="13" showInDefault="1" showInWebsite="1" showInStore="1">
   <label>Store view</label>
   <source_model>Magento\Cms\Ui\Component\Listing\Column\Cms\Options</source_model>
</field>

form_edit.xml

<field name="store">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Magento\Cms\Ui\Component\Listing\Column\Cms\Options/item>
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">Store</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">number</item>
            <item name="formElement" xsi:type="string">multiselect</item>
            <item name="source" xsi:type="string">store</item>
            <item name="multiple" xsi:type="boolean">true</item>
            <item name="dataScope" xsi:type="string">store</item>
            <item name="valueMap" xsi:type="array">
                <item name="true" xsi:type="number">1</item>
                <item name="false" xsi:type="number">0</item>
            </item>
            <item name="default" xsi:type="number">0</item>
        </item>
    </argument>
</field>

enter image description here

Is it possible at all the way magento has build this?

0

system.xml :-

<field id="store_view" translate="label" type="multiselect" sortOrder="13" showInDefault="1" showInWebsite="1" showInStore="1">
   <label>Store view</label>
   <source_model>vendor\module\Model\Source\Config\Option</source_model>
</field>
<?php

option.php

namespace vendor\module\Model\Source\Config;

class Option implements \Magento\Framework\Data\OptionSourceInterface
{

    protected $eavConfig;


    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager
    )
    {
        $this->_storeManager = $storeManager;
    }


    public function toOptionArray()
    {
        $storeManagerDataList = $this->_storeManager->getStores();
        $options = array();

        foreach ($storeManagerDataList as $key => $value) {
               $options[] = array(
                'value' =>  $value['name'],
                'label' => $value['code'],
            );
        }
        return $options;
    }
}
  • That's not the answer. in need to show parent of store view also in similar fashion to the store view switcher, same as image attached in the question. – Juliano Vargas Apr 5 at 13:23

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.