*/
namespace Magento\Framework\Data\Form\Element;
use Magento\Framework\Escaper;
class Multiselect extends AbstractElement
{
/**
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
$data = []
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->setType('select');
$this->setExtType('multiple');
$this->setSize(10);
}
/**
* Get the name
*
* @return string
*/
public function getName()
{
$name = parent::getName();
if (strpos($name, '[]') === false) {
$name .= '[]';
}
return $name;
}
/**
* Get the element as HTML
*
* @return string
*/
public function getElementHtml()
{
$this->addClass('select multiselect admin__control-multiselect');
$html = '';
if ($this->getCanBeEmpty()) {
$html .= '';
}
$html .= '' . "\n";
$html .= $this->getAfterElementHtml();
return $html;
}
/**
* Get the HTML attributes
*
* @return string[]
*/
public function getHtmlAttributes()
{
return [
'title',
'class',
'style',
'onclick',
'onchange',
'disabled',
'size',
'tabindex',
'data-form-part',
'data-role',
'data-action'
];
}
/**
* Get the default HTML
*
* @return string
*/
public function getDefaultHtml()
{
$result = $this->getNoSpan() === true ? '' : '' . "\n";
$result .= $this->getLabelHtml();
$result .= $this->getElementHtml();
if ($this->getSelectAll() && $this->getDeselectAll()) {
$result .= '' .
$this->getSelectAll() .
' | ';
$result .= '' .
$this->getDeselectAll() .
'';
}
$result .= $this->getNoSpan() === true ? '' : '' . "\n";
$result .= '';
return $result;
}
/**
* Get the name of the JS object
*
* @return string
*/
public function getJsObjectName()
{
return $this->getHtmlId() . 'ElementControl';
}
/**
* @param array $option
* @param array $selected
* @return string
*/
protected function _optionToHtml($option, $selected)
{
$html = '' . "\n";
return $html;
}
}