Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Contact\Helper;
8 
11 use Magento\Customer\Helper\View as CustomerViewHelper;
14 
22 {
24 
30  protected $_customerSession;
31 
36 
40  private $dataPersistor;
41 
45  private $postData = null;
46 
52  public function __construct(
53  \Magento\Framework\App\Helper\Context $context,
54  \Magento\Customer\Model\Session $customerSession,
55  CustomerViewHelper $customerViewHelper
56  ) {
57  $this->_customerSession = $customerSession;
58  $this->_customerViewHelper = $customerViewHelper;
59  parent::__construct($context);
60  }
61 
68  public function isEnabled()
69  {
70  return $this->scopeConfig->getValue(
71  self::XML_PATH_ENABLED,
72  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
73  );
74  }
75 
81  public function getUserName()
82  {
83  if (!$this->_customerSession->isLoggedIn()) {
84  return '';
85  }
89  $customer = $this->_customerSession->getCustomerDataObject();
90 
91  return trim($this->_customerViewHelper->getCustomerName($customer));
92  }
93 
99  public function getUserEmail()
100  {
101  if (!$this->_customerSession->isLoggedIn()) {
102  return '';
103  }
107  $customer = $this->_customerSession->getCustomerDataObject();
108 
109  return $customer->getEmail();
110  }
111 
118  public function getPostValue($key)
119  {
120  if (null === $this->postData) {
121  $this->postData = (array) $this->getDataPersistor()->get('contact_us');
122  $this->getDataPersistor()->clear('contact_us');
123  }
124 
125  if (isset($this->postData[$key])) {
126  return (string) $this->postData[$key];
127  }
128 
129  return '';
130  }
131 
137  private function getDataPersistor()
138  {
139  if ($this->dataPersistor === null) {
140  $this->dataPersistor = ObjectManager::getInstance()
141  ->get(DataPersistorInterface::class);
142  }
143 
144  return $this->dataPersistor;
145  }
146 }
$customer
Definition: customers.php:11
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Customer\Model\Session $customerSession, CustomerViewHelper $customerViewHelper)
Definition: Data.php:52