public function preSet(FormEvent $event)
 {
     $form = $event->getForm();
     $rootName = $form->getRoot()->getName();
     if (!$form->isRoot() && ($parent = $form->getParent())) {
         $name = $this->getDottedName($form);
         $fullName = $this->getFullName($rootName, $name);
         // Add input from the previous submit
         if ($form->getName() !== '_token' && $this->session->hasOldInput($fullName)) {
             // Get old value
             $value = $this->session->getOldInput($fullName);
             // Transform back to good data
             $value = $this->transformValue($event, $value);
             // Store on the form
             $event->setData($value);
         }
         if ($this->session->has('errors')) {
             /** @var \Illuminate\Support\ViewErrorBag $errors */
             $errors = $this->session->get('errors');
             if ($errors->has($name)) {
                 $form->addError(new FormError(implode(' ', $errors->get($name))));
             }
         }
     }
 }
Example #2
0
 /**
  * Shows the form for item editing.
  *
  * @param string $model Model to use.
  * @param int $id Item ID.
  * @return \Illuminate\Http\Response
  */
 public function edit($model, $id)
 {
     $this->setModel($model);
     $this->checkAction('edit');
     $item = $this->staticModelgetFormItem($id);
     if (!$item) {
         abort(404);
     }
     $title = trans('lavanda::common.edit_title', ['entity' => mb_strtolower($this->staticModelGetName()), 'id' => $id]);
     $form = $this->staticModelGetForm('put', $this->getRoute('update', ['id' => $id]), $this->session->hasOldInput() ? null : $item);
     if (!$this->session->has('back_url')) {
         $this->session->flash('back_url', $this->request->server('HTTP_REFERER'));
     } else {
         $this->session->reflash();
     }
     return view('lavanda::entity.edit', ['title' => $title, 'form' => $form]);
 }