Skip to content

Commit 9ca29a0

Browse files
author
Sergii Kovalenko
committed
MAGETWO-69521: Customer attribute with "Show on Storefront" set to No does not appear in backend
1 parent 0e36511 commit 9ca29a0

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

app/code/Magento/Customer/Model/Customer/DataProvider.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
4141
*/
4242
const MAX_FILE_SIZE = 2097152;
4343

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+
4454
/**
4555
* @var Collection
4656
*/
@@ -127,6 +137,14 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
127137
*/
128138
private $context;
129139

140+
/**
141+
* Enum: can be frontend or admin
142+
* Shows what user is used dataProvider
143+
*
144+
* @var string
145+
*/
146+
private $userScope;
147+
130148
/**
131149
* @param string $name
132150
* @param string $primaryFieldName
@@ -151,7 +169,8 @@ public function __construct(
151169
FileProcessorFactory $fileProcessorFactory = null,
152170
ContextInterface $context = null,
153171
array $meta = [],
154-
array $data = []
172+
array $data = [],
173+
$userScope = self::ADMIN_SCOPE
155174
) {
156175
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
157176
$this->eavValidationRules = $eavValidationRules;
@@ -161,6 +180,7 @@ public function __construct(
161180
$this->filterPool = $filterPool;
162181
$this->fileProcessorFactory = $fileProcessorFactory ?: $this->getFileProcessorFactory();
163182
$this->context = $context ?: ObjectManager::getInstance()->get(ContextInterface::class);
183+
$this->userScope = $userScope;
164184
$this->meta['customer']['children'] = $this->getAttributesMeta(
165185
$this->eavConfig->getEntityType('customer')
166186
);
@@ -339,10 +359,8 @@ protected function getAttributesMeta(Type $entityType)
339359
}
340360

341361
$meta[$code]['arguments']['data']['config']['componentType'] = Field::NAME;
362+
$meta[$code]['arguments']['data']['config']['visible'] = $this->canShowAttribute($attribute);
342363

343-
if ($this->canShowAttribute($attribute)) {
344-
$meta[$code]['arguments']['data']['config']['visible'] = true;
345-
}
346364

347365
$this->overrideFileUploaderMetadata($entityType, $attribute, $meta[$code]['arguments']['data']['config']);
348366
}
@@ -360,12 +378,20 @@ protected function getAttributesMeta(Type $entityType)
360378
private function canShowAttribute(AbstractAttribute $customerAttribute)
361379
{
362380
$isRegistration = is_null($this->context->getRequestParam($this->getRequestFieldName()));
381+
$userDefined = (bool) $customerAttribute->getIsUserDefined();
363382

364-
return is_array($customerAttribute->getUsedInForms()) &&
383+
if (!$userDefined) {
384+
return $customerAttribute->getIsVisible();
385+
}
386+
387+
$canShowOnForm = is_array($customerAttribute->getUsedInForms()) &&
365388
(
366389
(in_array('customer_account_create', $customerAttribute->getUsedInForms()) && $isRegistration) ||
367390
(in_array('customer_account_edit', $customerAttribute->getUsedInForms()) && !$isRegistration)
368391
);
392+
393+
return ($this->userScope === self::ADMIN_SCOPE && $canShowOnForm) ||
394+
($this->userScope === self::FRONTEND_SCOPE && $canShowOnForm && $customerAttribute->getIsVisible());
369395
}
370396

371397
/**

0 commit comments

Comments
 (0)