コード例 #1
0
ファイル: Form.php プロジェクト: whoople/magento2-testing
 /**
  * Add fieldsets
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getUrl('adminhtml/*/validate'), 'method' => 'post', 'enctype' => 'multipart/form-data']]);
     // base fieldset
     $fieldsets['base'] = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
     $fieldsets['base']->addField('entity', 'select', ['name' => 'entity', 'title' => __('Entity Type'), 'label' => __('Entity Type'), 'required' => true, 'onchange' => 'varienImport.handleEntityTypeSelector();', 'values' => $this->_entityFactory->create()->toOptionArray(), 'after_element_html' => $this->getDownloadSampleFileHtml()]);
     // add behaviour fieldsets
     $uniqueBehaviors = $this->_importModel->getUniqueEntityBehaviors();
     foreach ($uniqueBehaviors as $behaviorCode => $behaviorClass) {
         $fieldsets[$behaviorCode] = $form->addFieldset($behaviorCode . '_fieldset', ['legend' => __('Import Behavior'), 'class' => 'no-display']);
         /** @var $behaviorSource \Magento\ImportExport\Model\Source\Import\AbstractBehavior */
         $fieldsets[$behaviorCode]->addField($behaviorCode, 'select', ['name' => 'behavior', 'title' => __('Import Behavior'), 'label' => __('Import Behavior'), 'required' => true, 'disabled' => true, 'values' => $this->_behaviorFactory->create($behaviorClass)->toOptionArray(), 'class' => $behaviorCode, 'onchange' => 'varienImport.handleImportBehaviorSelector();', 'note' => ' ']);
         $fieldsets[$behaviorCode]->addField($behaviorCode . \Magento\ImportExport\Model\Import::FIELD_NAME_VALIDATION_STRATEGY, 'select', ['name' => \Magento\ImportExport\Model\Import::FIELD_NAME_VALIDATION_STRATEGY, 'title' => __(' '), 'label' => __(' '), 'required' => true, 'class' => $behaviorCode, 'disabled' => true, 'values' => [ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR => 'Stop on Error', ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS => 'Skip error entries'], 'after_element_html' => $this->getDownloadSampleFileHtml()]);
         $fieldsets[$behaviorCode]->addField($behaviorCode . '_' . \Magento\ImportExport\Model\Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 'label' => __('Allowed Errors Count'), 'title' => __('Allowed Errors Count'), 'required' => true, 'disabled' => true, 'value' => 10, 'class' => $behaviorCode . ' validate-number validate-greater-than-zero input-text', 'note' => __('Please specify number of errors to halt import process')]);
         $fieldsets[$behaviorCode]->addField($behaviorCode . '_' . \Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR, 'label' => __('Field separator'), 'title' => __('Field separator'), 'required' => true, 'disabled' => true, 'class' => $behaviorCode, 'value' => ',']);
         $fieldsets[$behaviorCode]->addField($behaviorCode . \Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR, 'label' => __('Multiple value separator'), 'title' => __('Multiple value separator'), 'required' => true, 'disabled' => true, 'class' => $behaviorCode, 'value' => ',']);
     }
     // fieldset for file uploading
     $fieldsets['upload'] = $form->addFieldset('upload_file_fieldset', ['legend' => __('File to Import'), 'class' => 'no-display']);
     $fieldsets['upload']->addField(\Magento\ImportExport\Model\Import::FIELD_NAME_SOURCE_FILE, 'file', ['name' => \Magento\ImportExport\Model\Import::FIELD_NAME_SOURCE_FILE, 'label' => __('Select File to Import'), 'title' => __('Select File to Import'), 'required' => true, 'class' => 'input-file']);
     $fieldsets['upload']->addField(\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR, 'label' => __('Images File Directory'), 'title' => __('Images File Directory'), 'required' => false, 'class' => 'input-text', 'note' => __('For Type "Local Server" use relative path to Magento installation,
                             e.g. var/export, var/import, var/export/some/dir')]);
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
コード例 #2
0
ファイル: Form.php プロジェクト: kid17/magento2
 /**
  * Add fieldsets
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getUrl('adminhtml/*/validate'), 'method' => 'post', 'enctype' => 'multipart/form-data']]);
     // base fieldset
     $fieldsets['base'] = $form->addFieldset('base_fieldset', ['legend' => __('Import Settings')]);
     $fieldsets['base']->addField('entity', 'select', ['name' => 'entity', 'title' => __('Entity Type'), 'label' => __('Entity Type'), 'required' => true, 'onchange' => 'varienImport.handleEntityTypeSelector();', 'values' => $this->_entityFactory->create()->toOptionArray()]);
     // add behaviour fieldsets
     $uniqueBehaviors = $this->_importModel->getUniqueEntityBehaviors();
     foreach ($uniqueBehaviors as $behaviorCode => $behaviorClass) {
         $fieldsets[$behaviorCode] = $form->addFieldset($behaviorCode . '_fieldset', ['legend' => __('Import Behavior'), 'class' => 'no-display']);
         /** @var $behaviorSource \Magento\ImportExport\Model\Source\Import\AbstractBehavior */
         $fieldsets[$behaviorCode]->addField($behaviorCode, 'select', ['name' => 'behavior', 'title' => __('Import Behavior'), 'label' => __('Import Behavior'), 'required' => true, 'disabled' => true, 'values' => $this->_behaviorFactory->create($behaviorClass)->toOptionArray(), 'class' => $behaviorCode]);
         $fieldsets[$behaviorCode]->addField($behaviorCode . \Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR, 'label' => __('Field separator'), 'title' => __('Field separator'), 'required' => true, 'disabled' => true, 'class' => $behaviorCode, 'value' => ',']);
         $fieldsets[$behaviorCode]->addField($behaviorCode . \Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR, 'label' => __('Multiple value separator'), 'title' => __('Multiple value separator'), 'required' => true, 'disabled' => true, 'class' => $behaviorCode, 'value' => ',']);
     }
     // fieldset for file uploading
     $fieldsets['upload'] = $form->addFieldset('upload_file_fieldset', ['legend' => __('File to Import'), 'class' => 'no-display']);
     $fieldsets['upload']->addField(\Magento\ImportExport\Model\Import::FIELD_NAME_SOURCE_FILE, 'file', ['name' => \Magento\ImportExport\Model\Import::FIELD_NAME_SOURCE_FILE, 'label' => __('Select File to Import'), 'title' => __('Select File to Import'), 'required' => true, 'class' => 'input-file']);
     $fieldsets['upload']->addField(\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR, 'text', ['name' => \Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR, 'label' => __('Images File Directory'), 'title' => __('Images File Directory'), 'required' => false, 'class' => 'input-text', 'note' => __('For Type "Local Server" use relative path to Magento installation,
                             e.g. var/export, var/import, var/export/some/dir')]);
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
コード例 #3
0
ファイル: Form.php プロジェクト: aiesh/magento2
 /**
  * Add fieldsets
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getUrl('adminhtml/*/validate'), 'method' => 'post', 'enctype' => 'multipart/form-data')));
     // base fieldset
     $fieldsets['base'] = $form->addFieldset('base_fieldset', array('legend' => __('Import Settings')));
     $fieldsets['base']->addField('entity', 'select', array('name' => 'entity', 'title' => __('Entity Type'), 'label' => __('Entity Type'), 'required' => true, 'onchange' => 'varienImport.handleEntityTypeSelector();', 'values' => $this->_entityFactory->create()->toOptionArray()));
     // add behaviour fieldsets
     $uniqueBehaviors = $this->_importModel->getUniqueEntityBehaviors();
     foreach ($uniqueBehaviors as $behaviorCode => $behaviorClass) {
         $fieldsets[$behaviorCode] = $form->addFieldset($behaviorCode . '_fieldset', array('legend' => __('Import Behavior'), 'class' => 'no-display'));
         /** @var $behaviorSource \Magento\ImportExport\Model\Source\Import\AbstractBehavior */
         $fieldsets[$behaviorCode]->addField($behaviorCode, 'select', array('name' => 'behavior', 'title' => __('Import Behavior'), 'label' => __('Import Behavior'), 'required' => true, 'disabled' => true, 'values' => $this->_behaviorFactory->create($behaviorClass)->toOptionArray()));
     }
     // fieldset for file uploading
     $fieldsets['upload'] = $form->addFieldset('upload_file_fieldset', array('legend' => __('File to Import'), 'class' => 'no-display'));
     $fieldsets['upload']->addField(\Magento\ImportExport\Model\Import::FIELD_NAME_SOURCE_FILE, 'file', array('name' => \Magento\ImportExport\Model\Import::FIELD_NAME_SOURCE_FILE, 'label' => __('Select File to Import'), 'title' => __('Select File to Import'), 'required' => true, 'class' => 'input-file'));
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
コード例 #4
0
ファイル: Import.php プロジェクト: pradeep-wagento/magento2
 /**
  * Gets array of entities and appropriate behaviours
  * array(
  *     <entity_code> => array(
  *         'token' => <behavior_class_name>,
  *         'code'  => <behavior_model_code>,
  *     ),
  *     ...
  * )
  *
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getEntityBehaviors()
 {
     $behaviourData = [];
     $entities = $this->_importConfig->getEntities();
     foreach ($entities as $entityCode => $entityData) {
         $behaviorClassName = isset($entityData['behaviorModel']) ? $entityData['behaviorModel'] : null;
         if ($behaviorClassName && class_exists($behaviorClassName)) {
             /** @var $behavior \Magento\ImportExport\Model\Source\Import\AbstractBehavior */
             $behavior = $this->_behaviorFactory->create($behaviorClassName);
             $behaviourData[$entityCode] = ['token' => $behaviorClassName, 'code' => $behavior->getCode() . '_behavior', 'notes' => $behavior->getNotes($entityCode)];
         } else {
             throw new \Magento\Framework\Exception\LocalizedException(__('The behavior token for %1 is invalid.', $entityCode));
         }
     }
     return $behaviourData;
 }