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
1. Go to Stores > All Stores and choose the Store you want to change the default store view for. 2. In the Default Store View section set the Store View you want to be a default one for this particular store and press Save Store button.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With