Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Gender.php
Go to the documentation of this file.
1 <?php
7 
12 
18 class Gender extends AbstractWidget
19 {
23  protected $_customerSession;
24 
29 
40  public function __construct(
41  \Magento\Framework\View\Element\Template\Context $context,
42  \Magento\Customer\Helper\Address $addressHelper,
45  \Magento\Customer\Model\Session $customerSession,
46  array $data = []
47  ) {
48  $this->_customerSession = $customerSession;
49  $this->customerRepository = $customerRepository;
50  parent::__construct($context, $addressHelper, $customerMetadata, $data);
51  $this->_isScopePrivate = true;
52  }
53 
59  public function _construct()
60  {
61  parent::_construct();
62  $this->setTemplate('Magento_Customer::widget/gender.phtml');
63  }
64 
69  public function isEnabled()
70  {
71  return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isVisible() : false;
72  }
73 
78  public function isRequired()
79  {
80  return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isRequired() : false;
81  }
82 
88  public function getCustomer()
89  {
90  return $this->customerRepository->getById($this->_customerSession->getCustomerId());
91  }
92 
97  public function getGenderOptions()
98  {
99  return $this->_getAttribute('gender')->getOptions();
100  }
101 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Helper\Address $addressHelper, CustomerMetadataInterface $customerMetadata, CustomerRepositoryInterface $customerRepository, \Magento\Customer\Model\Session $customerSession, array $data=[])
Definition: Gender.php:40