Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
framework
Data
Form
Element
Select.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Framework\Data\Form\Element
;
7
8
use
Magento\Framework\Escaper
;
9
17
class
Select
extends
AbstractElement
18
{
25
public
function
__construct
(
26
Factory
$factoryElement,
27
CollectionFactory
$factoryCollection,
28
Escaper
$escaper,
29
$data
= []
30
) {
31
parent::__construct($factoryElement, $factoryCollection, $escaper,
$data
);
32
$this->
setType
(
'select'
);
33
$this->setExtType(
'combobox'
);
34
$this->
_prepareOptions
();
35
}
36
42
public
function
getElementHtml
()
43
{
44
$this->
addClass
(
'select admin__control-select'
);
45
46
$html =
''
;
47
if
($this->
getBeforeElementHtml
()) {
48
$html .=
'<label class="addbefore" for="'
.
49
$this->
getHtmlId
() .
50
'">'
.
51
$this->
getBeforeElementHtml
() .
52
'</label>'
;
53
}
54
55
$html .=
'<select id="'
. $this->
getHtmlId
() .
'" name="'
. $this->
getName
() .
'" '
. $this->
serialize
(
56
$this->
getHtmlAttributes
()
57
) . $this->
_getUiId
() .
'>'
.
"\n"
;
58
59
$value
= $this->getValue();
60
if
(!is_array(
$value
)) {
61
$value
= [
$value
];
62
}
63
64
if
(
$values
= $this->getValues()) {
65
foreach
(
$values
as $key =>
$option
) {
66
if
(!is_array(
$option
)) {
67
$html .= $this->
_optionToHtml
([
'value'
=> $key,
'label'
=>
$option
],
$value
);
68
}
elseif
(is_array(
$option
[
'value'
])) {
69
$html .=
'<optgroup label="'
.
$option
[
'label'
] .
'">'
.
"\n"
;
70
foreach
(
$option
[
'value'
] as $groupItem) {
71
$html .= $this->
_optionToHtml
($groupItem,
$value
);
72
}
73
$html .=
'</optgroup>'
.
"\n"
;
74
}
else
{
75
$html .= $this->
_optionToHtml
(
$option
,
$value
);
76
}
77
}
78
}
79
80
$html .=
'</select>'
.
"\n"
;
81
if
($this->
getAfterElementHtml
()) {
82
$html .=
'<label class="addafter" for="'
.
83
$this->
getHtmlId
() .
84
'">'
.
85
"\n{$this->getAfterElementHtml()}\n"
.
86
'</label>'
.
87
"\n"
;
88
}
89
return
$html;
90
}
91
99
protected
function
_optionToHtml
(
$option
, $selected)
100
{
101
if
(is_array(
$option
[
'value'
])) {
102
$html =
'<optgroup label="'
.
$option
[
'label'
] .
'">'
.
"\n"
;
103
foreach
(
$option
[
'value'
] as $groupItem) {
104
$html .= $this->
_optionToHtml
($groupItem, $selected);
105
}
106
$html .=
'</optgroup>'
.
"\n"
;
107
}
else
{
108
$html =
'<option value="'
. $this->
_escape
(
$option
[
'value'
]) .
'"'
;
109
$html .= isset(
$option
[
'title'
]) ?
'title="'
. $this->
_escape
(
$option
[
'title'
]) .
'"'
:
''
;
110
$html .= isset(
$option
[
'style'
]) ?
'style="'
.
$option
[
'style'
] .
'"'
:
''
;
111
if
(in_array(
$option
[
'value'
], $selected)) {
112
$html .=
' selected="selected"'
;
113
}
114
$html .=
'>'
. $this->
_escape
(
$option
[
'label'
]) .
'</option>'
.
"\n"
;
115
}
116
return
$html;
117
}
118
124
protected
function
_prepareOptions
()
125
{
126
$values
= $this->getValues();
127
if
(empty(
$values
)) {
128
$options
= $this->getOptions();
129
if
(is_array(
$options
)) {
130
$values
= [];
131
foreach
(
$options
as
$value
=>
$label
) {
132
$values
[] = [
'value'
=>
$value
,
'label'
=>
$label
];
133
}
134
}
elseif
(is_string(
$options
)) {
135
$values
= [[
'value'
=>
$options
,
'label'
=>
$options
]];
136
}
137
$this->
setValues
(
$values
);
138
}
139
}
140
146
public
function
getHtmlAttributes
()
147
{
148
return
[
149
'title'
,
150
'class'
,
151
'style'
,
152
'onclick'
,
153
'onchange'
,
154
'disabled'
,
155
'readonly'
,
156
'tabindex'
,
157
'data-form-part'
,
158
'data-role'
,
159
'data-action'
160
];
161
}
162
}
Magento\Framework\Data\Form\Element\CollectionFactory
Definition:
CollectionFactory.php:10
Magento\Framework\Data\Form\Element\AbstractElement\getBeforeElementHtml
getBeforeElementHtml()
Definition:
AbstractElement.php:383
elseif
elseif(isset( $params[ 'redirect_parent']))
Definition:
iframe.phtml:17
Magento\Framework\Data\Form\Element\AbstractElement\_getUiId
_getUiId($suffix=null)
Definition:
AbstractElement.php:333
Magento\Framework\Data\Form\Element\Select\_prepareOptions
_prepareOptions()
Definition:
Select.php:124
Magento\Framework\Data\Form\Element\Factory
Definition:
Factory.php:14
$values
$values
Definition:
options.phtml:88
Magento\Framework\Data\Form\Element\Select\__construct
__construct(Factory $factoryElement, CollectionFactory $factoryCollection, Escaper $escaper, $data=[])
Definition:
Select.php:25
Magento\Framework\Data\Form\setValues
setValues($values)
Definition:
Form.php:213
Magento\Framework\Data\Form\Element\AbstractElement\_escape
_escape($string)
Definition:
AbstractElement.php:286
Magento\Framework\Escaper
Definition:
Escaper.php:15
Magento\Framework\Data\Form\Element\AbstractElement\getName
getName()
Definition:
AbstractElement.php:182
Magento\Framework\Data\Form\Element\Select\getHtmlAttributes
getHtmlAttributes()
Definition:
Select.php:146
$label
$label
Definition:
details.phtml:21
$data
$data
Definition:
attribute_set_with_image_attribute.php:16
$value
$value
Definition:
gender.phtml:16
Magento\Framework\Data\Form\Element\AbstractElement\addClass
addClass($class)
Definition:
AbstractElement.php:257
Magento\Framework\Data\Form\Element\AbstractElement\getHtmlId
getHtmlId()
Definition:
AbstractElement.php:172
Magento\Framework\Data\Form\Element\AbstractElement\setType
setType($type)
Definition:
AbstractElement.php:197
Magento\Framework\Data\Form\Element\AbstractElement\serialize
serialize($attributes=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
Definition:
AbstractElement.php:486
Magento\Framework\Data\Form\Element
Definition:
AbstractElement.php:6
Magento\Framework\Data\Form\Element\AbstractElement\getAfterElementHtml
getAfterElementHtml()
Definition:
AbstractElement.php:393
Magento\Framework\Data\Form\Element\Select
Definition:
Select.php:17
Magento\Framework\Data\Form\Element\Select\getElementHtml
getElementHtml()
Definition:
Select.php:42
Magento\Framework\Data\Form\Element\Select\_optionToHtml
_optionToHtml($option, $selected)
Definition:
Select.php:99
$option
$option
Definition:
product_configurable_with_single_child.php:38
Magento\Framework\Data\Form\Element\AbstractElement
Definition:
AbstractElement.php:21
$options
$options
Definition:
multiple_mixed_products.php:29