Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Register.php
Go to the documentation of this file.
1 <?php
7 
9 
18 {
22  protected $_customerSession;
23 
27  protected $_moduleManager;
28 
32  protected $_customerUrl;
33 
50  public function __construct(
51  \Magento\Framework\View\Element\Template\Context $context,
52  \Magento\Directory\Helper\Data $directoryHelper,
53  \Magento\Framework\Json\EncoderInterface $jsonEncoder,
54  \Magento\Framework\App\Cache\Type\Config $configCacheType,
55  \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory,
56  \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory,
57  \Magento\Framework\Module\Manager $moduleManager,
58  \Magento\Customer\Model\Session $customerSession,
59  \Magento\Customer\Model\Url $customerUrl,
60  array $data = []
61  ) {
62  $this->_customerUrl = $customerUrl;
63  $this->_moduleManager = $moduleManager;
64  $this->_customerSession = $customerSession;
65  parent::__construct(
66  $context,
68  $jsonEncoder,
69  $configCacheType,
70  $regionCollectionFactory,
71  $countryCollectionFactory,
72  $data
73  );
74  $this->_isScopePrivate = false;
75  }
76 
83  public function getConfig($path)
84  {
85  return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
86  }
87 
91  protected function _prepareLayout()
92  {
93  $this->pageConfig->getTitle()->set(__('Create New Customer Account'));
94  return parent::_prepareLayout();
95  }
96 
102  public function getPostActionUrl()
103  {
104  return $this->_customerUrl->getRegisterPostUrl();
105  }
106 
112  public function getBackUrl()
113  {
114  $url = $this->getData('back_url');
115  if ($url === null) {
116  $url = $this->_customerUrl->getLoginUrl();
117  }
118  return $url;
119  }
120 
126  public function getFormData()
127  {
128  $data = $this->getData('form_data');
129  if ($data === null) {
130  $formData = $this->_customerSession->getCustomerFormData(true);
131  $data = new \Magento\Framework\DataObject();
132  if ($formData) {
133  $data->addData($formData);
134  $data->setCustomerData(1);
135  }
136  if (isset($data['region_id'])) {
137  $data['region_id'] = (int)$data['region_id'];
138  }
139  $this->setData('form_data', $data);
140  }
141  return $data;
142  }
143 
149  public function getCountryId()
150  {
151  $countryId = $this->getFormData()->getCountryId();
152  if ($countryId) {
153  return $countryId;
154  }
155  return parent::getCountryId();
156  }
157 
163  public function getRegion()
164  {
165  if (null !== ($region = $this->getFormData()->getRegion())) {
166  return $region;
167  } elseif (null !== ($region = $this->getFormData()->getRegionId())) {
168  return $region;
169  }
170  return null;
171  }
172 
178  public function isNewsletterEnabled()
179  {
180  return $this->_moduleManager->isOutputEnabled('Magento_Newsletter');
181  }
182 
191  public function restoreSessionData(\Magento\Customer\Model\Metadata\Form $form, $scope = null)
192  {
193  if ($this->getFormData()->getCustomerData()) {
194  $request = $form->prepareRequest($this->getFormData()->getData());
195  $data = $form->extractData($request, $scope, false);
196  $form->restoreData($data);
197  }
198 
199  return $this;
200  }
201 
208  public function getMinimumPasswordLength()
209  {
210  return $this->_scopeConfig->getValue(AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH);
211  }
212 
220  {
221  return $this->_scopeConfig->getValue(AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER);
222  }
223 }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$customerUrl
Definition: info.phtml:28
__()
Definition: __.php:13
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Directory\Helper\Data $directoryHelper, \Magento\Framework\Json\EncoderInterface $jsonEncoder, \Magento\Framework\App\Cache\Type\Config $configCacheType, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, \Magento\Framework\Module\Manager $moduleManager, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Url $customerUrl, array $data=[])
Definition: Register.php:50
$moduleManager
Definition: products.php:75
setData($key, $value=null)
Definition: DataObject.php:72
restoreSessionData(\Magento\Customer\Model\Metadata\Form $form, $scope=null)
Definition: Register.php:191