Skip to content

Commit 4fa922f

Browse files
author
Sergey Shvets
committed
MAGETWO-86239: Customer Address attribute value length is still validated when min/max length fields are not displayed at the backend
1 parent 7a6d77c commit 4fa922f

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

app/code/Magento/Ui/DataProvider/EavValidationRules.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Ui\DataProvider;
78

89
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
@@ -31,25 +32,51 @@ class EavValidationRules
3132
*/
3233
public function build(AbstractAttribute $attribute, array $data)
3334
{
34-
$validation = [];
35+
$validations = [];
3536
if (isset($data['required']) && $data['required'] == 1) {
36-
$validation = array_merge($validation, ['required-entry' => true]);
37+
$validations = array_merge($validations, ['required-entry' => true]);
3738
}
3839
if ($attribute->getFrontendInput() === 'price') {
39-
$validation = array_merge($validation, ['validate-zero-or-greater' => true]);
40+
$validations = array_merge($validations, ['validate-zero-or-greater' => true]);
4041
}
4142
if ($attribute->getValidateRules()) {
42-
$validation = array_merge($validation, $attribute->getValidateRules());
43+
$validations = array_merge($validations, $this->clipLengthRules($attribute->getValidateRules()));
4344
}
45+
return $this->aggregateRules($validations);
46+
}
47+
48+
/**
49+
* @param array $validations
50+
* @return array
51+
*/
52+
protected function aggregateRules(array $validations): array
53+
{
4454
$rules = [];
45-
foreach ($validation as $type => $ruleName) {
46-
$rule = [$type => $ruleName];
55+
foreach ($validations as $type => $ruleValue) {
56+
$rule = [$type => $ruleValue];
4757
if ($type === 'input_validation') {
48-
$rule = isset($this->validationRules[$ruleName]) ? $this->validationRules[$ruleName] : [];
58+
$rule = $this->validationRules[$ruleValue] ?? [];
59+
}
60+
if (count($rule) !== 0) {
61+
$key = key($rule);
62+
$rules[$key] = $rule[$key];
4963
}
50-
$rules = array_merge($rules, $rule);
5164
}
65+
return $rules;
66+
}
5267

68+
/**
69+
* @param array $rules
70+
* @return array
71+
*/
72+
private function clipLengthRules(array $rules): array
73+
{
74+
if (empty($validateRules['input_validation'])) {
75+
unset(
76+
$rules['min_text_length'],
77+
$rules['max_text_length']
78+
);
79+
}
5380
return $rules;
5481
}
5582
}

0 commit comments

Comments
 (0)