Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
8 
13 {
19  const XML_PATH_VALIDATOR_DATA_INPUT_TYPES = 'general/validator_data/input_types';
20 
24  protected $_attributesLockedFields = [];
25 
30 
34  protected $_attributeConfig;
35 
39  protected $_eavConfig;
40 
47  public function __construct(
48  \Magento\Framework\App\Helper\Context $context,
49  \Magento\Eav\Model\Entity\Attribute\Config $attributeConfig,
50  \Magento\Eav\Model\Config $eavConfig
51  ) {
52  $this->_attributeConfig = $attributeConfig;
53  $this->_eavConfig = $eavConfig;
54  parent::__construct($context);
55  }
56 
62  protected function _getDefaultFrontendClasses()
63  {
64  return [
65  ['value' => '', 'label' => __('None')],
66  ['value' => 'validate-number', 'label' => __('Decimal Number')],
67  ['value' => 'validate-digits', 'label' => __('Integer Number')],
68  ['value' => 'validate-email', 'label' => __('Email')],
69  ['value' => 'validate-url', 'label' => __('URL')],
70  ['value' => 'validate-alpha', 'label' => __('Letters')],
71  ['value' => 'validate-alphanum', 'label' => __('Letters (a-z, A-Z) or Numbers (0-9)')]
72  ];
73  }
74 
82  {
83  $_defaultClasses = $this->_getDefaultFrontendClasses();
84 
85  if (isset($this->_entityTypeFrontendClasses[$entityTypeCode])) {
86  return array_merge($_defaultClasses, $this->_entityTypeFrontendClasses[$entityTypeCode]);
87  }
88 
89  return $_defaultClasses;
90  }
91 
99  {
100  if (!$entityTypeCode) {
101  return [];
102  }
103  if (isset($this->_attributesLockedFields[$entityTypeCode])) {
104  return $this->_attributesLockedFields[$entityTypeCode];
105  }
106  $attributesLockedFields = $this->_attributeConfig->getEntityAttributesLockedFields($entityTypeCode);
107  if (count($attributesLockedFields)) {
108  $this->_attributesLockedFields[$entityTypeCode] = $attributesLockedFields;
109  return $this->_attributesLockedFields[$entityTypeCode];
110  }
111  return [];
112  }
113 
119  public function getInputTypesValidatorData()
120  {
121  return $this->scopeConfig->getValue(
122  self::XML_PATH_VALIDATOR_DATA_INPUT_TYPES,
123  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
124  );
125  }
126 
140  {
141  $attribute = $this->_eavConfig->getAttribute($entityTypeCode, $attributeCode);
142  return [
143  'entity_type_id' => $attribute->getEntityTypeId(),
144  'attribute_id' => $attribute->getAttributeId(),
145  'attribute_table' => $attribute->getBackend()->getTable(),
146  'backend_type' => $attribute->getBackendType()
147  ];
148  }
149 }
const XML_PATH_VALIDATOR_DATA_INPUT_TYPES
Definition: Data.php:19
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Eav\Model\Entity\Attribute\Config $attributeConfig, \Magento\Eav\Model\Config $eavConfig)
Definition: Data.php:47
__()
Definition: __.php:13
getFrontendClasses($entityTypeCode)
Definition: Data.php:81
$attributeCode
Definition: extend.phtml:12
getAttributeMetadata($entityTypeCode, $attributeCode)
Definition: Data.php:139
getAttributeLockedFields($entityTypeCode)
Definition: Data.php:98