/** * create attribute type instance * * @param Attribute $attribute * @return TypeInterface * @throws \Exception */ public function create(Attribute $attribute) { $type = $attribute->getType(); $typeConfig = $this->typeConfig->getConfig('entity/' . $attribute->getEntityCode() . '/type/' . $type); if (!isset($typeConfig['model'])) { throw new \Exception('Attribute type "' . $type . '" does not exist'); } /** @var \Umc\Base\Model\Core\Attribute\Type\TypeInterface $typeInstance */ $typeInstance = $this->objectManager->create($typeConfig['model']); if (false == $typeInstance instanceof TypeInterface) { throw new \Exception('Attribute type instance is not instance on \\Umc\\Base\\Model\\Core\\Attribute\\Type\\TypeInterface'); } $typeInstance->setAttribute($attribute); return $typeInstance; }
/** * add attribute * * @param Attribute $attribute * @return $this */ public function addAttribute(Attribute $attribute) { $attribute->setEntity($this); $this->attributes[] = $attribute; return $this; }
/** * get form fields * * @return array */ public function getFields() { $entities = [$this->moduleInstance->getEntityCode() => __('MODULE'), $this->settingsInstance->getEntityCode() => __('SETTINGS'), $this->entityInstance->getEntityCode() => __('ENTITY'), $this->attributeInstance->getEntityCode() => __('ATTRIBUTE')]; $data = []; foreach ($entities as $entityCode => $entityLabel) { $data[] = ['__colspan' => $entityLabel]; $config = $this->formConfig->getConfig('form/' . $entityCode, true, []); foreach ($config['fieldset'] as $fieldset) { $data[] = ['__colspan' => $fieldset['label']]; foreach ($fieldset['field'] as $field) { if ($field['type'] != 'hidden') { $data[] = ['field' => $field['label'], 'type' => $field['type'], 'description' => isset($field['tooltip']) ? $field['tooltip'] : '']; } } } } return $data; }
/** * get attribute dependencies as json * * @return string */ public function getAttributeDepends() { return $this->formConfig->getDepends($this->attribute->getEntityCode()); }