public function createControlByIdentifier($id)
 {
     $r = $this->entityManager->getRepository('\\Concrete\\Core\\Entity\\Attribute\\Key\\Key');
     $key = $r->findOneBy(array('akID' => $id));
     $control = new AttributeKeyControl();
     $control->setAttributeKey($key);
     return $control;
 }
Example #2
0
 public function action_add_control()
 {
     $entityManager = \Core::make('database/orm')->entityManager();
     $post = $this->request->request->all();
     $session = \Core::make('session');
     $controls = $session->get('block.express_form.new');
     if (!is_array($controls)) {
         $controls = array();
     }
     $field = explode('|', $this->request->request->get('type'));
     switch ($field[0]) {
         case 'attribute_key':
             $type = Type::getByID($field[1]);
             if (is_object($type)) {
                 $control = new AttributeKeyControl();
                 $control->setId((new UuidGenerator())->generate($entityManager, $control));
                 $key = new ExpressKey();
                 $key->setAttributeKeyName($post['question']);
                 if ($post['required']) {
                     $control->setIsRequired(true);
                 }
                 $key->setAttributeType($type);
                 if (!$post['question']) {
                     $e = \Core::make('error');
                     $e->add(t('You must give this question a name.'));
                     return new JsonResponse($e);
                 }
                 $controller = $type->getController();
                 $key = $this->saveAttributeKeySettings($controller, $key, $post);
                 $control->setAttributeKey($key);
             }
             break;
         case 'entity_property':
             /**
              * @var $propertyType EntityPropertyType
              */
             $propertyType = $this->app->make(EntityPropertyType::class);
             $control = $propertyType->createControlByIdentifier($field[1]);
             $control->setId((new UuidGenerator())->generate($entityManager, $control));
             $saver = $control->getControlSaveHandler();
             $control = $saver->saveFromRequest($control, $this->request);
             break;
     }
     if (!isset($control)) {
         $e = \Core::make('error');
         $e->add(t('You must choose a valid field type.'));
         return new JsonResponse($e);
     } else {
         $controls[$control->getId()] = $control;
         $session->set('block.express_form.new', $controls);
         return new JsonResponse($control);
     }
 }