Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractWidget.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  protected $customerMetadata;
17 
21  protected $_addressHelper;
22 
29  public function __construct(
30  \Magento\Framework\View\Element\Template\Context $context,
31  \Magento\Customer\Helper\Address $addressHelper,
33  array $data = []
34  ) {
35  $this->_addressHelper = $addressHelper;
36  $this->customerMetadata = $customerMetadata;
37  parent::__construct($context, $data);
38  $this->_isScopePrivate = true;
39  }
40 
45  public function getConfig($key)
46  {
47  return $this->_addressHelper->getConfig($key);
48  }
49 
53  public function getFieldIdFormat()
54  {
55  if (!$this->hasData('field_id_format')) {
56  $this->setData('field_id_format', '%s');
57  }
58  return $this->getData('field_id_format');
59  }
60 
64  public function getFieldNameFormat()
65  {
66  if (!$this->hasData('field_name_format')) {
67  $this->setData('field_name_format', '%s');
68  }
69  return $this->getData('field_name_format');
70  }
71 
76  public function getFieldId($field)
77  {
78  return sprintf($this->getFieldIdFormat(), $field);
79  }
80 
85  public function getFieldName($field)
86  {
87  return sprintf($this->getFieldNameFormat(), $field);
88  }
89 
96  protected function _getAttribute($attributeCode)
97  {
98  try {
99  return $this->customerMetadata->getAttributeMetadata($attributeCode);
100  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
101  return null;
102  }
103  }
104 }
getData($key='', $index=null)
Definition: DataObject.php:119
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Helper\Address $addressHelper, CustomerMetadataInterface $customerMetadata, array $data=[])
$attributeCode
Definition: extend.phtml:12
setData($key, $value=null)
Definition: DataObject.php:72