1
|
|
|
<?php namespace Anomaly\ConfigurationModule\Configuration\Form; |
2
|
|
|
|
3
|
|
|
use Anomaly\ConfigurationModule\Configuration\Contract\ConfigurationRepositoryInterface; |
4
|
|
|
use Anomaly\Streams\Platform\Addon\FieldType\FieldType; |
5
|
|
|
use Anomaly\Streams\Platform\Ui\Form\Contract\FormRepositoryInterface; |
6
|
|
|
use Anomaly\Streams\Platform\Ui\Form\FormBuilder; |
7
|
|
|
use Illuminate\Config\Repository; |
8
|
|
|
use Illuminate\Container\Container; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ConfigurationFormRepositoryInterface |
12
|
|
|
* |
13
|
|
|
* @link http://pyrocms.com/ |
14
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
15
|
|
|
* @author Ryan Thompson <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class ConfigurationFormRepository implements FormRepositoryInterface |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The config repository. |
22
|
|
|
* |
23
|
|
|
* @var Repository |
24
|
|
|
*/ |
25
|
|
|
protected $config; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The application container. |
29
|
|
|
* |
30
|
|
|
* @var Container |
31
|
|
|
*/ |
32
|
|
|
protected $container; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The configurations repository. |
36
|
|
|
* |
37
|
|
|
* @var ConfigurationRepositoryInterface |
38
|
|
|
*/ |
39
|
|
|
protected $configurations; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a new ConfigurationFormRepositoryInterface instance. |
43
|
|
|
* |
44
|
|
|
* @param Repository $config |
45
|
|
|
* @param Container $container |
46
|
|
|
* @param ConfigurationRepositoryInterface $configurations |
47
|
|
|
*/ |
48
|
|
|
public function __construct( |
49
|
|
|
Repository $config, |
50
|
|
|
Container $container, |
51
|
|
|
ConfigurationRepositoryInterface $configurations |
52
|
|
|
) { |
53
|
|
|
$this->config = $config; |
54
|
|
|
$this->configurations = $configurations; |
55
|
|
|
$this->container = $container; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Find an entry or return a new one. |
60
|
|
|
* |
61
|
|
|
* @param $id |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function findOrNew($id) |
65
|
|
|
{ |
66
|
|
|
return $id; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Save the form. |
71
|
|
|
* |
72
|
|
|
* @param FormBuilder|ConfigurationFormBuilder $builder |
73
|
|
|
* @return bool|mixed |
74
|
|
|
*/ |
75
|
|
|
public function save(FormBuilder $builder) |
76
|
|
|
{ |
77
|
|
|
$namespace = $builder->getFormEntry() . '::'; |
78
|
|
|
|
79
|
|
|
/* @var FieldType $field */ |
80
|
|
|
foreach ($builder->getFormFields() as $field) { |
81
|
|
|
|
82
|
|
|
$scope = $builder->getScope(); |
83
|
|
|
$key = $namespace . $field->getField(); |
84
|
|
|
$value = $builder->getFormValue($field->getInputName()); |
85
|
|
|
|
86
|
|
|
$this->configurations->set($key, $scope, $value); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|