123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Customer\Block\Widget;
- use Magento\Customer\Api\CustomerMetadataInterface;
- use Magento\Customer\Api\CustomerRepositoryInterface;
- use Magento\Customer\Api\Data\CustomerInterface;
- use Magento\Customer\Api\Data\OptionInterface;
- /**
- * Block to render customer's gender attribute
- *
- * @SuppressWarnings(PHPMD.DepthOfInheritance)
- */
- class Gender extends AbstractWidget
- {
- /**
- * @var \Magento\Customer\Model\Session
- */
- protected $_customerSession;
- /**
- * @var CustomerRepositoryInterface
- */
- protected $customerRepository;
- /**
- * Create an instance of the Gender widget
- *
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Customer\Helper\Address $addressHelper
- * @param CustomerMetadataInterface $customerMetadata
- * @param CustomerRepositoryInterface $customerRepository
- * @param \Magento\Customer\Model\Session $customerSession
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Customer\Helper\Address $addressHelper,
- CustomerMetadataInterface $customerMetadata,
- CustomerRepositoryInterface $customerRepository,
- \Magento\Customer\Model\Session $customerSession,
- array $data = []
- ) {
- $this->_customerSession = $customerSession;
- $this->customerRepository = $customerRepository;
- parent::__construct($context, $addressHelper, $customerMetadata, $data);
- $this->_isScopePrivate = true;
- }
- /**
- * Initialize block
- *
- * @return void
- */
- public function _construct()
- {
- parent::_construct();
- $this->setTemplate('Magento_Customer::widget/gender.phtml');
- }
- /**
- * Check if gender attribute enabled in system
- *
- * @return bool
- */
- public function isEnabled()
- {
- return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isVisible() : false;
- }
- /**
- * Check if gender attribute marked as required
- *
- * @return bool
- */
- public function isRequired()
- {
- return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isRequired() : false;
- }
- /**
- * Retrieve store attribute label
- *
- * @param string $attributeCode
- *
- * @return string
- */
- public function getStoreLabel($attributeCode)
- {
- $attribute = $this->_getAttribute($attributeCode);
- return $attribute ? __($attribute->getStoreLabel()) : '';
- }
- /**
- * Get current customer from session
- *
- * @return CustomerInterface
- */
- public function getCustomer()
- {
- return $this->customerRepository->getById($this->_customerSession->getCustomerId());
- }
- /**
- * Returns options from gender attribute
- *
- * @return OptionInterface[]
- */
- public function getGenderOptions()
- {
- return $this->_getAttribute('gender')->getOptions();
- }
- }
|