Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CatalogEavValidationRules.php
Go to the documentation of this file.
1 <?php
7 
9 
17 {
27  {
28  $rules = [];
29  if (!empty($data['required'])) {
30  $rules['required-entry'] = true;
31  }
32  if ($attribute->getFrontendInput() === 'price') {
33  $rules['validate-zero-or-greater'] = true;
34  }
35 
36  $validationClasses = explode(' ', $attribute->getFrontendClass());
37 
38  foreach ($validationClasses as $class) {
39  if (preg_match('/^maximum-length-(\d+)$/', $class, $matches)) {
40  $rules = array_merge($rules, ['max_text_length' => $matches[1]]);
41  continue;
42  }
43  if (preg_match('/^minimum-length-(\d+)$/', $class, $matches)) {
44  $rules = array_merge($rules, ['min_text_length' => $matches[1]]);
45  continue;
46  }
47 
48  $rules = $this->mapRules($class, $rules);
49  }
50 
51  return $rules;
52  }
53 
62  protected function mapRules($class, array $rules)
63  {
64  switch ($class) {
65  case 'validate-number':
66  case 'validate-digits':
67  case 'validate-email':
68  case 'validate-url':
69  case 'validate-alpha':
70  case 'validate-alphanum':
71  $rules = array_merge($rules, [$class => true]);
72  break;
73  }
74 
75  return $rules;
76  }
77 }
$_option $_optionId $class
Definition: date.phtml:13
build(ProductAttributeInterface $attribute, array $data)