Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeMapper.php
Go to the documentation of this file.
1 <?php
7 
13 {
19  private $formElementMap = [
20  'text' => 'input',
21  'hidden' => 'input',
22  'boolean' => 'checkbox',
23  ];
24 
29  private $metaPropertiesMap = [
30  'dataType' => 'getFrontendInput',
31  'visible' => 'getIsVisible',
32  'required' => 'getIsRequired',
33  'label' => 'getStoreLabel',
34  'sortOrder' => 'getSortOrder',
35  'notice' => 'getNote',
36  'default' => 'getDefaultValue',
37  'size' => 'getMultilineCount'
38  ];
39 
43  protected $validationRules = [
44  'input_validation' => [
45  'email' => ['validate-email' => true],
46  'date' => ['validate-date' => true],
47  ],
48  ];
49 
57  public function map($attribute)
58  {
59  foreach ($this->metaPropertiesMap as $metaName => $methodName) {
60  $value = $attribute->$methodName();
61  $meta[$metaName] = $value;
62  if ('getFrontendInput' === $methodName) {
63  $meta['formElement'] = isset($this->formElementMap[$value])
64  ? $this->formElementMap[$value]
65  : $value;
66  }
67  }
68  if ($attribute->usesSource()) {
69  $meta['options'] = $attribute->getSource()->getAllOptions();
70  }
71 
72  $rules = [];
73  if (isset($meta['required']) && $meta['required'] == 1) {
74  $rules['required-entry'] = true;
75  }
76  foreach ($attribute->getValidateRules() as $name => $value) {
77  if (isset($this->validationRules[$name][$value])) {
78  $rules = array_merge($rules, $this->validationRules[$name][$value]);
79  } else {
80  $rules[$name] = $value;
81  }
82  }
83  $meta['validation'] = $rules;
84  return $meta;
85  }
86 }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14