示例#1
0
 public function testGetElementHtml()
 {
     $filePath = 'some/path/to/file.jpg';
     $this->imageElement->setValue($filePath);
     $html = $this->imageElement->getElementHtml();
     $this->assertContains('media/' . $filePath, $html);
 }
示例#2
0
 /**
  * @covers \Magento\Framework\Data\Form\Element\Image::getElementHtml
  */
 public function testGetElementHtmlWithValue()
 {
     $this->_image->setValue('test_value');
     $html = $this->_image->getElementHtml();
     $this->assertContains('class="input-file"', $html);
     $this->assertContains('<input', $html);
     $this->assertContains('type="file"', $html);
     $this->assertContains('value="test_value"', $html);
     $this->assertContains('<a href="test_value" onclick="imagePreview(\'_image\'); return false;"', $html);
     $this->assertContains('<input type="checkbox"', $html);
 }
示例#3
0
 /**
  * @covers \Magento\Framework\Data\Form\Element\Image::getElementHtml
  */
 public function testGetElementHtmlWithValue()
 {
     $this->_image->setValue('test_value');
     $this->urlBuilder->expects($this->once())->method('getBaseUrl')->with(['_type' => UrlInterface::URL_TYPE_MEDIA])->willReturn('http://localhost/media/');
     $html = $this->_image->getElementHtml();
     $this->assertContains('class="input-file"', $html);
     $this->assertContains('<input', $html);
     $this->assertContains('type="file"', $html);
     $this->assertContains('value="test_value"', $html);
     $this->assertContains('<a href="http://localhost/media/test_value" onclick="imagePreview(\'_image\'); return false;"', $html);
     $this->assertContains('<input type="checkbox"', $html);
 }
示例#4
0
文件: Image.php 项目: aiesh/magento2
 /**
  * Get image preview url
  *
  * @return string
  */
 protected function _getUrl()
 {
     $url = parent::_getUrl();
     $config = $this->getFieldConfig();
     /* @var $config array */
     if (isset($config['base_url'])) {
         $element = $config['base_url'];
         $urlType = empty($element['type']) ? 'link' : (string) $element['type'];
         $url = $this->_urlBuilder->getBaseUrl(['_type' => $urlType]) . $element['value'] . '/' . $url;
     }
     return $url;
 }
示例#5
0
文件: Image.php 项目: aiesh/magento2
 /**
  * @return string
  */
 protected function _getDeleteCheckbox()
 {
     $html = '';
     if ($attribute = $this->getEntityAttribute()) {
         if (!$attribute->getIsRequired()) {
             $html .= parent::_getDeleteCheckbox();
         } else {
             $inputField = '<input value="%s" id="%s_hidden" type="hidden" class="required-entry" />';
             $html .= sprintf($inputField, $this->getValue(), $this->getHtmlId());
             $html .= '<script type="text/javascript">
                 syncOnchangeValue(\'' . $this->getHtmlId() . '\', \'' . $this->getHtmlId() . '_hidden\');
             </script>';
         }
     } else {
         $html .= parent::_getDeleteCheckbox();
     }
     return $html;
 }
示例#6
0
文件: Image.php 项目: pleminh/Gemtoo
 /**
  * @param ArticleImage $imageModel
  * @param ElementFactory $factoryElement
  * @param ElementCollectionFactory $factoryCollection
  * @param Escaper $escaper
  * @param UrlInterface $urlBuilder
  * @param array $data
  */
 public function __construct(ArticleImage $imageModel, ElementFactory $factoryElement, ElementCollectionFactory $factoryCollection, Escaper $escaper, UrlInterface $urlBuilder, $data = [])
 {
     $this->imageModel = $imageModel;
     parent::__construct($factoryElement, $factoryCollection, $escaper, $urlBuilder, $data);
 }
示例#7
0
 /**
  * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
  * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
  * @param \Magento\Framework\Escaper $escaper
  * @param \Magento\Framework\UrlInterface $urlBuilder
  * @param \Magento\Framework\StoreManagerInterface $storeManager
  * @param array $data
  */
 public function __construct(\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Escaper $escaper, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\StoreManagerInterface $storeManager, $data = array())
 {
     $this->_storeManager = $storeManager;
     parent::__construct($factoryElement, $factoryCollection, $escaper, $urlBuilder, $data);
 }
 /**
  * constructor
  *
  * @param \Mageplaza\Blog\Model\Post\Image $imageModel
  * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
  * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
  * @param \Magento\Framework\Escaper $escaper
  * @param \Magento\Framework\UrlInterface $urlBuilder
  * @param array $data
  */
 public function __construct(\Mageplaza\Blog\Model\Post\Image $imageModel, \Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Escaper $escaper, \Magento\Framework\UrlInterface $urlBuilder, array $data)
 {
     $this->imageModel = $imageModel;
     parent::__construct($factoryElement, $factoryCollection, $escaper, $urlBuilder, $data);
 }