1
|
|
|
<?php namespace Anomaly\Streams\Platform\Ui\Form\Command; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Component\Action\Command\BuildActions; |
4
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Component\Action\Command\SetActiveAction; |
5
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Component\Button\Command\BuildButtons; |
6
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Component\Field\Command\BuildFields; |
7
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Component\Section\Command\BuildSections; |
8
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Event\FormWasBuilt; |
9
|
|
|
use Anomaly\Streams\Platform\Ui\Form\FormBuilder; |
10
|
|
|
use Illuminate\Contracts\Bus\SelfHandling; |
11
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
12
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class BuildForm |
16
|
|
|
* |
17
|
|
|
* @link http://anomaly.is/streams-platform |
18
|
|
|
* @author AnomalyLabs, Inc. <[email protected]> |
19
|
|
|
* @author Ryan Thompson <[email protected]> |
20
|
|
|
* @package Anomaly\Streams\Platform\Ui\Form\Command |
21
|
|
|
*/ |
22
|
|
|
class BuildForm implements SelfHandling |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
use DispatchesJobs; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The form builder. |
29
|
|
|
* |
30
|
|
|
* @var FormBuilder |
31
|
|
|
*/ |
32
|
|
|
protected $builder; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create a new BuildFormColumnsCommand instance. |
36
|
|
|
* |
37
|
|
|
* @param FormBuilder $builder |
38
|
|
|
*/ |
39
|
|
|
public function __construct(FormBuilder $builder) |
40
|
|
|
{ |
41
|
|
|
$this->builder = $builder; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Handle the command. |
46
|
|
|
* |
47
|
|
|
* @param Dispatcher $events |
48
|
|
|
*/ |
49
|
|
|
public function handle(Dispatcher $events) |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Setup some objects and options using |
54
|
|
|
* provided input or sensible defaults. |
55
|
|
|
*/ |
56
|
|
|
$this->dispatch(new SetFormModel($this->builder)); |
57
|
|
|
$this->dispatch(new SetFormStream($this->builder)); |
58
|
|
|
$this->dispatch(new SetRepository($this->builder)); |
59
|
|
|
$this->dispatch(new SetFormEntry($this->builder)); |
60
|
|
|
$this->dispatch(new SetDefaultParameters($this->builder)); |
61
|
|
|
$this->dispatch(new SetFormOptions($this->builder)); |
62
|
|
|
$this->dispatch(new SetDefaultOptions($this->builder)); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Load anything we need that might be flashed. |
66
|
|
|
*/ |
67
|
|
|
$this->dispatch(new LoadFormErrors($this->builder)); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Before we go any further, authorize the request. |
71
|
|
|
*/ |
72
|
|
|
$this->dispatch(new AuthorizeForm($this->builder)); |
73
|
|
|
|
74
|
|
|
/* |
75
|
|
|
* Build form fields. |
76
|
|
|
*/ |
77
|
|
|
$this->dispatch(new BuildFields($this->builder)); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Build form sections. |
81
|
|
|
*/ |
82
|
|
|
$this->dispatch(new BuildSections($this->builder)); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Build form actions and flag active. |
86
|
|
|
*/ |
87
|
|
|
$this->dispatch(new BuildActions($this->builder)); |
88
|
|
|
$this->dispatch(new SetActiveAction($this->builder)); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Build form buttons. |
92
|
|
|
*/ |
93
|
|
|
$this->dispatch(new BuildButtons($this->builder)); |
94
|
|
|
|
95
|
|
|
$events->fire(new FormWasBuilt($this->builder)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|