Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Logo.php
Go to the documentation of this file.
1 <?php
8 
16 {
22  protected $_template = 'Magento_Theme::html/header/logo.phtml';
23 
28 
34  public function __construct(
35  \Magento\Framework\View\Element\Template\Context $context,
36  \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageHelper,
37  array $data = []
38  ) {
39  $this->_fileStorageHelper = $fileStorageHelper;
40  parent::__construct($context, $data);
41  }
42 
48  public function isHomePage()
49  {
50  $currentUrl = $this->getUrl('', ['_current' => true]);
51  $urlRewrite = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
52  return $currentUrl == $urlRewrite;
53  }
54 
60  public function getLogoSrc()
61  {
62  if (empty($this->_data['logo_src'])) {
63  $this->_data['logo_src'] = $this->_getLogoUrl();
64  }
65  return $this->_data['logo_src'];
66  }
67 
73  public function getLogoAlt()
74  {
75  if (empty($this->_data['logo_alt'])) {
76  $this->_data['logo_alt'] = $this->_scopeConfig->getValue(
77  'design/header/logo_alt',
78  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
79  );
80  }
81  return $this->_data['logo_alt'];
82  }
83 
89  public function getLogoWidth()
90  {
91  if (empty($this->_data['logo_width'])) {
92  $this->_data['logo_width'] = $this->_scopeConfig->getValue(
93  'design/header/logo_width',
94  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
95  );
96  }
97  return (int)$this->_data['logo_width'] ? : (int)$this->getLogoImgWidth();
98  }
99 
105  public function getLogoHeight()
106  {
107  if (empty($this->_data['logo_height'])) {
108  $this->_data['logo_height'] = $this->_scopeConfig->getValue(
109  'design/header/logo_height',
110  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
111  );
112  }
113  return (int)$this->_data['logo_height'] ? : (int)$this->getLogoImgHeight();
114  }
115 
121  protected function _getLogoUrl()
122  {
123  $folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR;
124  $storeLogoPath = $this->_scopeConfig->getValue(
125  'design/header/logo_src',
126  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
127  );
128  $path = $folderName . '/' . $storeLogoPath;
129  $logoUrl = $this->_urlBuilder
130  ->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path;
131 
132  if ($storeLogoPath !== null && $this->_isFile($path)) {
133  $url = $logoUrl;
134  } elseif ($this->getLogoFile()) {
135  $url = $this->getViewFileUrl($this->getLogoFile());
136  } else {
137  $url = $this->getViewFileUrl('images/logo.svg');
138  }
139  return $url;
140  }
141 
148  protected function _isFile($filename)
149  {
150  if ($this->_fileStorageHelper->checkDbUsage() && !$this->getMediaDirectory()->isFile($filename)) {
151  $this->_fileStorageHelper->saveFileToFilesystem($filename);
152  }
153 
154  return $this->getMediaDirectory()->isFile($filename);
155  }
156 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageHelper, array $data=[])
Definition: Logo.php:34