Image.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Customer Widget Form Image File Element Block
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Customer\Block\Adminhtml\Form\Element;
  12. class Image extends \Magento\Customer\Block\Adminhtml\Form\Element\File
  13. {
  14. /**
  15. * Return Delete CheckBox Label
  16. *
  17. * @return \Magento\Framework\Phrase
  18. */
  19. protected function _getDeleteCheckboxLabel()
  20. {
  21. return __('Delete Image');
  22. }
  23. /**
  24. * Return Delete CheckBox SPAN Class name
  25. *
  26. * @return string
  27. */
  28. protected function _getDeleteCheckboxSpanClass()
  29. {
  30. return 'delete-image';
  31. }
  32. /**
  33. * Return File preview link HTML
  34. *
  35. * @return string
  36. */
  37. protected function _getPreviewHtml()
  38. {
  39. $html = '';
  40. if ($this->getValue() && !is_array($this->getValue())) {
  41. $url = $this->_getPreviewUrl();
  42. $imageId = sprintf('%s_image', $this->getHtmlId());
  43. $image = [
  44. 'alt' => __('View Full Size'),
  45. 'title' => __('View Full Size'),
  46. 'src' => $url,
  47. 'class' => 'small-image-preview v-middle',
  48. 'height' => 22,
  49. 'width' => 22,
  50. 'id' => $imageId
  51. ];
  52. $link = ['href' => $url, 'onclick' => "imagePreview('{$imageId}'); return false;"];
  53. $html = sprintf(
  54. '%s%s</a> ',
  55. $this->_drawElementHtml('a', $link, false),
  56. $this->_drawElementHtml('img', $image)
  57. );
  58. }
  59. return $html;
  60. }
  61. /**
  62. * Return Image URL
  63. *
  64. * @return string
  65. */
  66. protected function _getPreviewUrl()
  67. {
  68. return $this->_adminhtmlData->getUrl(
  69. 'customer/index/viewfile',
  70. ['image' => $this->urlEncoder->encode($this->getValue())]
  71. );
  72. }
  73. }