@@ -41,6 +41,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
41
41
*/
42
42
const MAX_FILE_SIZE = 2097152 ;
43
43
44
+ /**
45
+ * Says that data is provided to admin and admin user will see customer account
46
+ */
47
+ const ADMIN_SCOPE = "admin " ;
48
+
49
+ /**
50
+ * Says that data is provided to customer
51
+ */
52
+ const FRONTEND_SCOPE = "frontend " ;
53
+
44
54
/**
45
55
* @var Collection
46
56
*/
@@ -127,6 +137,14 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
127
137
*/
128
138
private $ context ;
129
139
140
+ /**
141
+ * Enum: can be frontend or admin
142
+ * Shows what user is used dataProvider
143
+ *
144
+ * @var string
145
+ */
146
+ private $ userScope ;
147
+
130
148
/**
131
149
* @param string $name
132
150
* @param string $primaryFieldName
@@ -151,7 +169,8 @@ public function __construct(
151
169
FileProcessorFactory $ fileProcessorFactory = null ,
152
170
ContextInterface $ context = null ,
153
171
array $ meta = [],
154
- array $ data = []
172
+ array $ data = [],
173
+ $ userScope = self ::ADMIN_SCOPE
155
174
) {
156
175
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data );
157
176
$ this ->eavValidationRules = $ eavValidationRules ;
@@ -161,6 +180,7 @@ public function __construct(
161
180
$ this ->filterPool = $ filterPool ;
162
181
$ this ->fileProcessorFactory = $ fileProcessorFactory ?: $ this ->getFileProcessorFactory ();
163
182
$ this ->context = $ context ?: ObjectManager::getInstance ()->get (ContextInterface::class);
183
+ $ this ->userScope = $ userScope ;
164
184
$ this ->meta ['customer ' ]['children ' ] = $ this ->getAttributesMeta (
165
185
$ this ->eavConfig ->getEntityType ('customer ' )
166
186
);
@@ -339,10 +359,8 @@ protected function getAttributesMeta(Type $entityType)
339
359
}
340
360
341
361
$ meta [$ code ]['arguments ' ]['data ' ]['config ' ]['componentType ' ] = Field::NAME ;
362
+ $ meta [$ code ]['arguments ' ]['data ' ]['config ' ]['visible ' ] = $ this ->canShowAttribute ($ attribute );
342
363
343
- if ($ this ->canShowAttribute ($ attribute )) {
344
- $ meta [$ code ]['arguments ' ]['data ' ]['config ' ]['visible ' ] = true ;
345
- }
346
364
347
365
$ this ->overrideFileUploaderMetadata ($ entityType , $ attribute , $ meta [$ code ]['arguments ' ]['data ' ]['config ' ]);
348
366
}
@@ -360,12 +378,20 @@ protected function getAttributesMeta(Type $entityType)
360
378
private function canShowAttribute (AbstractAttribute $ customerAttribute )
361
379
{
362
380
$ isRegistration = is_null ($ this ->context ->getRequestParam ($ this ->getRequestFieldName ()));
381
+ $ userDefined = (bool ) $ customerAttribute ->getIsUserDefined ();
363
382
364
- return is_array ($ customerAttribute ->getUsedInForms ()) &&
383
+ if (!$ userDefined ) {
384
+ return $ customerAttribute ->getIsVisible ();
385
+ }
386
+
387
+ $ canShowOnForm = is_array ($ customerAttribute ->getUsedInForms ()) &&
365
388
(
366
389
(in_array ('customer_account_create ' , $ customerAttribute ->getUsedInForms ()) && $ isRegistration ) ||
367
390
(in_array ('customer_account_edit ' , $ customerAttribute ->getUsedInForms ()) && !$ isRegistration )
368
391
);
392
+
393
+ return ($ this ->userScope === self ::ADMIN_SCOPE && $ canShowOnForm ) ||
394
+ ($ this ->userScope === self ::FRONTEND_SCOPE && $ canShowOnForm && $ customerAttribute ->getIsVisible ());
369
395
}
370
396
371
397
/**
0 commit comments