Ejemplo n.º 1
0
 /**
  * Handle the form.
  */
 public function handle()
 {
     $form = $this->builder->getForm();
     $model = $this->builder->getModel();
     /**
      * If the model is already instantiated
      * then use it as is.
      */
     if (is_object($model)) {
         $form->setModel($model);
         return;
     }
     /**
      * If no model is set, try guessing the
      * model based on best practices.
      */
     if ($model === null) {
         $parts = explode('\\', str_replace('FormBuilder', 'Model', get_class($this->builder)));
         unset($parts[count($parts) - 2]);
         $model = implode('\\', $parts);
         $this->builder->setModel($model);
     }
     /**
      * If the model does not exist or
      * is disabled then skip it.
      */
     if (!$model || !class_exists($model)) {
         $this->builder->setModel(null);
         return;
     }
     /**
      * Set the model on the form!
      */
     $form->setModel(app($model));
 }
Ejemplo n.º 2
0
 /**
  * Handle the command.
  *
  * @param Container $container
  */
 public function handle(Container $container)
 {
     /*
      * Set the default options handler based
      * on the builder class. Defaulting to
      * no handler.
      */
     if (!$this->builder->getRepository()) {
         $model = $this->builder->getFormModel();
         $entry = $this->builder->getEntry();
         $form = $this->builder->getForm();
         $repository = str_replace('FormBuilder', 'FormRepository', get_class($this->builder));
         if (!$this->builder->getRepository() && class_exists($repository)) {
             $this->builder->setRepository($container->make($repository, compact('form', 'model')));
         } elseif (!$this->builder->getRepository() && $model instanceof EntryModel) {
             $this->builder->setRepository($container->make(EntryFormRepository::class, compact('form', 'model')));
         } elseif (!$this->builder->getRepository() && $model instanceof EloquentModel) {
             $this->builder->setRepository($container->make(EloquentFormRepository::class, compact('form', 'model')));
         } elseif (!$this->builder->getRepository() && $entry instanceof EntryModel) {
             $this->builder->setRepository($container->make(EntryFormRepository::class, ['form' => $form, 'model' => $entry]));
         } elseif (!$this->builder->getRepository() && $entry instanceof EloquentModel) {
             $this->builder->setRepository($container->make(EloquentFormRepository::class, ['form' => $form, 'model' => $entry]));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Handle the event.
  */
 public function handle()
 {
     $form = $this->builder->getForm();
     /* @var FieldType $field */
     foreach ($form->getEnabledFields() as $field) {
         $form->setValue($field->getInputName(), $field->getInputValue());
     }
 }
 /**
  * Handle the command.
  *
  * @param MessageBag $messages
  */
 public function handle(MessageBag $messages)
 {
     $form = $this->builder->getForm();
     $errors = $form->getErrors();
     if ($errors instanceof \Illuminate\Support\MessageBag) {
         $messages->error($errors->all());
     }
 }
Ejemplo n.º 5
0
 /**
  * Handle the command.
  */
 public function handle()
 {
     $form = $this->builder->getForm();
     $options = $form->getOptions();
     $data = $form->getData();
     $content = view($options->get('form_view'), $data->all());
     $form->setContent($content);
     $form->addData('content', $content);
 }
 /**
  * Handle the command.
  */
 public function handle()
 {
     if (!$this->builder->canSave()) {
         return;
     }
     $form = $this->builder->getForm();
     foreach ($this->builder->getSkips() as $fieldSlug) {
         $form->removeField($fieldSlug);
     }
 }
Ejemplo n.º 7
0
 public function handle()
 {
     $form = $this->builder->getForm();
     $model = $this->builder->getModel();
     if (is_string($model) && !class_exists($model)) {
         return;
     }
     if (is_string($model)) {
         $model = app($model);
     }
     if ($model instanceof EntryInterface) {
         $form->setStream($model->getStream());
     }
 }
 /**
  * Save the form.
  *
  * @param FormBuilder $builder
  * @return bool|mixed
  */
 public function save(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $namespace = $form->getEntry() . '::';
     /* @var FieldType $field */
     foreach ($form->getFields() as $field) {
         $this->preferences->set($namespace . $field->getField(), $form->getValue($field->getInputName()));
     }
 }
Ejemplo n.º 9
0
 /**
  * Build the actions.
  *
  * @param FormBuilder $builder
  */
 public function build(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $this->input->read($builder);
     foreach ($builder->getActions() as $action) {
         if (array_get($action, 'enabled', true)) {
             $form->addAction($this->factory->make($action));
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Handle the command.
  *
  * @param Container            $container
  * @param ViewTemplate         $template
  * @param BreadcrumbCollection $breadcrumbs
  */
 public function handle(Container $container, ViewTemplate $template, BreadcrumbCollection $breadcrumbs)
 {
     $form = $this->builder->getForm();
     if ($handler = $form->getOption('data')) {
         $container->call($handler, compact('form'));
     }
     if ($layout = $form->getOption('layout_view')) {
         $template->put('layout', $layout);
     }
     if ($title = $form->getOption('title')) {
         $template->put('title', $title);
     }
     // Move this to options so we can read it.
     $this->builder->setFormOption('read_only', $this->builder->isReadOnly());
     $form->addData('form', $form);
     if ($breadcrumb = $form->getOption('breadcrumb', 'streams::form.mode.' . $this->builder->getFormMode())) {
         $breadcrumbs->put($breadcrumb, '#');
     }
 }
 /**
  * Normalize action input.
  *
  * @param FormBuilder $builder
  */
 public function normalize(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $actions = $builder->getActions();
     $prefix = $form->getOption('prefix');
     foreach ($actions as $slug => &$action) {
         $action = $this->process($prefix, $slug, $action);
     }
     $builder->setActions($actions);
 }
Ejemplo n.º 12
0
 /**
  * Save the form.
  *
  * @param FormBuilder $builder
  * @return bool|mixed
  */
 public function save(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $namespace = $form->getEntry() . '::';
     /* @var FieldType $field */
     foreach ($form->getFields() as $field) {
         $key = $namespace . $field->getField();
         $value = $form->getValue($field->getInputName());
         $this->settings->set($key, $value);
     }
 }
 /**
  * Process fields that handle themselves.
  *
  * @param FormBuilder $builder
  */
 protected function processSelfHandlingFields(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $entry = $form->getEntry();
     $fields = $form->getFields();
     $fields = $fields->selfHandling();
     /* @var FieldType $field */
     foreach ($fields as $field) {
         app()->call([$field->setEntry($entry), 'handle'], compact('builder'));
     }
 }