コード例 #1
0
ファイル: Form.php プロジェクト: rustamveer/magento2
 /**
  * Prepare form
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /**
      * Checking if user have permission to save information
      */
     if ($this->_isAllowedAction('Ves_Setup::import')) {
         $isElementDisabled = false;
     } else {
         $isElementDisabled = true;
     }
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data']]);
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Ves Setup Import')]);
     $folders = $this->_exportFolders->toArray();
     $fds = [];
     foreach ($folders as $k => $v) {
         $k = strtolower(str_replace("/", "-", $k));
         $fds[$k] = $v;
     }
     $fieldset->addField('folder', 'select', ['label' => __('Folder'), 'title' => __('Folder'), 'name' => 'folder', 'options' => $fds, 'disabled' => $isElementDisabled, 'class' => 'ves-import']);
     foreach ($this->_exportFolders->toArray() as $key => $val) {
         $orginKey = $key;
         $key = strtolower(str_replace("/", "-", $key));
         $fieldPreset = $fieldset->addField($key, 'select', ['name' => $key, 'label' => __('Select Configuration to Import'), 'title' => __('Select Configuration to Import'), 'values' => $this->_importFiles->toOptionArray($orginKey), 'note' => '
                 Folder: <strong>app/design/frontend/' . $orginKey . '/backup</strong>
                 <script type="text/javascript">
                 require(["jquery"], function(){
                     jQuery("#' . $key . '").parents(".admin__field").hide();
                     jQuery(".ves-import").change(function(){
                         var folder_name = jQuery(this).val();
                         if(folder_name!="' . $key . '"){
                             jQuery("#' . $key . '").parents(".admin__field").hide();    
                         }else{
                             jQuery("#' . $key . '").parents(".admin__field").show();    
                         }
                     }).change();
                     jQuery("#' . $key . '").change(function(){
                         var data_import_file = jQuery(this).val();
                         if(data_import_file == "data_import_file"){
                             jQuery("#data_import_file").parents(".admin__field").show();
                         }else{
                             jQuery("#data_import_file").parents(".admin__field").hide();
                         }
                     }).change();
                 });</script>']);
     }
     $fieldset->addField('data_import_file', 'file', ['name' => 'data_import_file', 'label' => __('Upload Custom File'), 'title' => __('Upload Custom File'), 'after_element_html' => '
             <script type="text/javascript">
                 require(["jquery"], function(){
                     jQuery("#data_import_file").parents(".admin__field").hide();
                 });
             </script>
             ']);
     $fieldset->addField('overwrite_blocks', 'select', ['name' => 'overwrite_blocks', 'label' => __('Overwrite Existing Blocks'), 'title' => __('Overwrite Existing Blocks'), 'values' => $this->_yesno->toArray(), 'note' => __('If set to <b>Yes</b>, the import data will override exist data. Check exits data according to the field <b>URL Key</b> of <b>Cms Pages</b> and the field <b>Identifier</b> of <b>Static Block</b>.<br><br>If set to <b>No</b>, the function import will empty data of all table of <b>CMS Page</b> and <b>Static Block</b>, then insert import data.')]);
     $field = $fieldset->addField('store_id', 'select', ['name' => 'store_id', 'label' => __('Configuration Scope'), 'title' => __('Configuration Scope'), 'values' => $this->_systemStore->getStoreValuesForForm(false, true), 'disabled' => $isElementDisabled, 'note' => __('Imported configuration settings will be applied to selected scope (selected store view or website). If you\'re not sure what is \'scope\' in Magento system configuration.<br/><br/>It is highly recommended to leave the default scope <strong>\'Default Config\'</strong>. In this case imported configuration will be applied to all existing store views.')]);
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
コード例 #2
0
ファイル: Form.php プロジェクト: dragonsword007008/magento2
 /**
  * Prepare form
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /**
      * Checking if user have permission to save information
      */
     if ($this->_isAllowedAction('Ves_Setup::export')) {
         $isElementDisabled = false;
     } else {
         $isElementDisabled = true;
     }
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data']]);
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Ves Setup Export')]);
     $fieldset->addField('file_name', 'text', ['name' => 'file_name', 'label' => __('File Name'), 'title' => __('File Name'), 'required' => true, 'disabled' => $isElementDisabled, 'note' => __('This will be the name of the file in which configuration will be saved. You can enter any name you want.')]);
     $fieldset->addField('file_extension', 'select', ['name' => 'file_extension', 'label' => __('File Extension'), 'title' => __('File Extension'), 'options' => $this->_fileExtension->toArray(), 'disabled' => $isElementDisabled]);
     $fieldset->addField('isdowload', 'select', ['label' => __('Download File'), 'title' => __('Download File'), 'name' => 'isdowload', 'options' => $this->_yesno->toArray(), 'disabled' => $isElementDisabled]);
     $fieldset->addField('folder', 'select', ['label' => __('Folder'), 'title' => __('Folder'), 'name' => 'folder', 'options' => $this->_exportFolders->toArray(), 'disabled' => $isElementDisabled, 'note' => '<script type="text/javascript">
                     require(["jquery"], function(){
                         jQuery("#folder").change(function(){
                             var val = jQuery(this).val();
                             jQuery("#folder-note").html("");
                             jQuery("#folder-note").append("Folder: "+val);
                         }).change();
                     });
                 </script>']);
     $field = $fieldset->addField('store_id', 'select', ['name' => 'store_id', 'label' => __('Configuration Scope'), 'title' => __('Configuration Scope'), 'values' => $this->_systemStore->getStoreValuesForForm(false, true), 'disabled' => $isElementDisabled, 'note' => __('Configuration of selected store will be saved in a file. Apply for all system config of modules')]);
     $field = $fieldset->addField('modules', 'multiselect', ['name' => 'modules[]', 'label' => __('Ves Modules'), 'title' => __('Ves Modules'), 'values' => $this->_vesModules->toOptionArray(), 'disabled' => $isElementDisabled]);
     $renderer = $this->getLayout()->createBlock('Ves\\Setup\\Block\\Adminhtml\\Form\\Renderer\\Fieldset\\Element');
     $field->setRenderer($renderer);
     $field = $fieldset->addField('cmspages', 'multiselect', ['name' => 'cmspages[]', 'label' => __('CMS Pages'), 'title' => __('CMS Pages'), 'values' => $this->_cmsPage->toOptionArray(), 'disabled' => $isElementDisabled]);
     $renderer = $this->getLayout()->createBlock('Ves\\Setup\\Block\\Adminhtml\\Form\\Renderer\\Fieldset\\Element');
     $field->setRenderer($renderer);
     $field = $fieldset->addField('cmsblocks', 'multiselect', ['name' => 'cmsblocks[]', 'label' => __('CMS Blocks'), 'title' => __('CMS Blocks'), 'values' => $this->_staticBlock->toOptionArray(), 'disabled' => $isElementDisabled]);
     $renderer = $this->getLayout()->createBlock('Ves\\Setup\\Block\\Adminhtml\\Form\\Renderer\\Fieldset\\Element');
     $field->setRenderer($renderer);
     $field = $fieldset->addField('widgets', 'multiselect', ['name' => 'widgets[]', 'label' => __('Widgets'), 'title' => __('Widgets'), 'values' => $this->_widgets->toOptionArray(), 'disabled' => $isElementDisabled]);
     $renderer = $this->getLayout()->createBlock('Ves\\Setup\\Block\\Adminhtml\\Form\\Renderer\\Fieldset\\Element');
     $field->setRenderer($renderer);
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }