Link.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Magento Form element renderer to display link element
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Framework\Data\Form\Element;
  12. use Magento\Framework\Escaper;
  13. class Link extends AbstractElement
  14. {
  15. /**
  16. * @param Factory $factoryElement
  17. * @param CollectionFactory $factoryCollection
  18. * @param Escaper $escaper
  19. * @param array $data
  20. */
  21. public function __construct(
  22. Factory $factoryElement,
  23. CollectionFactory $factoryCollection,
  24. Escaper $escaper,
  25. $data = []
  26. ) {
  27. parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
  28. $this->setType('link');
  29. }
  30. /**
  31. * Generates element html
  32. *
  33. * @return string
  34. */
  35. public function getElementHtml()
  36. {
  37. $html = $this->getBeforeElementHtml() . '<a id="' . $this->getHtmlId() . '" ' . $this->serialize(
  38. $this->getHtmlAttributes()
  39. ) . $this->_getUiId() . '>' . $this->getEscapedValue() . "</a>\n" . $this->getAfterElementHtml();
  40. return $html;
  41. }
  42. /**
  43. * Prepare array of anchor attributes
  44. *
  45. * @return string[]
  46. */
  47. public function getHtmlAttributes()
  48. {
  49. return [
  50. 'charset',
  51. 'coords',
  52. 'href',
  53. 'hreflang',
  54. 'rel',
  55. 'rev',
  56. 'name',
  57. 'shape',
  58. 'target',
  59. 'accesskey',
  60. 'class',
  61. 'dir',
  62. 'lang',
  63. 'style',
  64. 'tabindex',
  65. 'title',
  66. 'xml:lang',
  67. 'onblur',
  68. 'onclick',
  69. 'ondblclick',
  70. 'onfocus',
  71. 'onmousedown',
  72. 'onmousemove',
  73. 'onmouseout',
  74. 'onmouseover',
  75. 'onmouseup',
  76. 'onkeydown',
  77. 'onkeypress',
  78. 'onkeyup',
  79. 'data-role',
  80. 'data-action'
  81. ];
  82. }
  83. }