Example #1
0
 public function __construct(Prototyped $subject)
 {
     $this->subject = $subject;
     $form = $this->subject->proto()->makeForm()->add(Primitive::choice('action')->setList($this->commandMap)->setDefault($this->defaultAction));
     if ($this->idFieldName) {
         $form->add(Primitive::alias($this->idFieldName, $form->get('id')));
     }
     $this->map = MappedForm::create($form)->addSource('id', RequestType::get())->addSource('action', RequestType::get())->setDefaultType(RequestType::post());
     if ($this->idFieldName) {
         $this->map->addSource($this->idFieldName, RequestType::get());
     }
 }
 public function chooseAction(HttpRequest $request)
 {
     $action = Primitive::choice('action')->setList($this->methodMap);
     if ($this->getDefaultAction()) {
         $action->setDefault($this->getDefaultAction());
     }
     Form::create()->add($action)->import($request->getGet())->importMore($request->getPost())->importMore($request->getAttached());
     if (!($command = $action->getValue())) {
         return $action->getDefault();
     }
     return $command;
 }