*/
namespace Magento\Framework\Data\Form\Element;
use Magento\Framework\Escaper;
class Editablemultiselect extends \Magento\Framework\Data\Form\Element\Multiselect
{
/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;
/**
* Editablemultiselect constructor.
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
Factory $factoryElement,
CollectionFactory $factoryCollection,
Escaper $escaper,
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}
/**
* Name of the default JavaScript class that is used to make multiselect editable
*
* This class must define init() method and receive configuration in the constructor
*/
const DEFAULT_ELEMENT_JS_CLASS = 'EditableMultiselect';
/**
* Retrieve HTML markup of the element
*
* @return string
* @throws \InvalidArgumentException
*/
public function getElementHtml()
{
$html = parent::getElementHtml();
$selectConfig = $this->getData('select_config');
if ($this->getData('disabled')) {
$selectConfig['is_entity_editable'] = false;
}
$elementJsClass = self::DEFAULT_ELEMENT_JS_CLASS;
if ($this->getData('element_js_class')) {
$elementJsClass = $this->getData('element_js_class');
}
$selectConfigJson = $this->serializer->serialize($selectConfig);
$jsObjectName = $this->getJsObjectName();
// TODO: TaxRateEditableMultiselect should be moved to a static .js module.
$html .= "
";
return $html;
}
/**
* Retrieve HTML markup of given select option
*
* @param array $option
* @param string[] $selected
* @return string
*/
protected function _optionToHtml($option, $selected)
{
$html = '' . "\n";
return $html;
}
}