6
6
namespace Magento \Customer \Model \Metadata \Form ;
7
7
8
8
use Magento \Customer \Api \Data \AttributeMetadataInterface ;
9
- use Magento \Customer \Model \Metadata \ElementFactory ;
10
9
use Magento \Directory \Helper \Data as DirectoryHelper ;
11
- use Magento \Framework \Api \ArrayObjectSearch ;
12
10
use Magento \Framework \Stdlib \StringUtils ;
13
11
use Magento \Framework \Locale \ResolverInterface ;
14
12
use Psr \Log \LoggerInterface as PsrLogger ;
17
15
/**
18
16
* Customer Address Postal/Zip Code Attribute Data Model
19
17
*/
20
- class Postcode extends AbstractData
18
+ class Postcode extends Text
21
19
{
22
20
/**
23
21
* @var DirectoryHelper
24
22
*/
25
- protected $ directoryHelper ;
23
+ protected DirectoryHelper $ directoryHelper ;
26
24
27
25
/**
28
26
* @var StringUtils
@@ -52,7 +50,7 @@ public function __construct(
52
50
StringUtils $ stringHelper = null
53
51
) {
54
52
$ this ->directoryHelper = $ directoryHelper ;
55
- if (is_null ( $ stringHelper) ) {
53
+ if ($ stringHelper === null ) {
56
54
$ stringHelper = \Magento \Framework \App \ObjectManager::getInstance ()->get (StringUtils::class);
57
55
}
58
56
$ this ->_string = $ stringHelper ;
@@ -63,7 +61,8 @@ public function __construct(
63
61
$ localeResolver ,
64
62
$ value ,
65
63
$ entityTypeCode ,
66
- $ isAjax
64
+ $ isAjax ,
65
+ $ stringHelper
67
66
);
68
67
}
69
68
@@ -102,74 +101,4 @@ public function validateValue($value)
102
101
}
103
102
return $ errors ;
104
103
}
105
-
106
- /**
107
- * @inheritdoc
108
- */
109
- public function extractValue (\Magento \Framework \App \RequestInterface $ request )
110
- {
111
- return $ this ->_applyInputFilter ($ this ->_getRequestValue ($ request ));
112
- }
113
-
114
- /**
115
- * @inheritdoc
116
- */
117
- public function compactValue ($ value )
118
- {
119
- return $ value ;
120
- }
121
-
122
- /**
123
- * @inheritdoc
124
- */
125
- public function restoreValue ($ value )
126
- {
127
- return $ this ->compactValue ($ value );
128
- }
129
-
130
- /**
131
- * @inheritdoc
132
- */
133
- public function outputValue ($ format = ElementFactory::OUTPUT_FORMAT_TEXT )
134
- {
135
- return $ this ->_applyOutputFilter ($ this ->_value );
136
- }
137
-
138
- /**
139
- * Length validation
140
- *
141
- * @param mixed $value
142
- * @param AttributeMetadataInterface $attribute
143
- * @param array $errors
144
- * @return array
145
- */
146
- private function validateLength ($ value , AttributeMetadataInterface $ attribute , array $ errors ): array
147
- {
148
- // validate length
149
- $ label = __ ($ attribute ->getStoreLabel ());
150
-
151
- $ length = $ value ? $ this ->_string ->strlen (trim ($ value )) : 0 ;
152
-
153
- $ validateRules = $ attribute ->getValidationRules ();
154
-
155
- if (!empty (ArrayObjectSearch::getArrayElementByName ($ validateRules , 'input_validation ' ))) {
156
- $ minTextLength = ArrayObjectSearch::getArrayElementByName (
157
- $ validateRules ,
158
- 'min_text_length '
159
- );
160
- if ($ minTextLength !== null && $ length < $ minTextLength ) {
161
- $ errors [] = __ ('"%1" length must be equal or greater than %2 characters. ' , $ label , $ minTextLength );
162
- }
163
-
164
- $ maxTextLength = ArrayObjectSearch::getArrayElementByName (
165
- $ validateRules ,
166
- 'max_text_length '
167
- );
168
- if ($ maxTextLength !== null && $ length > $ maxTextLength ) {
169
- $ errors [] = __ ('"%1" length must be equal or less than %2 characters. ' , $ label , $ maxTextLength );
170
- }
171
- }
172
-
173
- return $ errors ;
174
- }
175
104
}
0 commit comments