1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CMS\Controllers; |
4
|
|
|
|
5
|
|
|
use Convert; |
6
|
|
|
use SilverStripe\Admin\AddToCampaignHandler; |
7
|
|
|
use SS_HTTPResponse; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @package cms |
11
|
|
|
*/ |
12
|
|
|
class CMSPageEditController extends CMSMain { |
|
|
|
|
13
|
|
|
|
14
|
|
|
private static $url_segment = 'pages/edit'; |
|
|
|
|
15
|
|
|
|
16
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
private static $url_priority = 41; |
|
|
|
|
19
|
|
|
|
20
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; |
|
|
|
|
21
|
|
|
|
22
|
|
|
private static $allowed_actions = array( |
|
|
|
|
23
|
|
|
'AddToCampaignForm', |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
public function getClientConfig() |
27
|
|
|
{ |
28
|
|
|
return array_merge( parent::getClientConfig(), [ |
29
|
|
|
'form' => [ |
30
|
|
|
'AddToCampaignForm' => [ |
31
|
|
|
'schemaUrl' => $this->Link('schema/AddToCampaignForm') |
32
|
|
|
], |
33
|
|
|
], |
34
|
|
|
]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Action handler for adding pages to a campaign |
39
|
|
|
* |
40
|
|
|
* @param array $data |
41
|
|
|
* @param Form $form |
42
|
|
|
* @return DBHTMLText|SS_HTTPResponse |
43
|
|
|
*/ |
44
|
|
|
public function addtocampaign($data, $form) |
45
|
|
|
{ |
46
|
|
|
$id = $data['ID']; |
47
|
|
|
$record = \Page::get()->byID($id); |
48
|
|
|
|
49
|
|
|
$handler = AddToCampaignHandler::create($this, $record); |
50
|
|
|
$results = $handler->addToCampaign($record, $data['Campaign']); |
51
|
|
|
if (!is_null($results)) { |
52
|
|
|
$request = $this->getRequest(); |
53
|
|
|
if($request->getHeader('X-Formschema-Request')) { |
54
|
|
|
$data = $this->getSchemaForForm($handler->Form($record)); |
55
|
|
|
$data['message'] = $results; |
56
|
|
|
|
57
|
|
|
$response = new SS_HTTPResponse(Convert::raw2json($data)); |
58
|
|
|
$response->addHeader('Content-Type', 'application/json'); |
59
|
|
|
return $response; |
60
|
|
|
} |
61
|
|
|
return $results; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Url handler for add to campaign form |
67
|
|
|
* |
68
|
|
|
* @param SS_HTTPRequest $request |
69
|
|
|
* @return Form |
70
|
|
|
*/ |
71
|
|
|
public function AddToCampaignForm($request) |
72
|
|
|
{ |
73
|
|
|
// Get ID either from posted back value, or url parameter |
74
|
|
|
$id = $request->param('ID') ?: $request->postVar('ID'); |
75
|
|
|
return $this->getAddToCampaignForm($id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param int $id |
80
|
|
|
* @return Form |
81
|
|
|
*/ |
82
|
|
|
public function getAddToCampaignForm($id) |
83
|
|
|
{ |
84
|
|
|
// Get record-specific fields |
85
|
|
|
$record = \Page::get()->byID($id); |
86
|
|
|
|
87
|
|
|
if (!$record) { |
88
|
|
|
$this->httpError(404, _t( |
89
|
|
|
'AssetAdmin.ErrorNotFound', |
90
|
|
|
'That {Type} couldn\'t be found', |
91
|
|
|
'', |
92
|
|
|
['Type' => _t('SiteTree.SINGULARNAME')] |
|
|
|
|
93
|
|
|
)); |
94
|
|
|
return null; |
95
|
|
|
} |
96
|
|
|
if (!$record->canView()) { |
97
|
|
|
$this->httpError(403, _t( |
98
|
|
|
'AssetAdmin.ErrorItemPermissionDenied', |
99
|
|
|
'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign', |
100
|
|
|
'', |
101
|
|
|
['ObjectTitle' => _t('SiteTree.SINGULARNAME')] |
|
|
|
|
102
|
|
|
)); |
103
|
|
|
return null; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$handler = AddToCampaignHandler::create($this, $record); |
107
|
|
|
return $handler->Form($record); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|