123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Contact\Helper;
- use Magento\Contact\Model\ConfigInterface;
- use Magento\Customer\Api\Data\CustomerInterface;
- use Magento\Customer\Helper\View as CustomerViewHelper;
- use Magento\Framework\App\ObjectManager;
- use Magento\Framework\App\Request\DataPersistorInterface;
- /**
- * Contact base helper
- *
- * @deprecated 100.2.0
- * @see \Magento\Contact\Model\ConfigInterface
- */
- class Data extends \Magento\Framework\App\Helper\AbstractHelper
- {
- const XML_PATH_ENABLED = ConfigInterface::XML_PATH_ENABLED;
- /**
- * Customer session
- *
- * @var \Magento\Customer\Model\Session
- */
- protected $_customerSession;
- /**
- * @var \Magento\Customer\Helper\View
- */
- protected $_customerViewHelper;
- /**
- * @var DataPersistorInterface
- */
- private $dataPersistor;
- /**
- * @var array
- */
- private $postData = null;
- /**
- * @param \Magento\Framework\App\Helper\Context $context
- * @param \Magento\Customer\Model\Session $customerSession
- * @param CustomerViewHelper $customerViewHelper
- */
- public function __construct(
- \Magento\Framework\App\Helper\Context $context,
- \Magento\Customer\Model\Session $customerSession,
- CustomerViewHelper $customerViewHelper
- ) {
- $this->_customerSession = $customerSession;
- $this->_customerViewHelper = $customerViewHelper;
- parent::__construct($context);
- }
- /**
- * Check if enabled
- *
- * @return string|null
- * @deprecated 100.2.0 use \Magento\Contact\Api\ConfigInterface::isEnabled() instead
- */
- public function isEnabled()
- {
- return $this->scopeConfig->getValue(
- self::XML_PATH_ENABLED,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- );
- }
- /**
- * Get user name
- *
- * @return string
- */
- public function getUserName()
- {
- if (!$this->_customerSession->isLoggedIn()) {
- return '';
- }
- /**
- * @var \Magento\Customer\Api\Data\CustomerInterface $customer
- */
- $customer = $this->_customerSession->getCustomerDataObject();
- return trim($this->_customerViewHelper->getCustomerName($customer));
- }
- /**
- * Get user email
- *
- * @return string
- */
- public function getUserEmail()
- {
- if (!$this->_customerSession->isLoggedIn()) {
- return '';
- }
- /**
- * @var CustomerInterface $customer
- */
- $customer = $this->_customerSession->getCustomerDataObject();
- return $customer->getEmail();
- }
- /**
- * Get value from POST by key
- *
- * @param string $key
- * @return string
- */
- public function getPostValue($key)
- {
- if (null === $this->postData) {
- $this->postData = (array) $this->getDataPersistor()->get('contact_us');
- $this->getDataPersistor()->clear('contact_us');
- }
- if (isset($this->postData[$key])) {
- return (string) $this->postData[$key];
- }
- return '';
- }
- /**
- * Get Data Persistor
- *
- * @return DataPersistorInterface
- */
- private function getDataPersistor()
- {
- if ($this->dataPersistor === null) {
- $this->dataPersistor = ObjectManager::getInstance()
- ->get(DataPersistorInterface::class);
- }
- return $this->dataPersistor;
- }
- }
|