Пример #1
0
 /**
  * @return array
  */
 public function getTypes()
 {
     $types = $this->typeConfig->getTypes($this->relationInstance->getEntityCode());
     $options = [];
     foreach ($types as $key => $settings) {
         $options[$key] = __($settings['label']);
     }
     return $options;
 }
Пример #2
0
 /**
  * create attribute type instance
  *
  * @param Relation $relation
  * @return TypeInterface
  * @throws \Exception
  */
 public function create(Relation $relation)
 {
     $type = $relation->getType();
     $typeConfig = $this->typeConfig->getConfig('entity/' . $relation->getEntityCode() . '/type/' . $type);
     if (!isset($typeConfig['model'])) {
         throw new \Exception('Relation type "' . $type . '" does not exist');
     }
     /** @var \Umc\Base\Model\Core\Relation\Type\TypeInterface $typeInstance */
     $typeInstance = $this->objectManager->create($typeConfig['model']);
     if (false == $typeInstance instanceof TypeInterface) {
         throw new \Exception('Relation type instance is not instance on \\Umc\\Base\\Model\\Core\\Relation\\Type\\TypeInterface');
     }
     $typeInstance->setRelation($relation);
     return $typeInstance;
 }
Пример #3
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;
 }