-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathForm.php
More file actions
executable file
·118 lines (105 loc) · 3.6 KB
/
Form.php
File metadata and controls
executable file
·118 lines (105 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* @copyright: Copyright © 2016 Firebear Studio GmbH. All rights reserved.
* @author: Firebear Studio <fbeardev@gmail.com>
*/
namespace Firebear\ImportExport\Plugin\Block\Import;
use Firebear\ImportExport\Model\Source\ConfigInterface;
/**
* Class Form
* @package Firebear\ImportExport\Plugin\Block\Import
*/
class Form
{
/**
* Source types config
*
* @var ConfigInterface|null
*/
protected $config = null;
/**
* Form constructor.
*
* @param ConfigInterface $config
*/
public function __construct(
ConfigInterface $config
) {
$this->config = $config;
}
/**
* Add import source fieldset to default import form
*
* @param \Magento\ImportExport\Block\Adminhtml\Import\Edit\Form $subject
* @param $form
* @return array
*/
public function beforeSetForm(\Magento\ImportExport\Block\Adminhtml\Import\Edit\Form $subject, $form)
{
$fileFieldset = $form->getElement('upload_file_fieldset');
$oldClass = $fileFieldset->getClass();
$fileFieldset->setClass('source-fieldset ' . $oldClass);
$types = $this->config->get();
$sources = [
['label' => __('-- Please Select --'), 'value' => ''],
['label' => __('File'), 'value' => 'file']
];
foreach ($types as $typeName => $type) {
$sources[] = ['label' => $type['label'], 'value' => $typeName];
}
$fieldsets['source'] = $form->addFieldset(
'import_source_fieldset',
['legend' => __('Import Source'), 'class' => 'no-display'],
'custom_behavior_fieldset'
);
$fieldsets['source']->addField(
'import_source',
'select',
[
'name' => 'import_source',
'label' => __('Source'),
'title' => __('Source'),
'required' => true,
'class' => 'input-text',
'onchange' => 'varienImport.handleImportSourceSelector();',
'values' => $sources,
]
);
foreach ($types as $typeName => $type) {
$fieldsets[$typeName] = $form->addFieldset(
'upload_' . $typeName . '_fieldset',
['legend' => __($type['label']), 'class' => 'source-fieldset no-display']
);
foreach ($type['fields'] as $fieldName => $field) {
// if ($fieldName != 'file_path') {
// continue;
// }
$fieldsets[$typeName]->addField(
$typeName . '_' . $fieldName,
$field['type'],
[
'name' => $typeName . '_' . $fieldName,
'label' => __($field['label']),
'title' => __($field['label']),
'required' => $field['required'],
'note' => $field['notice'],
'value' => $field['value'],
'class' => 'input-' . $field['type']
]
);
}
}
$fileFieldset = $form->getElement('basic_behavior_fieldset');
$fileFieldset->addField(
'base_behavior generate_url',
'checkbox',
[
'name' => 'generate_url',
'label' => __('Generate Unique Url if Duplicate'),
'title' => __('Generate Unique Url if Duplicate'),
'value' => 1,
]
);
return [$form];
}
}