Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 public function testGetDateAttributeCodes()
 {
     $this->assertEquals('[]', $this->entity->getDateAttributeCodes());
     $attribute = $this->setupAttribute();
     $attribute->setType('date');
     $this->entity->addAttribute($attribute);
     $this->assertEquals("['name']", $this->entity->getDateAttributeCodes());
     $attribute = $this->setupAttribute();
     $attribute->setCode('some_date');
     $attribute->setType('date');
     $attribute->setIsName(false);
     $this->entity->addAttribute($attribute);
     $this->assertEquals("['name', 'some_date']", $this->entity->getDateAttributeCodes());
     $attribute = $this->setupAttribute();
     $attribute->setCode('something');
     $attribute->setIsName(false);
     $this->entity->addAttribute($attribute);
     $this->assertEquals("['name', 'some_date']", $this->entity->getDateAttributeCodes());
 }
Example #5
0
 /**
  * add entity
  *
  * @param Entity $entity
  * @return $this
  */
 public function addEntity(Entity $entity)
 {
     $this->entityFlags = [];
     $entity->setData('sort_order', (count($this->entities) + 1) * 10);
     $entity->setModule($this);
     $this->entities[] = $entity;
     return $this;
 }
Example #6
0
 /**
  * get entity dependencies as json
  *
  * @return string
  */
 public function getEntityDepends()
 {
     return $this->formConfig->getDepends($this->entity->getEntityCode());
 }