Example #1
0
 /**
  * Prepare chooser element HTML
  *
  * @param AbstractElement $element Form Element
  * @return AbstractElement
  */
 public function prepareElementHtml(AbstractElement $element)
 {
     $uniqId = $this->mathRandom->getUniqueHash($element->getId());
     $sourceUrl = $this->getUrl('catalog/product_widget/chooser', ['uniq_id' => $uniqId, 'use_massaction' => false]);
     $chooser = $this->getLayout()->createBlock('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->setElement($element)->setConfig($this->getConfig())->setFieldsetId($this->getFieldsetId())->setSourceUrl($sourceUrl)->setUniqId($uniqId);
     if ($element->getValue()) {
         $value = explode('/', $element->getValue());
         $productId = false;
         if (isset($value[0]) && isset($value[1]) && $value[0] == 'product') {
             $productId = $value[1];
         }
         $categoryId = isset($value[2]) ? $value[2] : false;
         $label = '';
         if ($categoryId) {
             $label = $this->_resourceCategory->getAttributeRawValue($categoryId, 'name', $this->_storeManager->getStore()) . '/';
         }
         if ($productId) {
             $label .= $this->_resourceProduct->getAttributeRawValue($productId, 'name', $this->_storeManager->getStore());
         }
         $chooser->setLabel($label);
     }
     $element->setData('after_element_html', $chooser->toHtml());
     return $element;
 }