options = $options; parent::__construct($context, $addressHelper, $customerMetadata, $data); $this->addressMetadata = $addressMetadata; $this->_isScopePrivate = true; } /** * @return void */ public function _construct() { parent::_construct(); // default template location $this->setTemplate('Magento_Customer::widget/telephone.phtml'); } /** * Can show config value * * @param string $key * * @return bool */ protected function _showConfig($key) { return (bool)$this->getConfig($key); } /** * Can show prefix * * @return bool */ public function showTelephone() { return $this->_isAttributeVisible(self::ATTRIBUTE_CODE); } /** * @inheritdoc */ protected function _getAttribute($attributeCode) { if ($this->getForceUseCustomerAttributes() || $this->getObject() instanceof CustomerInterface) { return parent::_getAttribute($attributeCode); } try { $attribute = $this->addressMetadata->getAttributeMetadata($attributeCode); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { return null; } if ($this->getForceUseCustomerRequiredAttributes() && $attribute && !$attribute->isRequired()) { $customerAttribute = parent::_getAttribute($attributeCode); if ($customerAttribute && $customerAttribute->isRequired()) { $attribute = $customerAttribute; } } return $attribute; } /** * Retrieve store attribute label * * @param string $attributeCode * * @return string */ public function getStoreLabel($attributeCode) { $attribute = $this->_getAttribute($attributeCode); return $attribute ? __($attribute->getStoreLabel()) : ''; } /** * Get string with frontend validation classes for attribute * * @param string $attributeCode * * @return string */ public function getAttributeValidationClass($attributeCode) { return $this->_addressHelper->getAttributeValidationClass($attributeCode); } /** * @param string $attributeCode * * @return bool */ private function _isAttributeVisible($attributeCode) { $attributeMetadata = $this->_getAttribute($attributeCode); return $attributeMetadata ? (bool)$attributeMetadata->isVisible() : false; } /** * Check if telephone attribute enabled in system * * @return bool */ public function isEnabled() { return $this->_getAttribute(self::ATTRIBUTE_CODE) ? (bool)$this->_getAttribute(self::ATTRIBUTE_CODE)->isVisible( ) : false; } /** * Check if telephone attribute marked as required * * @return bool */ public function isRequired() { return $this->_getAttribute(self::ATTRIBUTE_CODE) ? (bool)$this->_getAttribute(self::ATTRIBUTE_CODE) ->isRequired() : false; } }