Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

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

Stuck in a new issue regarding adding store selector for my custom module in admin form - I need to add a store selector and to add the values of a store in a different table as it is working with existing cms_block and cms_page modules

enter image description here

EDIT

I added a custom form in admin section without using ui_component and now added a store selector in form, now a new issue in my front is to save this store data in my custom modules store's table , my custom table is cms_job and my custom module's store table is cms_job_store

now further i want to save data in both these tables and to retrive data for Grid section which is generated using ui_component

please help me on this,

Thanks

share|improve this question

magento\vendor\magento\module-cms\view\adminhtml\ui_component\cms_block_form.xml

<field name="storeviews">
    <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="dataType" xsi:type="string">int</item>
            <item name="label" xsi:type="string" translate="true">Store View</item>
            <item name="formElement" xsi:type="string">multiselect</item>
            <item name="source" xsi:type="string">block</item>
            <item name="dataScope" xsi:type="string">store_id</item>
            <item name="default" xsi:type="string">0</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>

magento\vendor\magento\module-cms\Ui\Component\Listing\Column\Cms\Options.php

Copy this file in ur module & apply name changes accordingly

share|improve this answer
    
thanks, but i am not using ui_component to generate form in my custom module, secondly , now i am able to show store selector in my form , and want to save its values and also want to show in Grid, by joining my table with store table, any help – amit_game 6 hours ago

For your phtml file define your block class containing following code: Please refer getStores function in following block class

namespace Vendor\Module\Block;

class Classname extends \Magento\Framework\View\Element\Template {

    protected $_objectManager;


    public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = []
    ) {
        parent::__construct($context, $data);

    }


    /**
     * Retrieve stores structure
     *
     * @param bool $isAll       
     */
    public function getStores($isAll = false)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $model = $objectManager->create('\Magento\Store\Model\System\Store');

        $out = $model->getStoresStructure($isAll);
         $result = array();
        foreach($out as $data){
           $result[]=$data;
        }

        $_mainWebsites = array();
        $i=0;
        $j=1;
        foreach ($result as $k => $v) {
            $_mainWebsites[$i]['main_website']= $result[$k]['label'] ;
            $_mainWebsites[$i]['store'] = $result[$k]['children'][$j]['label'] ;
            foreach ($result[$k]['children'][$j]['children'] as $p => $q){
                 $_mainWebsites[$i]['store_views'][$p] = $result[$k]['children'][$j]['children'][$p]['label'] ;
            }
            $i++;
        }

        return $_mainWebsites;
    }

} 
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.