/** * Customize the attribute form * * @param Form $form * @param AbstractAttribute $attribute */ protected function customizeForm(Form $form, AbstractAttribute $attribute) { $attTypeClass = $this->attTypeFactory->get($attribute->getAttributeType()); $fields = $attTypeClass->buildAttributeFormTypes($this->factory, $attribute); foreach ($fields as $field) { $form->add($field); } }
/** * Create an attribute * * @param string $type * * @return \Pim\Bundle\CatalogBundle\Model\AbstractAttribute */ public function createAttribute($type = null) { $class = $this->getAttributeClass(); $attribute = new $class(); $attribute->setEntityType($this->productClass); if ($type) { $attributeType = $this->factory->get($type); $attribute->setBackendType($attributeType->getBackendType()); $attribute->setAttributeType($attributeType->getName()); } return $attribute; }
/** * @param ProductValueInterface $value * @param array $context * * @return FormInterface */ public function buildProductValueForm(ProductValueInterface $value, array $context) { $attributeTypeAlias = $value->getAttribute()->getAttributeType(); $attributeType = $this->attributeTypeFactory->get($attributeTypeAlias); $name = $attributeType->prepareValueFormName($value); $type = $attributeType->prepareValueFormAlias($value); $data = $attributeType->prepareValueFormData($value); $options = array_merge($attributeType->prepareValueFormConstraints($value), $attributeType->prepareValueFormOptions($value)); $event = new CreateProductValueFormEvent($value, $type, $data, $options, $context); $this->eventDispatcher->dispatch(ProductEvents::CREATE_VALUE_FORM, $event); $valueForm = $this->formFactory->createNamed($name, $event->getFormType(), $event->getFormData(), $event->getFormOptions()); return $valueForm; }