_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; } }