/**
  * Create and configure an attribute
  *
  * @param string|null $type
  *
  * @return AttributeInterface
  */
 public function createAttribute($type = null)
 {
     $attribute = $this->create();
     if (null !== $type && '' !== $type) {
         $attributeType = $this->registry->get($type);
         $attribute->setBackendType($attributeType->getBackendType());
         $attribute->setAttributeType($attributeType->getName());
         $attribute->setUnique($attributeType->isUnique());
     }
     return $attribute;
 }
 /**
  * Customize the attribute form
  *
  * @param FormInterface      $form
  * @param AttributeInterface $attribute
  */
 protected function customizeForm(FormInterface $form, AttributeInterface $attribute)
 {
     $attributeTypeClass = $this->attributeTypeRegistry->get($attribute->getAttributeType());
     $fields = $attributeTypeClass->buildAttributeFormTypes($this->factory, $attribute);
     foreach ($fields as $field) {
         $form->add($field);
     }
 }
 /**
  * @param AttributeInterface $attribute
  * @param string|null        $data
  */
 protected function setType($attribute, $data)
 {
     if ('' === $data || null === $data) {
         throw new \InvalidArgumentException('attributeType must be filled.');
     }
     try {
         $attributeType = $this->registry->get($data);
         $attribute->setAttributeType($attributeType->getName());
         $attribute->setBackendType($attributeType->getBackendType());
         $attribute->setUnique($attributeType->isUnique());
     } catch (\LogicException $exception) {
         throw new \InvalidArgumentException(sprintf('AttributeType "%s" does not exist.', $data));
     }
 }