5

I am creating a module which will support different configuration settings for different store views and it would be great to have a store view selector similar to the one which appears when one is editing a product in the admin.

I have managed to add buttons to my module toolbar using the code:

class Edit extends \Magento\Backend\Block\Template
{   
    protected function _prepareLayout()
    {
        $this->getToolbar()->addChild(
            'save_button',
            'Magento\Backend\Block\Widget\Button',
            [
                'label' => __('Save'),
                'data_attribute' => [
                    'role' => 'save',
                ],
                'class' => 'save primary',
                'onclick' => "jQuery('#mp_mymodule_edit_form').submit();",
            ]
        );
        return parent::_prepareLayout();
    }
}

I wondered if it was possible to insert the store view selector using Tools::addChild method? Looked around Stack Overflow and Google in general and have not managed to find any thing on this. Fingers crossed, someone does know.

Thanks in advance

musaffar.patel
  • 153
  • 3
  • 14

1 Answers1

7

Eventually managed to work this out by poking around various Magento files, posting here in case anyone is looking for the same solution:

Method 1 - Adding to the _prapareLayout function:

    $this->getToolbar()->addChild(
        'store_switcher',
        'Magento\Backend\Block\Store\Switcher'
    );

Method 2 - Layout XML file (in my case I added this to my layout file in app/code/MP/MyModule/view/adminhtml/layout/productpricebysize_dimension_edit

<referenceContainer name="page.main.actions">
        <block class="Magento\Backend\Block\Store\Switcher" name="store_switcher">
            <action method="setUseConfirm">
                <argument name="params" xsi:type="string">1</argument>
            </action>
        </block>
</referenceContainer>
musaffar.patel
  • 153
  • 3
  • 14
  • @musaffar.patel Can you also elaborate how to store values for store view in my custom module. Further for my module I used simple tables not EAV. Is it compulsory to use EAV for multi store view? – AbdulBasit Nov 05 '17 at 11:01