Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Link.php
Go to the documentation of this file.
1 <?php
7 
18 {
22  protected $allowedAttributes = [
23  'href',
24  'title',
25  'charset',
26  'name',
27  'target',
28  'hreflang',
29  'rel',
30  'rev',
31  'accesskey',
32  'shape',
33  'coords',
34  'tabindex',
35  'onfocus',
36  'onblur', // %attrs
37  'id',
38  'class',
39  'style', // %coreattrs
40  'lang',
41  'dir', // %i18n
42  'onclick',
43  'ondblclick',
44  'onmousedown',
45  'onmouseup',
46  'onmouseover',
47  'onmousemove',
48  'onmouseout',
49  'onkeypress',
50  'onkeydown',
51  'onkeyup', // %events
52  ];
53 
59  public function getLinkAttributes()
60  {
61  $attributes = [];
62  foreach ($this->allowedAttributes as $attribute) {
63  $value = $this->getDataUsingMethod($attribute);
64  if ($value !== null) {
66  }
67  }
68 
69  if (!empty($attributes)) {
70  return $this->serialize($attributes);
71  }
72 
73  return '';
74  }
75 
85  public function serialize($attributes = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"')
86  {
87  $data = [];
88  foreach ($attributes as $key => $value) {
89  $data[] = $key . $valueSeparator . $quote . $value . $quote;
90  }
91 
92  return implode($fieldSeparator, $data);
93  }
94 
100  protected function _toHtml()
101  {
102  if (false != $this->getTemplate()) {
103  return parent::_toHtml();
104  }
105 
106  return '<li><a ' . $this->getLinkAttributes() . ' >' . $this->escapeHtml($this->getLabel()) . '</a></li>';
107  }
108 
114  public function getHref()
115  {
116  return $this->getUrl($this->getPath());
117  }
118 }
getDataUsingMethod($key, $args=null)
Definition: DataObject.php:218
$quote
$value
Definition: gender.phtml:16
$attributes
Definition: matrix.phtml:13