1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\CMSDarkTheme\Control; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
6
|
|
|
use SilverStripe\Control\HTTPRequest; |
7
|
|
|
use SilverStripe\Control\HTTPResponse; |
8
|
|
|
use Sunnysideup\CMSDarkTheme\Api\LeftAndMainDarkThemeApi; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class \Sunnysideup\CMSDarkTheme\Control\LeftAndMainDarkThemeToggle |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class LeftAndMainDarkThemeToggle extends Controller |
15
|
|
|
{ |
16
|
|
|
private static $url_segment = 'admin/displaymode'; |
17
|
|
|
|
18
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID'; |
19
|
|
|
|
20
|
|
|
// private static $ignore_menuitem = false; |
21
|
|
|
|
22
|
|
|
private static $allowed_actions = [ |
23
|
|
|
'switch', |
24
|
|
|
'setlightmode', |
25
|
|
|
'setdarkmode', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* set mode and then. |
30
|
|
|
* |
31
|
|
|
* @param HTTPRequest $request |
32
|
|
|
* |
33
|
|
|
* @return HTTPResponse |
34
|
|
|
*/ |
35
|
|
|
public function index($request) |
36
|
|
|
{ |
37
|
|
|
return $this->switch($request); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* set mode and then. |
42
|
|
|
* |
43
|
|
|
* @param HTTPRequest $request |
44
|
|
|
* |
45
|
|
|
* @return HTTPResponse |
46
|
|
|
*/ |
47
|
|
|
public function switch($request) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$owner = $this->getOwner(); |
|
|
|
|
50
|
|
|
if (LeftAndMainDarkThemeApi::is_dark_mode()) { |
51
|
|
|
LeftAndMainDarkThemeApi::set_display_mode('Light'); |
52
|
|
|
} else { |
53
|
|
|
LeftAndMainDarkThemeApi::set_display_mode('Dark'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $owner->redirect('/admin/myprofile#Root_Cms'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setlightmode($request): HTTPResponse |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$owner = $this->getOwner(); |
62
|
|
|
LeftAndMainDarkThemeApi::set_display_mode('Light'); |
63
|
|
|
|
64
|
|
|
return $owner->redirect('admin/myprofile#Root_Cms'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setdarkmode($request): HTTPResponse |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$owner = $this->getOwner(); |
70
|
|
|
LeftAndMainDarkThemeApi::set_display_mode('Dark'); |
71
|
|
|
|
72
|
|
|
return $owner->redirect('admin/myprofile#Root_Cms'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.