1
|
|
|
<?php namespace Anomaly\PreferencesModule\Preference\Form; |
2
|
|
|
|
3
|
|
|
use Anomaly\PreferencesModule\Preference\Contract\PreferenceRepositoryInterface; |
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 PreferenceFormRepositoryInterface |
12
|
|
|
* |
13
|
|
|
* @link http://pyrocms.com/ |
14
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
15
|
|
|
* @author Ryan Thompson <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class PreferenceFormRepository 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 preferences repository. |
36
|
|
|
* |
37
|
|
|
* @var PreferenceRepositoryInterface |
38
|
|
|
*/ |
39
|
|
|
protected $preferences; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a new PreferenceFormRepositoryInterface instance. |
43
|
|
|
* |
44
|
|
|
* @param Repository $config |
45
|
|
|
* @param Container $container |
46
|
|
|
* @param PreferenceRepositoryInterface $preferences |
47
|
|
|
*/ |
48
|
|
|
public function __construct(Repository $config, Container $container, PreferenceRepositoryInterface $preferences) |
49
|
|
|
{ |
50
|
|
|
$this->config = $config; |
51
|
|
|
$this->preferences = $preferences; |
52
|
|
|
$this->container = $container; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Find an entry or return a new one. |
57
|
|
|
* |
58
|
|
|
* @param $id |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function findOrNew($id) |
62
|
|
|
{ |
63
|
|
|
return $id; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Save the form. |
68
|
|
|
* |
69
|
|
|
* @param FormBuilder $builder |
70
|
|
|
* @return bool|mixed |
71
|
|
|
*/ |
72
|
|
|
public function save(FormBuilder $builder) |
73
|
|
|
{ |
74
|
|
|
$form = $builder->getForm(); |
75
|
|
|
|
76
|
|
|
$namespace = $form->getEntry() . '::'; |
77
|
|
|
|
78
|
|
|
/* @var FieldType $field */ |
79
|
|
|
foreach ($form->getFields() as $field) { |
80
|
|
|
|
81
|
|
|
$key = $namespace . $field->getField(); |
82
|
|
|
$value = $form->getValue($field->getInputName()); |
83
|
|
|
|
84
|
|
|
$this->preferences->set($key, $value); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|