Пример #1
0
 public function testAddColumn()
 {
     $config = ['name' => 'store_type', 'no_span' => true, 'value' => 'value'];
     $this->factoryElementMock->expects($this->once())->method('create')->with('column', ['data' => $config])->will($this->returnValue($this->elementMock));
     $this->elementMock->expects($this->once())->method('setId')->with('hidden');
     $this->elementMock->expects($this->exactly(2))->method('setForm')->will($this->returnSelf());
     $this->factoryCollectionMock->expects($this->once())->method('create')->will($this->returnValue($this->allElementsMock));
     $this->allElementsMock->expects($this->once())->method('add')->with($this->elementMock, false);
     $this->abstractForm->addColumn('hidden', $config);
 }
Пример #2
0
 /**
  * Add element to collection
  *
  * @todo get it straight with $after
  * @param AbstractElement $element
  * @param bool|string $after
  * @return AbstractElement
  */
 public function add(AbstractElement $element, $after = false)
 {
     // Set the Form for the node
     if ($this->_container->getForm() instanceof Form) {
         $element->setContainer($this->_container);
         $element->setForm($this->_container->getForm());
     }
     if ($after === false) {
         $this->_elements[] = $element;
     } elseif ($after === '^') {
         array_unshift($this->_elements, $element);
     } elseif (is_string($after)) {
         $newOrderElements = array();
         foreach ($this->_elements as $index => $currElement) {
             if ($currElement->getId() == $after) {
                 $newOrderElements[] = $currElement;
                 $newOrderElements[] = $element;
                 $this->_elements = array_merge($newOrderElements, array_slice($this->_elements, $index + 1));
                 return $element;
             }
             $newOrderElements[] = $currElement;
         }
         $this->_elements[] = $element;
     }
     return $element;
 }
Пример #3
0
 /**
  * @param array $keys
  * @param array $data
  * @param array $customAttributes
  * @param string $result
  * @dataProvider dataProviderSerialize
  */
 public function testSerialize($keys, $data, $customAttributes, $result)
 {
     foreach ($data as $key => $value) {
         $this->abstractForm->setData($key, $value);
     }
     foreach ($customAttributes as $key => $value) {
         $this->abstractForm->addCustomAttribute($key, $value);
     }
     $this->assertEquals($result, $this->abstractForm->serialize($keys));
 }
Пример #4
0
 /**
  * Serialize the element.
  *
  * @param string[] $attributes
  * @param string $valueSeparator
  * @param string $fieldSeparator
  * @param string $quote
  * @return string
  */
 public function serialize($attributes = array(), $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"')
 {
     if ($this->isLocked() && !empty($attributes)) {
         $attributes[] = $this->lockHtmlAttribute;
     }
     if (in_array('disabled', $attributes) && !empty($this->_data['disabled'])) {
         $this->_data['disabled'] = 'disabled';
     } else {
         unset($this->_data['disabled']);
     }
     if (in_array('checked', $attributes) && !empty($this->_data['checked'])) {
         $this->_data['checked'] = 'checked';
     } else {
         unset($this->_data['checked']);
     }
     return parent::serialize($attributes, $valueSeparator, $fieldSeparator, $quote);
 }
Пример #5
0
 /**
  * Initialize config field group
  *
  * @param \Magento\Backend\Model\Config\Structure\Element\Group $group
  * @param \Magento\Backend\Model\Config\Structure\Element\Section $section
  * @param \Magento\Framework\Data\Form\AbstractForm $form
  * @return void
  */
 protected function _initGroup(\Magento\Backend\Model\Config\Structure\Element\Group $group, \Magento\Backend\Model\Config\Structure\Element\Section $section, \Magento\Framework\Data\Form\AbstractForm $form)
 {
     $frontendModelClass = $group->getFrontendModel();
     $fieldsetRenderer = $frontendModelClass ? $this->_layout->getBlockSingleton($frontendModelClass) : $this->_fieldsetRenderer;
     $fieldsetRenderer->setForm($this);
     $fieldsetRenderer->setConfigData($this->_configData);
     $fieldsetRenderer->setGroup($group);
     $fieldsetConfig = ['legend' => $group->getLabel(), 'comment' => $group->getComment(), 'expanded' => $group->isExpanded(), 'group' => $group->getData()];
     $fieldset = $form->addFieldset($this->_generateElementId($group->getPath()), $fieldsetConfig);
     $fieldset->setRenderer($fieldsetRenderer);
     $group->populateFieldset($fieldset);
     $this->_addElementTypes($fieldset);
     $dependencies = $group->getDependencies($this->getStoreCode());
     $elementName = $this->_generateElementName($group->getPath());
     $elementId = $this->_generateElementId($group->getPath());
     $this->_populateDependenciesBlock($dependencies, $elementId, $elementName);
     if ($group->shouldCloneFields()) {
         $cloneModel = $group->getCloneModel();
         foreach ($cloneModel->getPrefixes() as $prefix) {
             $this->initFields($fieldset, $group, $section, $prefix['field'], $prefix['label']);
         }
     } else {
         $this->initFields($fieldset, $group, $section);
     }
     $this->_fieldsets[$group->getId()] = $fieldset;
 }
Пример #6
0
 /**
  * Add form element
  *
  * @param AbstractElement $element
  * @param bool $after
  * @return $this
  */
 public function addElement(AbstractElement $element, $after = false)
 {
     $this->checkElementId($element->getId());
     parent::addElement($element, $after);
     $this->addElementToCollection($element);
     return $this;
 }
Пример #7
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;
 }
Пример #8
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;
 }
Пример #9
0
 /**
  * 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);
     }
 }