|
1
|
|
|
<?php namespace Anomaly\Streams\Platform\Http\Controller; |
|
2
|
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Addon\FieldType\FieldType; |
|
4
|
|
|
use Anomaly\Streams\Platform\Addon\FieldType\FieldTypeCollection; |
|
5
|
|
|
use Anomaly\Streams\Platform\Addon\Module\ModuleCollection; |
|
6
|
|
|
use Anomaly\Streams\Platform\Field\Form\FieldFormBuilder; |
|
7
|
|
|
use Anomaly\Streams\Platform\Field\Table\FieldTableBuilder; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class FieldsController |
|
11
|
|
|
* |
|
12
|
|
|
* @link http://pyrocms.com/ |
|
13
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
|
14
|
|
|
* @author Ryan Thompson <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class FieldsController extends AdminController |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The stream namespace. |
|
21
|
|
|
* |
|
22
|
|
|
* @var null|string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $namespace = null; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Return an index of existing fields. |
|
28
|
|
|
* |
|
29
|
|
|
* @param FieldTableBuilder $table |
|
30
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
31
|
|
|
*/ |
|
32
|
|
|
public function index(FieldTableBuilder $table) |
|
33
|
|
|
{ |
|
34
|
|
|
return $table |
|
35
|
|
|
->setNamespace($this->getNamespace()) |
|
36
|
|
|
->render(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Choose a field type for creating a field. |
|
41
|
|
|
* |
|
42
|
|
|
* @param FieldTypeCollection $fieldTypes |
|
43
|
|
|
* @return \Illuminate\View\View |
|
44
|
|
|
*/ |
|
45
|
|
|
public function choose(FieldTypeCollection $fieldTypes, ModuleCollection $modules) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->view->make( |
|
48
|
|
|
'streams::fields/choose', |
|
49
|
|
|
[ |
|
50
|
|
|
'field_types' => $fieldTypes, |
|
51
|
|
|
'module' => $modules->active(), |
|
52
|
|
|
] |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Create a new field. |
|
58
|
|
|
* |
|
59
|
|
|
* @param FieldFormBuilder $form |
|
60
|
|
|
* @param FieldTypeCollection $fieldTypes |
|
61
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function create(FieldFormBuilder $form, FieldTypeCollection $fieldTypes) |
|
64
|
|
|
{ |
|
65
|
|
|
return $form |
|
66
|
|
|
->setNamespace($this->getNamespace()) |
|
67
|
|
|
->setFieldType($fieldTypes->get($this->request->get('field_type'))) |
|
68
|
|
|
->render(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Edit an existing field. |
|
73
|
|
|
* |
|
74
|
|
|
* @param FieldFormBuilder $form |
|
75
|
|
|
* @param FieldTypeCollection $fieldTypes |
|
76
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
77
|
|
|
*/ |
|
78
|
|
|
public function edit(FieldFormBuilder $form, FieldTypeCollection $fieldTypes) |
|
79
|
|
|
{ |
|
80
|
|
|
return $form |
|
81
|
|
|
->setNamespace($this->getNamespace()) |
|
82
|
|
|
->setFieldType($fieldTypes->get($this->request->get('field_type'))) |
|
83
|
|
|
->render($this->route->parameter('id')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Choose a field type for changing an existing field. |
|
88
|
|
|
* |
|
89
|
|
|
* @param FieldTypeCollection $fieldTypes |
|
90
|
|
|
* @return \Illuminate\View\View |
|
91
|
|
|
*/ |
|
92
|
|
|
public function change(FieldTypeCollection $fieldTypes, ModuleCollection $modules) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->view->make( |
|
95
|
|
|
'streams::fields/change', |
|
96
|
|
|
[ |
|
97
|
|
|
'field_types' => $fieldTypes->filter( |
|
98
|
|
|
function (FieldType $fieldType) { |
|
99
|
|
|
return $fieldType->getColumnType() !== false; |
|
100
|
|
|
} |
|
101
|
|
|
), |
|
102
|
|
|
'module' => $modules->active(), |
|
103
|
|
|
] |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Get the namespace. |
|
109
|
|
|
* |
|
110
|
|
|
* @return null|string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getNamespace() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->namespace; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|