Ejemplo n.º 1
0
 public function testAddField()
 {
     $config = ['name' => 'store_type', 'no_span' => true, 'value' => 'value'];
     $this->factoryElementMock->expects($this->once())->method('create')->with('hidden', ['data' => $config])->will($this->returnValue($this->elementMock));
     $this->elementMock->expects($this->once())->method('setId')->with('store_type');
     $this->factoryCollectionMock->expects($this->once())->method('create')->will($this->returnValue($this->allElementsMock));
     $this->allElementsMock->expects($this->once())->method('add')->with($this->elementMock, false);
     $this->assertEquals($this->elementMock, $this->abstractForm->addField('store_type', 'hidden', $config));
     $this->abstractForm->removeField('hidden');
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }