1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\Settings; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Thinktomorrow\Chief\Fields\Fields; |
7
|
|
|
use Thinktomorrow\Chief\Fields\FieldManager; |
8
|
|
|
use Thinktomorrow\Chief\Fields\RenderingFields; |
9
|
|
|
use Thinktomorrow\Chief\Fields\Types\Field; |
10
|
|
|
use Thinktomorrow\Chief\Fields\Types\InputField; |
11
|
|
|
use Thinktomorrow\Chief\Fields\Types\SelectField; |
12
|
|
|
use Thinktomorrow\Chief\Settings\Application\ChangeHomepage; |
13
|
|
|
use Thinktomorrow\Chief\Urls\UrlHelper; |
14
|
|
|
use Thinktomorrow\Chief\Urls\UrlRecord; |
15
|
|
|
|
16
|
|
|
class SettingFieldsManager extends Fields implements FieldManager |
17
|
|
|
{ |
18
|
|
|
use RenderingFields; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** @var Settings */ |
21
|
|
|
private $settings; |
22
|
|
|
|
23
|
6 |
|
public function __construct(Settings $settings) |
24
|
|
|
{ |
25
|
6 |
|
$this->settings = $settings; |
26
|
6 |
|
} |
27
|
|
|
|
28
|
6 |
|
public function fields(): Fields |
29
|
|
|
{ |
30
|
6 |
|
return new Fields([ |
31
|
6 |
|
SelectField::make('homepage') |
32
|
6 |
|
->name('homepage[:locale]') |
33
|
6 |
|
->options(UrlHelper::allOnlineSingles()) |
34
|
6 |
|
->translatable(config('translatable.locales')) |
35
|
6 |
|
->validation('required') |
36
|
6 |
|
->grouped() |
37
|
6 |
|
->label('Homepagina') |
|
|
|
|
38
|
6 |
|
->description('Geef hier de homepagina voor de site op.'), |
|
|
|
|
39
|
6 |
|
InputField::make('app_name') |
40
|
6 |
|
->label('Site naam') |
|
|
|
|
41
|
6 |
|
->description('Naam van de applicatie. Dit wordt getoond in o.a. de mail communicatie.'), |
|
|
|
|
42
|
6 |
|
InputField::make('contact_email') |
43
|
6 |
|
->validation('email') |
44
|
6 |
|
->label('Webmaster email') |
45
|
6 |
|
->description('Het emailadres van de webmaster. Hierop ontvang je standaard alle contactnames.'), |
46
|
6 |
|
InputField::make('contact_name') |
47
|
6 |
|
->label('Webmaster naam') |
48
|
6 |
|
->description('Voor en achternaam van de webmaster.'), |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function fieldValue(Field $field, $locale = null) |
53
|
|
|
{ |
54
|
|
|
return $this->settings->get($field->key(), $locale); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
5 |
|
public function saveFields(Request $request) |
58
|
|
|
{ |
59
|
5 |
|
$existingHomepageValue = []; |
60
|
|
|
|
61
|
5 |
|
foreach ($this->fields() as $key => $field) { |
62
|
5 |
|
if (!$setting = Setting::where('key', $key)->first()) { |
63
|
5 |
|
Setting::create([ |
64
|
5 |
|
'key' => $key, |
65
|
5 |
|
'value' => $request->get($key, ''), |
66
|
|
|
]); |
67
|
|
|
|
68
|
5 |
|
continue; |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
if ($key === Setting::HOMEPAGE) { |
72
|
1 |
|
$existingHomepageValue = $setting->value; |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
$setting->update(['value' => $request->get($key, '')]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// A changed homepage needs to be reflected in the urls as well in order to respond to incoming requests. |
79
|
5 |
|
if ($request->filled(Setting::HOMEPAGE)) { |
80
|
5 |
|
app(ChangeHomepage::class)->onSettingChanged($existingHomepageValue); |
|
|
|
|
81
|
|
|
} |
82
|
5 |
|
} |
83
|
|
|
} |
84
|
|
|
|