mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1587 from open-sausages/pulls/4.0/add-to-campaign
Fixes for add to campaign in pages admin
This commit is contained in:
commit
fdcc3f9b83
@ -22,7 +22,6 @@ use SilverStripe\Admin\AdminRootController;
|
|||||||
use SilverStripe\Admin\LeftAndMain;
|
use SilverStripe\Admin\LeftAndMain;
|
||||||
use SilverStripe\Admin\CMSBatchActionHandler;
|
use SilverStripe\Admin\CMSBatchActionHandler;
|
||||||
use SilverStripe\Admin\CMSPreviewable;
|
use SilverStripe\Admin\CMSPreviewable;
|
||||||
use SilverStripe\Admin\AddToCampaignHandler;
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\CMS\Model\RedirectorPage;
|
use SilverStripe\CMS\Model\RedirectorPage;
|
||||||
use SilverStripe\CMS\Model\CurrentPageIdentifier;
|
use SilverStripe\CMS\Model\CurrentPageIdentifier;
|
||||||
@ -1309,18 +1308,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
return $this->getResponseNegotiator()->respond($this->getRequest());
|
return $this->getResponseNegotiator()->respond($this->getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Action handler for adding pages to a campaign
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param Form $form
|
|
||||||
* @return DBHTMLText|SS_HTTPResponse
|
|
||||||
*/
|
|
||||||
public function addtocampaign($data, $form) {
|
|
||||||
$handler = AddToCampaignHandler::create($form, $data);
|
|
||||||
return $handler->handle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Batch Actions Handler
|
* Batch Actions Handler
|
||||||
*/
|
*/
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Controllers;
|
namespace SilverStripe\CMS\Controllers;
|
||||||
|
|
||||||
|
use Convert;
|
||||||
|
use SilverStripe\Admin\AddToCampaignHandler;
|
||||||
|
use SS_HTTPResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package cms
|
* @package cms
|
||||||
*/
|
*/
|
||||||
@ -15,4 +19,92 @@ class CMSPageEditController extends CMSMain {
|
|||||||
|
|
||||||
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
|
private static $required_permission_codes = 'CMS_ACCESS_CMSMain';
|
||||||
|
|
||||||
|
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
|
||||||
|
* @return DBHTMLText|SS_HTTPResponse
|
||||||
|
*/
|
||||||
|
public function addtocampaign($data, $form)
|
||||||
|
{
|
||||||
|
$id = $data['ID'];
|
||||||
|
$record = \Page::get()->byID($id);
|
||||||
|
|
||||||
|
$handler = AddToCampaignHandler::create($this, $record);
|
||||||
|
$results = $handler->addToCampaign($record, $data['Campaign']);
|
||||||
|
if (!is_null($results)) {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
if($request->getHeader('X-Formschema-Request')) {
|
||||||
|
$data = $this->getSchemaForForm($handler->Form($record));
|
||||||
|
$data['message'] = $results;
|
||||||
|
|
||||||
|
$response = new SS_HTTPResponse(Convert::raw2json($data));
|
||||||
|
$response->addHeader('Content-Type', 'application/json');
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Url handler for add to campaign form
|
||||||
|
*
|
||||||
|
* @param SS_HTTPRequest $request
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@ class ErrorPageControllerExtension extends Extension {
|
|||||||
* @throws SS_HTTPResponse_Exception
|
* @throws SS_HTTPResponse_Exception
|
||||||
*/
|
*/
|
||||||
public function onBeforeHTTPError($statusCode, $request) {
|
public function onBeforeHTTPError($statusCode, $request) {
|
||||||
|
if (\Director::is_ajax()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$response = ErrorPage::response_for($statusCode);
|
$response = ErrorPage::response_for($statusCode);
|
||||||
if($response) {
|
if($response) {
|
||||||
throw new SS_HTTPResponse_Exception($response, $statusCode);
|
throw new SS_HTTPResponse_Exception($response, $statusCode);
|
||||||
|
Loading…
Reference in New Issue
Block a user