Skip to content

Commit 0a64fbd

Browse files
committed
MAGETWO-93522: Custom customer attributes don't show in admin unless they're configured to show on frontend
1 parent b636eb5 commit 0a64fbd

File tree

3 files changed

+7
-43
lines changed

3 files changed

+7
-43
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* Dataprovider of customer addresses for customer address grid.
22+
*
2223
* @property \Magento\Customer\Model\ResourceModel\Address\Collection $collection
2324
*/
2425
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
@@ -222,8 +223,7 @@ private function getAttributesMeta(Type $entityType): array
222223
$meta[$attribute->getAttributeCode()] = $this->attributeMetadataResolver->getAttributesMeta(
223224
$attribute,
224225
$entityType,
225-
$this->allowToShowHiddenAttributes,
226-
$this->getRequestFieldName()
226+
$this->allowToShowHiddenAttributes
227227
);
228228
}
229229
$this->attributeMetadataResolver->processWebsiteMeta($meta);

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

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,13 @@ public function __construct(
101101
* @param AbstractAttribute $attribute
102102
* @param Type $entityType
103103
* @param bool $allowToShowHiddenAttributes
104-
* @param string $requestFieldName
105104
* @return array
106105
* @throws \Magento\Framework\Exception\LocalizedException
107106
*/
108107
public function getAttributesMeta(
109108
AbstractAttribute $attribute,
110109
Type $entityType,
111-
bool $allowToShowHiddenAttributes,
112-
string $requestFieldName
110+
bool $allowToShowHiddenAttributes
113111
): array {
114112
$meta = $this->modifyBooleanAttributeMeta($attribute);
115113
// use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
@@ -138,7 +136,6 @@ public function getAttributesMeta(
138136
$meta['arguments']['data']['config']['componentType'] = Field::NAME;
139137
$meta['arguments']['data']['config']['visible'] = $this->canShowAttribute(
140138
$attribute,
141-
$requestFieldName,
142139
$allowToShowHiddenAttributes
143140
);
144141

@@ -155,48 +152,16 @@ public function getAttributesMeta(
155152
* Detect can we show attribute on specific form or not
156153
*
157154
* @param AbstractAttribute $customerAttribute
158-
* @param string $requestFieldName
159155
* @param bool $allowToShowHiddenAttributes
160156
* @return bool
161157
*/
162158
private function canShowAttribute(
163159
AbstractAttribute $customerAttribute,
164-
string $requestFieldName,
165160
bool $allowToShowHiddenAttributes
166161
) {
167-
$userDefined = (bool)$customerAttribute->getIsUserDefined();
168-
if (!$userDefined) {
169-
return $customerAttribute->getIsVisible();
170-
}
171-
172-
$canShowOnForm = $this->canShowAttributeInForm($customerAttribute, $requestFieldName);
173-
174-
return ($allowToShowHiddenAttributes && $canShowOnForm) ||
175-
(!$allowToShowHiddenAttributes && $canShowOnForm && $customerAttribute->getIsVisible());
176-
}
177-
178-
/**
179-
* Check whether the specific attribute can be shown in form: customer registration, customer edit, etc...
180-
*
181-
* @param AbstractAttribute $customerAttribute
182-
* @param string $requestFieldName
183-
* @return bool
184-
*/
185-
private function canShowAttributeInForm(AbstractAttribute $customerAttribute, string $requestFieldName): bool
186-
{
187-
$isRegistration = $this->context->getRequestParam($requestFieldName) === null;
188-
189-
if ($customerAttribute->getEntityType()->getEntityTypeCode() === 'customer') {
190-
return \is_array($customerAttribute->getUsedInForms()) &&
191-
(
192-
(\in_array('customer_account_create', $customerAttribute->getUsedInForms(), true)
193-
&& $isRegistration) ||
194-
(\in_array('customer_account_edit', $customerAttribute->getUsedInForms(), true)
195-
&& !$isRegistration)
196-
);
197-
}
198-
return \is_array($customerAttribute->getUsedInForms()) &&
199-
\in_array('customer_address_edit', $customerAttribute->getUsedInForms(), true);
162+
return $allowToShowHiddenAttributes && (bool) $customerAttribute->getIsUserDefined()
163+
? true
164+
: (bool) $customerAttribute->getIsVisible();
200165
}
201166

202167
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ private function getAttributesMeta(Type $entityType): array
189189
$meta[$attribute->getAttributeCode()] = $this->attributeMetadataResolver->getAttributesMeta(
190190
$attribute,
191191
$entityType,
192-
$this->allowToShowHiddenAttributes,
193-
$this->getRequestFieldName()
192+
$this->allowToShowHiddenAttributes
194193
);
195194
}
196195
$this->attributeMetadataResolver->processWebsiteMeta($meta);

0 commit comments

Comments
 (0)