|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / app / code / Makarovsoft / Email / Block / Adminhtml / Template / Helper / |
Filename | /home/dev2.destoffenstraat.com/app/code/Makarovsoft/Email/Block/Adminhtml/Template/Helper/File.php |
Size | 2.76 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 06-Apr-2021 18:06 |
Last accessed | 23-Aug-2025 02:07 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace Makarovsoft\Email\Block\Adminhtml\Template\Helper;
use Magento\Framework\Data\Form\Element\File as FileField;
use Magento\Framework\Data\Form\Element\Factory as ElementFactory;
use Magento\Framework\Data\Form\Element\CollectionFactory as ElementCollectionFactory;
use Magento\Framework\Escaper;
use Makarovsoft\Email\Model\Template\File as TemplateFile;
use Magento\Framework\UrlInterface;
/**
* @method string getValue()
* @method bool getDisabled()
* @method File setExtType(\string $extType)
*/
class File extends FileField
{
protected $fileModel;
public function __construct(
TemplateFile $fileModel,
ElementFactory $factoryElement,
ElementCollectionFactory $factoryCollection,
Escaper $escaper,
$data = []
)
{
$this->fileModel = $fileModel;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->setType('file');
$this->setExtType('file');
}
/**
* @return string
*/
public function getElementHtml()
{
$html = '';
$this->addClass('input-file');
$html .= parent::getElementHtml();
if ($this->getValue()) {
$url = $this->_getUrl();
if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) {
$url = $this->fileModel->getBaseUrl() . $url;
}
$html .= '<br /><a href="'.$url.'">'.$this->_getUrl().'</a> ';
}
$html .= $this->_getDeleteCheckbox();
return $html;
}
/**
* @return string
*/
protected function _getDeleteCheckbox()
{
$html = '';
if ($this->getValue()) {
$label = __('Delete File');
$html .= '<span class="delete-image">';
$html .= '<input type="checkbox" name="'.
parent::getName().'[delete]" value="1" class="checkbox" id="'.
$this->getHtmlId().'_delete"'.($this->getDisabled() ? ' disabled="disabled"': '').'/>';
$html .= '<label for="'.$this->getHtmlId().'_delete"'.($this->getDisabled() ? ' class="disabled"' : '').'>';
$html .= $label.'</label>';
$html .= $this->_getHiddenInput();
$html .= '</span>';
}
return $html;
}
/**
* @return string
*/
protected function _getHiddenInput()
{
return '<input type="hidden" name="'.parent::getName().'[value]" value="'.$this->getValue().'" />';
}
/**
* @return string
*/
protected function _getUrl()
{
return $this->getValue();
}
/**
* @return mixed
*/
public function getName()
{
return $this->getData('name');
}
}
namespace Makarovsoft\Email\Block\Adminhtml\Template\Helper;
use Magento\Framework\Data\Form\Element\File as FileField;
use Magento\Framework\Data\Form\Element\Factory as ElementFactory;
use Magento\Framework\Data\Form\Element\CollectionFactory as ElementCollectionFactory;
use Magento\Framework\Escaper;
use Makarovsoft\Email\Model\Template\File as TemplateFile;
use Magento\Framework\UrlInterface;
/**
* @method string getValue()
* @method bool getDisabled()
* @method File setExtType(\string $extType)
*/
class File extends FileField
{
protected $fileModel;
public function __construct(
TemplateFile $fileModel,
ElementFactory $factoryElement,
ElementCollectionFactory $factoryCollection,
Escaper $escaper,
$data = []
)
{
$this->fileModel = $fileModel;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->setType('file');
$this->setExtType('file');
}
/**
* @return string
*/
public function getElementHtml()
{
$html = '';
$this->addClass('input-file');
$html .= parent::getElementHtml();
if ($this->getValue()) {
$url = $this->_getUrl();
if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) {
$url = $this->fileModel->getBaseUrl() . $url;
}
$html .= '<br /><a href="'.$url.'">'.$this->_getUrl().'</a> ';
}
$html .= $this->_getDeleteCheckbox();
return $html;
}
/**
* @return string
*/
protected function _getDeleteCheckbox()
{
$html = '';
if ($this->getValue()) {
$label = __('Delete File');
$html .= '<span class="delete-image">';
$html .= '<input type="checkbox" name="'.
parent::getName().'[delete]" value="1" class="checkbox" id="'.
$this->getHtmlId().'_delete"'.($this->getDisabled() ? ' disabled="disabled"': '').'/>';
$html .= '<label for="'.$this->getHtmlId().'_delete"'.($this->getDisabled() ? ' class="disabled"' : '').'>';
$html .= $label.'</label>';
$html .= $this->_getHiddenInput();
$html .= '</span>';
}
return $html;
}
/**
* @return string
*/
protected function _getHiddenInput()
{
return '<input type="hidden" name="'.parent::getName().'[value]" value="'.$this->getValue().'" />';
}
/**
* @return string
*/
protected function _getUrl()
{
return $this->getValue();
}
/**
* @return mixed
*/
public function getName()
{
return $this->getData('name');
}
}