Skip to content

Commit

Permalink
API Remove silverstripe/campaign-admin integration support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 20, 2024
1 parent 33e1556 commit a3600be
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 144 deletions.
21 changes: 1 addition & 20 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -1479,28 +1479,9 @@ protected function getArchiveWarningMessage($record)

// Get the IDs of all changeset including at least one of the pages.
$descendants[] = $record->ID;
$inChangeSetIDs = ChangeSetItem::get()->filter([
'ObjectID' => $descendants,
'ObjectClass' => SiteTree::class
])->column('ChangeSetID');

// Count number of affected change set
$affectedChangeSetCount = 0;
if (count($inChangeSetIDs ?? []) > 0) {
$affectedChangeSetCount = ChangeSet::get()
->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
->count();
}

$numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
$numCampaigns = mb_strtolower($numCampaigns ?? '');

if (count($descendants ?? []) > 0 && $affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
} elseif (count($descendants ?? []) > 0) {
if (count($descendants ?? []) > 0) {
$archiveWarningMsg = $defaultMessage;
} elseif ($affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
} else {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarning', 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?');
}
Expand Down
95 changes: 0 additions & 95 deletions code/Controllers/CMSPageEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@

namespace SilverStripe\CMS\Controllers;

use Page;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\ModalController;
use SilverStripe\CampaignAdmin\AddToCampaignHandler;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Forms\Form;
use SilverStripe\Core\ArrayLib;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Core\Validation\ValidationResult;

/**
* @package cms
*/
class CMSPageEditController extends CMSMain
{

private static $url_segment = 'pages/edit';

private static $url_rule = '/$Action/$ID/$OtherID';
Expand All @@ -31,18 +20,11 @@ class CMSPageEditController extends CMSMain

private static $ignore_menuitem = true;

private static $allowed_actions = [
'AddToCampaignForm',
];

public function getClientConfig(): array
{
$modalController = ModalController::singleton();
return ArrayLib::array_merge_recursive(parent::getClientConfig(), [
'form' => [
'AddToCampaignForm' => [
'schemaUrl' => $this->Link('schema/AddToCampaignForm'),
],
'editorInternalLink' => [
'schemaUrl' => $modalController->Link('schema/editorInternalLink'),
],
Expand All @@ -52,81 +34,4 @@ public function getClientConfig(): array
],
]);
}

/**
* Action handler for adding pages to a campaign
*/
public function addtocampaign(array $data, Form $form): HTTPResponse
{
$id = $data['ID'];
$record = \Page::get()->byID($id);

$handler = AddToCampaignHandler::create($this, $record);
$response = $handler->addToCampaign($record, $data);
$message = $response->getBody();
if (empty($message)) {
return $response;
}

if ($this->getSchemaRequested()) {
// Send extra "message" data with schema response
$extraData = ['message' => $message];
$schemaId = Controller::join_links($this->Link('schema/AddToCampaignForm'), $id);
return $this->getSchemaResponse($schemaId, $form, null, $extraData);
}

return $response;
}

/**
* Url handler for add to campaign form
*
* @param 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 = SiteTree::get()->byID($id);

if (!$record) {
$this->httpError(404, _t(
__CLASS__ . '.ErrorNotFound',
'That {Type} couldn\'t be found',
'',
['Type' => Page::singleton()->i18n_singular_name()]
));
return null;
}
if (!$record->canView()) {
$this->httpError(403, _t(
__CLASS__.'.ErrorItemPermissionDenied',
'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign',
'',
['ObjectTitle' => Page::singleton()->i18n_singular_name()]
));
return null;
}

$handler = AddToCampaignHandler::create($this, $record);
$form = $handler->Form($record);

$form->setValidationResponseCallback(function (ValidationResult $errors) use ($form, $id) {
$schemaId = Controller::join_links($this->Link('schema/AddToCampaignForm'), $id);
return $this->getSchemaResponse($schemaId, $form, $errors);
});

return $form;
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"require": {
"php": "^8.3",
"silverstripe/admin": "^3",
"silverstripe/campaign-admin": "^3",
"silverstripe/framework": "^6",
"silverstripe/reports": "^6",
"silverstripe/siteconfig": "^6",
Expand Down
28 changes: 0 additions & 28 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1885,10 +1885,6 @@ public function testGetCMSActions()
$actions->fieldByName('ActionMenus.MoreOptions.action_archive'),
'archive action present for a saved draft page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'addtocampaign action present for a saved draft page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
'no unpublish action present for a saved draft page'
Expand Down Expand Up @@ -1922,10 +1918,6 @@ public function testGetCMSActions()
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
'no unpublish action present for a published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'addtocampaign action present for a published page'
);
$this->assertNull(
$actions->fieldByName('MajorActions.action_restore'),
'no restore action present for a published page'
Expand Down Expand Up @@ -1953,10 +1945,6 @@ public function testGetCMSActions()
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
'rollback action present for a changed published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'addtocampaign action present for a changed published page'
);
$this->assertNull(
$actions->fieldByName('MajorActions.action_restore'),
'no restore action present for a changed published page'
Expand All @@ -1983,10 +1971,6 @@ public function testGetCMSActions()
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
'no rollback action present for a archived page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'no addtocampaign action present for a archived page'
);
$this->assertNotNull(
$actions->fieldByName('MajorActions.action_restore'),
'restore action present for a archived page'
Expand Down Expand Up @@ -2016,10 +2000,6 @@ public function testGetCMSActionsWithoutForms()
$actions->fieldByName('ActionMenus.MoreOptions.action_archive')->getForm(),
'archive action has no form when page is draft'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
'addtocampaign action has no form when page is draft'
);
// END DRAFT

// BEGIN PUBLISHED
Expand All @@ -2030,10 +2010,6 @@ public function testGetCMSActionsWithoutForms()
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(),
'rollback action has no form when page is published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
'addtocampaign action has no form when page is published'
);
// END PUBLISHED

// BEGIN DRAFT AFTER PUBLISHED
Expand All @@ -2057,10 +2033,6 @@ public function testGetCMSActionsWithoutForms()
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(),
'rollback action has no form when page is draft after published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
'addtocampaign action has no form when page is draft after published'
);
// END DRAFT AFTER PUBLISHED

// BEGIN ARCHIVED
Expand Down

0 comments on commit a3600be

Please sign in to comment.