Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Links.php
Go to the documentation of this file.
1 <?php
7 
15 {
21  public function getLinks()
22  {
23  return $this->_layout->getChildBlocks($this->getNameInLayout());
24  }
25 
32  protected function getLinkByPath($path)
33  {
34  foreach ($this->getLinks() as $link) {
35  if ($link->getPath() == $path) {
36  return $link;
37  }
38  }
39  }
40 
47  public function setActive($path)
48  {
49  $link = $this->getLinkByPath($path);
50  if ($link) {
51  $link->setIsHighlighted(true);
52  }
53  }
54 
61  public function renderLink(\Magento\Framework\View\Element\AbstractBlock $link)
62  {
63  return $this->_layout->renderElement($link->getNameInLayout());
64  }
65 
71  protected function _toHtml()
72  {
73  if (false != $this->getTemplate()) {
74  return parent::_toHtml();
75  }
76 
77  $html = '';
78  if ($this->getLinks()) {
79  $html = '<ul' . ($this->hasCssClass() ? ' class="' . $this->escapeHtml(
80  $this->getCssClass()
81  ) . '"' : '') . '>';
82  foreach ($this->getLinks() as $link) {
83  $html .= $this->renderLink($link);
84  }
85  $html .= '</ul>';
86  }
87 
88  return $html;
89  }
90 }