2011-04-16 07:54:52 +02:00
|
|
|
<?php
|
2012-02-11 01:58:30 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
2016-08-25 11:30:53 +02:00
|
|
|
use SilverStripe\Admin\AddToCampaignHandler;
|
2016-09-09 01:26:24 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Control\HTTPResponse;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
2016-08-25 11:30:53 +02:00
|
|
|
|
2012-02-11 01:58:30 +01:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
*/
|
2011-04-16 07:54:52 +02:00
|
|
|
class CMSPageEditController extends CMSMain {
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_segment = 'pages/edit';
|
2016-08-10 06:08:39 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID';
|
2016-08-10 06:08:39 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_priority = 41;
|
2016-08-10 06:08:39 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
|
2012-08-28 00:28:58 +02:00
|
|
|
|
2016-08-25 11:30:53 +02:00
|
|
|
private static $allowed_actions = array(
|
|
|
|
'AddToCampaignForm',
|
|
|
|
);
|
|
|
|
|
|
|
|
public function getClientConfig()
|
|
|
|
{
|
|
|
|
return array_merge( parent::getClientConfig(), [
|
|
|
|
'form' => [
|
|
|
|
'AddToCampaignForm' => [
|
|
|
|
'schemaUrl' => $this->Link('schema/AddToCampaignForm')
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action handler for adding pages to a campaign
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param Form $form
|
2016-09-09 01:26:24 +02:00
|
|
|
* @return DBHTMLText|HTTPResponse
|
2016-08-25 11:30:53 +02:00
|
|
|
*/
|
|
|
|
public function addtocampaign($data, $form)
|
|
|
|
{
|
|
|
|
$id = $data['ID'];
|
|
|
|
$record = \Page::get()->byID($id);
|
|
|
|
|
|
|
|
$handler = AddToCampaignHandler::create($this, $record);
|
|
|
|
$results = $handler->addToCampaign($record, $data['Campaign']);
|
2016-08-23 04:36:06 +02:00
|
|
|
if (is_null($results)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if($request->getHeader('X-Formschema-Request')) {
|
|
|
|
$data = $this->getSchemaForForm($handler->Form($record));
|
|
|
|
$data['message'] = $results;
|
2016-08-25 11:30:53 +02:00
|
|
|
|
2016-09-09 01:26:24 +02:00
|
|
|
$response = new HTTPResponse(Convert::raw2json($data));
|
2016-08-23 04:36:06 +02:00
|
|
|
$response->addHeader('Content-Type', 'application/json');
|
|
|
|
return $response;
|
2016-08-25 11:30:53 +02:00
|
|
|
}
|
2016-08-23 04:36:06 +02:00
|
|
|
return $results;
|
2016-08-25 11:30:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Url handler for add to campaign form
|
|
|
|
*
|
2016-09-09 01:26:24 +02:00
|
|
|
* @param HTTPRequest $request
|
2016-08-25 11:30:53 +02:00
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function AddToCampaignForm($request)
|
|
|
|
{
|
|
|
|
// Get ID either from posted back value, or url parameter
|
|
|
|
$id = $request->param('ID') ?: $request->postVar('ID');
|
|
|
|
return $this->getAddToCampaignForm($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function getAddToCampaignForm($id)
|
|
|
|
{
|
|
|
|
// Get record-specific fields
|
|
|
|
$record = \Page::get()->byID($id);
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
$this->httpError(404, _t(
|
|
|
|
'AssetAdmin.ErrorNotFound',
|
|
|
|
'That {Type} couldn\'t be found',
|
|
|
|
'',
|
|
|
|
['Type' => _t('SiteTree.SINGULARNAME')]
|
|
|
|
));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!$record->canView()) {
|
|
|
|
$this->httpError(403, _t(
|
|
|
|
'AssetAdmin.ErrorItemPermissionDenied',
|
|
|
|
'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign',
|
|
|
|
'',
|
|
|
|
['ObjectTitle' => _t('SiteTree.SINGULARNAME')]
|
|
|
|
));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$handler = AddToCampaignHandler::create($this, $record);
|
|
|
|
return $handler->Form($record);
|
|
|
|
}
|
|
|
|
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|