1 | <?php |
||
24 | abstract class FormAbstract implements FormInterface |
||
25 | { |
||
26 | use LoggedUser; |
||
27 | |||
28 | /** |
||
29 | * An instance of Model. |
||
30 | * |
||
31 | * @var Model |
||
32 | */ |
||
33 | protected $model; |
||
34 | |||
35 | /** |
||
36 | * Set an instance of model currently being edited. |
||
37 | * |
||
38 | * @param Model $model |
||
39 | * |
||
40 | * @return void|FormInterface |
||
41 | */ |
||
42 | 13 | public function editingModel(Model $model) |
|
43 | { |
||
44 | 13 | $this->model = $model; |
|
45 | |||
46 | 13 | return $this; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Setup the object from the route parameters. |
||
51 | * |
||
52 | * @param array $params |
||
53 | * |
||
54 | * @return FormInterface |
||
55 | */ |
||
56 | public function setup(array $params) |
||
57 | { |
||
58 | 26 | $model = array_first($params, function ($key, $value) { |
|
59 | 4 | return $value instanceof Model; |
|
60 | 26 | }); |
|
61 | 26 | if ($model) { |
|
62 | 4 | $this->editingModel($model); |
|
63 | } |
||
64 | |||
65 | 26 | return $this; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Whether or not the form is in editing of a model. |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | 32 | public function isEditing() |
|
77 | |||
78 | /** |
||
79 | * Return an instance of the model being edited. |
||
80 | * |
||
81 | * @return Model |
||
82 | */ |
||
83 | 50 | public function getModel() |
|
84 | { |
||
85 | 50 | return $this->model; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Returns form type. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 41 | public function openType() |
|
97 | |||
98 | /** |
||
99 | * Returns an array of form actions. |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | 14 | public function actions() |
|
107 | |||
108 | /** |
||
109 | * Returns an array of form fields. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | public function fields() |
||
117 | |||
118 | /** |
||
119 | * Returns an array form rules. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | 31 | public function rules() |
|
127 | |||
128 | /** |
||
129 | * Returns the form redirect url on error. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getRedirectUrl() |
||
137 | |||
138 | /** |
||
139 | * Returns project upload fields. |
||
140 | * |
||
141 | * @param string $name |
||
142 | * @param ProjectModel $project |
||
143 | * @param UserModel $user |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | 13 | protected function projectUploadFields($name, ProjectModel $project, UserModel $user) |
|
162 | } |
||
163 |