public function testAttributeEmptyDataModelClass() { $this->_attributeMetadata->expects($this->once())->method('getDataModel')->will($this->returnValue('')); $this->_attributeMetadata->expects($this->once())->method('getFrontendInput')->will($this->returnValue('text')); $dataModel = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form\\Text', [], [], '', false); $params = ['entityTypeCode' => $this->_entityTypeCode, 'value' => 'Some Text', 'isAjax' => false, 'attribute' => $this->_attributeMetadata]; $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Customer\\Model\\Metadata\\Form\\Text', $params)->will($this->returnValue($dataModel)); $actual = $this->_elementFactory->create($this->_attributeMetadata, 'Some Text', $this->_entityTypeCode); $this->assertSame($dataModel, $actual); }
/** * {@inheritdoc} * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function renderArray($addressAttributes, $format = null) { switch ($this->getType()->getCode()) { case 'html': $dataFormat = ElementFactory::OUTPUT_FORMAT_HTML; break; case 'pdf': $dataFormat = ElementFactory::OUTPUT_FORMAT_PDF; break; case 'oneline': $dataFormat = ElementFactory::OUTPUT_FORMAT_ONELINE; break; default: $dataFormat = ElementFactory::OUTPUT_FORMAT_TEXT; break; } $attributesMetadata = $this->_addressMetadataService->getAllAttributesMetadata(); $data = []; foreach ($attributesMetadata as $attributeMetadata) { if (!$attributeMetadata->isVisible()) { continue; } $attributeCode = $attributeMetadata->getAttributeCode(); if ($attributeCode == 'country_id' && isset($addressAttributes['country_id'])) { $data['country'] = $this->_countryFactory->create()->loadByCode($addressAttributes['country_id'])->getName(); } elseif ($attributeCode == 'region' && isset($addressAttributes['region'])) { $data['region'] = __($addressAttributes['region']); } elseif (isset($addressAttributes[$attributeCode])) { $value = $addressAttributes[$attributeCode]; $dataModel = $this->_elementFactory->create($attributeMetadata, $value, 'customer_address'); $value = $dataModel->outputValue($dataFormat); if ($attributeMetadata->getFrontendInput() == 'multiline') { $values = $dataModel->outputValue(ElementFactory::OUTPUT_FORMAT_ARRAY); // explode lines foreach ($values as $k => $v) { $key = sprintf('%s%d', $attributeCode, $k + 1); $data[$key] = $v; } } $data[$attributeCode] = $value; } } if ($this->getType()->getEscapeHtml()) { foreach ($data as $key => $value) { $data[$key] = $this->escapeHtml($value); } } $format = $format !== null ? $format : $this->getFormatArray($addressAttributes); return $this->filterManager->template($format, ['variables' => $data]); }
/** * Return array of additional account data * Value is option style array * * @return array */ public function getCustomerAccountData() { $accountData = array(); $entityType = 'customer'; foreach ($this->_customerMetadataService->getAllAttributesMetadata($entityType) as $attribute) { /* @var $attribute \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata */ if (!$attribute->isVisible() || $attribute->isSystem()) { continue; } $orderKey = sprintf('customer_%s', $attribute->getAttributeCode()); $orderValue = $this->getOrder()->getData($orderKey); if ($orderValue != '') { $metadataElement = $this->_metadataElementFactory->create($attribute, $orderValue, $entityType); $value = $metadataElement->outputValue(AttributeDataFactory::OUTPUT_FORMAT_HTML); $sortOrder = $attribute->getSortOrder() + $attribute->isUserDefined() ? 200 : 0; $sortOrder = $this->_prepareAccountDataSortOrder($accountData, $sortOrder); $accountData[$sortOrder] = array('label' => $attribute->getFrontendLabel(), 'value' => $this->escapeHtml($value, array('br'))); } } ksort($accountData, SORT_NUMERIC); return $accountData; }
/** * Return attribute data model by attribute * * @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute * @return \Magento\Eav\Model\Attribute\Data\AbstractData */ protected function _getAttributeDataModel($attribute) { $dataModel = $this->_elementFactory->create($attribute, isset($this->_attributeValues[$attribute->getAttributeCode()]) ? $this->_attributeValues[$attribute->getAttributeCode()] : null, $this->_entityType, $this->_isAjax); return $dataModel; }