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 
12 {
18  protected $_href;
19 
25  protected $_title;
26 
32  protected $_anchorText;
33 
37  protected $_resourcePage;
38 
44  protected $_cmsPage;
45 
52  public function __construct(
53  \Magento\Framework\View\Element\Template\Context $context,
54  \Magento\Cms\Model\ResourceModel\Page $resourcePage,
55  \Magento\Cms\Helper\Page $cmsPage,
56  array $data = []
57  ) {
58  parent::__construct($context, $data);
59  $this->_resourcePage = $resourcePage;
60  $this->_cmsPage = $cmsPage;
61  }
62 
69  public function getHref()
70  {
71  if (!$this->_href) {
72  $this->_href = '';
73  if ($this->getData('href')) {
74  $this->_href = $this->getData('href');
75  } elseif ($this->getData('page_id')) {
76  $this->_href = $this->_cmsPage->getPageUrl($this->getData('page_id'));
77  }
78  }
79 
80  return $this->_href;
81  }
82 
89  public function getTitle()
90  {
91  if (!$this->_title) {
92  $this->_title = '';
93  if ($this->getData('title') !== null) {
94  // compare to null used here bc user can specify blank title
95  $this->_title = $this->getData('title');
96  } elseif ($this->getData('page_id')) {
97  $this->_title = $this->_resourcePage->getCmsPageTitleById($this->getData('page_id'));
98  } elseif ($this->getData('href')) {
99  $this->_title = $this->_resourcePage->setStore($this->_storeManager->getStore())
100  ->getCmsPageTitleByIdentifier($this->getData('href'));
101  }
102  }
103 
104  return $this->_title;
105  }
106 
114  public function getLabel()
115  {
116  if ($this->getData('anchor_text')) {
117  $this->_anchorText = $this->getData('anchor_text');
118  } elseif ($this->getData('href')) {
119  $this->_anchorText = $this->_resourcePage->setStore(
120  $this->_storeManager->getStore()
121  )->getCmsPageTitleByIdentifier(
122  $this->getData('href')
123  );
124  } elseif ($this->getData('page_id')) {
125  $this->_anchorText = $this->_resourcePage->getCmsPageTitleById($this->getData('page_id'));
126  } elseif ($this->getTitle()) {
127  $this->_anchorText = $this->getTitle();
128  } else {
129  $this->_anchorText = $this->getData('href');
130  }
131 
132  return $this->_anchorText;
133  }
134 }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17