/** * Add rendering EAV attributes to Form element * * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] $attributes * @param \Magento\Framework\Data\Form\AbstractForm $form * @return $this */ protected function _addAttributesToForm($attributes, \Magento\Framework\Data\Form\AbstractForm $form) { // add additional form types $types = $this->_getAdditionalFormElementTypes(); foreach ($types as $type => $className) { $form->addType($type, $className); } $renderers = $this->_getAdditionalFormElementRenderers(); foreach ($attributes as $attribute) { $inputType = $attribute->getFrontendInput(); if ($inputType) { $element = $form->addField($attribute->getAttributeCode(), $inputType, array('name' => $attribute->getAttributeCode(), 'label' => __($attribute->getStoreLabel()), 'class' => $attribute->getFrontendClass(), 'required' => $attribute->isRequired())); if ($inputType == 'multiline') { $element->setLineCount($attribute->getMultilineCount()); } $element->setEntityAttribute($attribute); $this->_addAdditionalFormElementData($element); if (!empty($renderers[$attribute->getAttributeCode()])) { $element->setRenderer($renderers[$attribute->getAttributeCode()]); } if ($inputType == 'select' || $inputType == 'multiselect') { $options = array(); foreach ($attribute->getOptions() as $optionData) { $options[] = \Magento\Framework\Service\SimpleDataObjectConverter::toFlatArray($optionData); } $element->setValues($options); } elseif ($inputType == 'date') { $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); $element->setImage($this->getViewFileUrl('images/grid-cal.gif')); $element->setDateFormat($format); } } } return $this; }
/** * Add rendering EAV attributes to Form element * * @param \Magento\Customer\Api\Data\AttributeMetadataInterface[] $attributes * @param \Magento\Framework\Data\Form\AbstractForm $form * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _addAttributesToForm($attributes, \Magento\Framework\Data\Form\AbstractForm $form) { // add additional form types $types = $this->_getAdditionalFormElementTypes(); foreach ($types as $type => $className) { $form->addType($type, $className); } $renderers = $this->_getAdditionalFormElementRenderers(); foreach ($attributes as $attribute) { $inputType = $attribute->getFrontendInput(); if ($inputType) { $element = $form->addField($attribute->getAttributeCode(), $inputType, ['name' => $attribute->getAttributeCode(), 'label' => __($attribute->getStoreLabel()), 'class' => $attribute->getFrontendClass(), 'required' => $attribute->isRequired()]); if ($inputType == 'multiline') { $element->setLineCount($attribute->getMultilineCount()); } $element->setEntityAttribute($attribute); $this->_addAdditionalFormElementData($element); if (!empty($renderers[$attribute->getAttributeCode()])) { $element->setRenderer($renderers[$attribute->getAttributeCode()]); } if ($inputType == 'select' || $inputType == 'multiselect') { $options = []; foreach ($attribute->getOptions() as $optionData) { $options[] = ConvertArray::toFlatArray($this->dataObjectProcessor->buildOutputDataArray($optionData, '\\Magento\\Customer\\Api\\Data\\OptionInterface')); } $element->setValues($options); } elseif ($inputType == 'date') { $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $element->setDateFormat($format); } } } return $this; }
/** * Add new element type * * @param \Magento\Framework\Data\Form\AbstractForm $baseElement * @return void */ protected function _addElementTypes(\Magento\Framework\Data\Form\AbstractForm $baseElement) { $types = $this->_getAdditionalElementTypes(); foreach ($types as $code => $className) { $baseElement->addType($code, $className); } }