@@ -72,20 +72,17 @@ public function validateValue($value)
72
72
return true ;
73
73
}
74
74
75
- if (empty ($ value ) && $ value !== '0 ' && $ attribute ->getDefaultValue () == NULL ) {
75
+ if (empty ($ value ) && $ value !== '0 ' && $ attribute ->getDefaultValue () === null ) {
76
76
$ label = __ ($ attribute ->getStoreLabel ());
77
77
$ errors [] = __ ('"%1" is a required value. ' , $ label );
78
78
}
79
79
80
- $ result = $ this ->validateLength ($ attribute , $ value );
81
- if (count ($ result ) !== 0 ) {
82
- $ errors = array_merge ($ errors , $ result );
83
- }
80
+ $ validateLengthResult = $ this ->validateLength ($ attribute , $ value );
81
+ $ errors = array_merge ($ errors , $ validateLengthResult );
82
+
83
+ $ validateInputRuleResult = $ this ->validateInputRule ($ value );
84
+ $ errors = array_merge ($ errors , $ validateInputRuleResult );
84
85
85
- $ result = $ this ->_validateInputRule ($ value );
86
- if ($ result !== true ) {
87
- $ errors = array_merge ($ errors , $ result );
88
- }
89
86
if (count ($ errors ) == 0 ) {
90
87
return true ;
91
88
}
@@ -141,7 +138,7 @@ public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::O
141
138
* @param string $value
142
139
* @return array errors
143
140
*/
144
- private function validateLength (\Magento \Eav \Model \Attribute $ attribute , $ value ): array
141
+ private function validateLength (\Magento \Eav \Model \Attribute $ attribute , string $ value ): array
145
142
{
146
143
$ errors = [];
147
144
$ length = $ this ->_string ->strlen (trim ($ value ));
@@ -162,4 +159,16 @@ private function validateLength(\Magento\Eav\Model\Attribute $attribute, $value)
162
159
163
160
return $ errors ;
164
161
}
162
+
163
+ /**
164
+ * Validate value by attribute input validation rule.
165
+ *
166
+ * @param string $value
167
+ * @return array
168
+ */
169
+ private function validateInputRule (string $ value ): array
170
+ {
171
+ $ result = $ this ->_validateInputRule ($ value );
172
+ return \is_array ($ result ) ? $ result : [];
173
+ }
165
174
}
0 commit comments