/** * get type options as array to use in a select * * @param bool $withEmpty * @return array */ public function toOptionArray($withEmpty = false) { if (is_null($this->options)) { $types = $this->typeConfig->getTypes($this->entityModel->getEntityCode()); $this->options = []; foreach ($types as $type) { $this->options[] = ['value' => $type['id'], 'label' => $type['label']]; } } $options = $this->options; if ($withEmpty) { array_unshift($options, ['value' => '', 'label' => __('Select Entity Type')]); } return $options; }
/** * create type instance * * @param Entity $entity * @return TypeInterface * @throws \Exception */ public function create(Entity $entity) { $type = $entity->getType(); $typeConfig = $this->typeConfig->getConfig('entity/' . $entity->getEntityCode() . '/type/' . $type); if (!isset($typeConfig['model'])) { throw new \Exception('Entity type "' . $type . '" does not exist'); } /** @var TypeInterface $typeInstance */ $typeInstance = $this->objectManager->create($typeConfig['model']); if (false == $typeInstance instanceof TypeInterface) { throw new \Exception('Entity type instance is not instance on \\Umc\\Base\\Model\\Core\\Entity\\Type\\TypeInterface'); } $typeInstance->setEntity($entity); return $typeInstance; }
/** * 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 entity dependencies as json * * @return string */ public function getEntityDepends() { return $this->formConfig->getDepends($this->entity->getEntityCode()); }