Exemplo n.º 1
0
 /**
  * Create Form Element
  *
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata $attribute
  * @param string|int|bool $value
  * @param string $entityTypeCode
  * @param bool $isAjax
  * @return \Magento\Customer\Model\Metadata\Form\AbstractData
  */
 public function create(\Magento\Customer\Service\V1\Data\Eav\AttributeMetadata $attribute, $value, $entityTypeCode, $isAjax = false)
 {
     $dataModelClass = $attribute->getDataModel();
     $params = array('entityTypeCode' => $entityTypeCode, 'value' => is_null($value) ? false : $value, 'isAjax' => $isAjax, 'attribute' => $attribute);
     /** TODO fix when Validation is implemented MAGETWO-17341 */
     if ($dataModelClass == 'Magento\\Customer\\Model\\Attribute\\Data\\Postcode') {
         $dataModelClass = 'Magento\\Customer\\Model\\Metadata\\Form\\Text';
     }
     if (!empty($dataModelClass)) {
         $dataModel = $this->_objectManager->create($dataModelClass, $params);
     } else {
         $dataModelClass = sprintf('Magento\\Customer\\Model\\Metadata\\Form\\%s', $this->_string->upperCaseWords($attribute->getFrontendInput()));
         $dataModel = $this->_objectManager->create($dataModelClass, $params);
     }
     return $dataModel;
 }
Exemplo n.º 2
0
 public function testConstructorAndGetters()
 {
     $options = array(array('value' => 'OPTION_ONE'), array('value' => 'OPTION_TWO'));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     /** @var \Magento\Customer\Service\V1\Data\Eav\OptionBuilder $optionBuilder */
     $optionBuilder = $objectManager->getObject('Magento\\Customer\\Service\\V1\\Data\\Eav\\OptionBuilder');
     $validationRuleBuilder = $objectManager->getObject('Magento\\Customer\\Service\\V1\\Data\\Eav\\ValidationRuleBuilder');
     $attributeMetadataBuilder = $objectManager->getObject('\\Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadataBuilder', ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder])->populateWithArray(array('attribute_code' => self::ATTRIBUTE_CODE, 'frontend_input' => self::FRONTEND_INPUT, 'input_filter' => self::INPUT_FILTER, 'store_label' => self::STORE_LABEL, 'validation_rules' => array(), 'options' => $options));
     $attributeMetadata = new AttributeMetadata($attributeMetadataBuilder);
     $this->assertSame(self::ATTRIBUTE_CODE, $attributeMetadata->getAttributeCode());
     $this->assertSame(self::FRONTEND_INPUT, $attributeMetadata->getFrontendInput());
     $this->assertSame(self::INPUT_FILTER, $attributeMetadata->getInputFilter());
     $this->assertSame(self::STORE_LABEL, $attributeMetadata->getStoreLabel());
     $this->assertSame(array(), $attributeMetadata->getValidationRules());
     $this->assertSame($options[0], $attributeMetadata->getOptions()[0]->__toArray());
     $this->assertSame($options[1], $attributeMetadata->getOptions()[1]->__toArray());
 }
Exemplo n.º 3
0
 /**
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata $attribute
  * @return array
  */
 protected function _getAttributeOptionsArray(\Magento\Customer\Service\V1\Data\Eav\AttributeMetadata $attribute)
 {
     $options = $attribute->getOptions();
     $result = array();
     foreach ($options as $option) {
         $result[] = $option->__toArray();
     }
     return $result;
 }