Skip to content

Commit c8f6c77

Browse files
committed
ENH Add campaign-admin support back in
1 parent 0958f4f commit c8f6c77

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

code/Controllers/CMSMain.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -1427,9 +1427,28 @@ protected function getArchiveWarningMessage(DataObject $record): string
14271427

14281428
// Get the IDs of all changeset including at least one of the records.
14291429
$descendants[] = $record->ID;
1430+
$inChangeSetIDs = ChangeSetItem::get()->filter([
1431+
'ObjectID' => $descendants,
1432+
'ObjectClass' => SiteTree::class
1433+
])->column('ChangeSetID');
14301434

1431-
if (count($descendants ?? []) > 0) {
1435+
// Count number of affected change set
1436+
$affectedChangeSetCount = 0;
1437+
if (count($inChangeSetIDs ?? []) > 0) {
1438+
$affectedChangeSetCount = ChangeSet::get()
1439+
->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
1440+
->count();
1441+
}
1442+
1443+
$numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
1444+
$numCampaigns = mb_strtolower($numCampaigns ?? '');
1445+
1446+
if (count($descendants ?? []) > 0 && $affectedChangeSetCount > 0) {
1447+
$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 ]);
1448+
} elseif (count($descendants ?? []) > 0) {
14321449
$archiveWarningMsg = $defaultMessage;
1450+
} elseif ($affectedChangeSetCount > 0) {
1451+
$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 ]);
14331452
} else {
14341453
$archiveWarningMsg = _t(
14351454
LeftAndMain::class . '.ArchiveWarning',

tests/php/Model/SiteTreeTest.php

+36
Original file line numberDiff line numberDiff line change
@@ -1690,14 +1690,32 @@ public function testGetCMSActions()
16901690
$actions->fieldByName('ActionMenus.MoreOptions.action_archive'),
16911691
'archive action present for a saved draft page'
16921692
);
1693+
if (class_exists(AddToCampaignHandler::class)) {
1694+
$this->assertNotNull(
1695+
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
1696+
'addtocampaign action present for a saved draft page'
1697+
);
1698+
}
16931699
$this->assertNull(
16941700
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
16951701
'no unpublish action present for a saved draft page'
16961702
);
1703+
if (class_exists(AddToCampaignHandler::class)) {
1704+
$this->assertNotNull(
1705+
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
1706+
'addtocampaign action present for a published page'
1707+
);
1708+
}
16971709
$this->assertNull(
16981710
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
16991711
'no rollback action present for a saved draft page'
17001712
);
1713+
if (class_exists(AddToCampaignHandler::class)) {
1714+
$this->assertNotNull(
1715+
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
1716+
'addtocampaign action present for a changed published page'
1717+
);
1718+
}
17011719
$this->assertNull(
17021720
$actions->fieldByName('MajorActions.action_restore'),
17031721
'no restore action present for a saved draft page'
@@ -1805,6 +1823,12 @@ public function testGetCMSActionsWithoutForms()
18051823
$actions->fieldByName('ActionMenus.MoreOptions.action_archive')->getForm(),
18061824
'archive action has no form when page is draft'
18071825
);
1826+
if (class_exists(AddToCampaignHandler::class)) {
1827+
$this->assertEmpty(
1828+
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
1829+
'addtocampaign action has no form when page is draft'
1830+
);
1831+
}
18081832
// END DRAFT
18091833

18101834
// BEGIN PUBLISHED
@@ -1815,6 +1839,12 @@ public function testGetCMSActionsWithoutForms()
18151839
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(),
18161840
'rollback action has no form when page is published'
18171841
);
1842+
if (class_exists(AddToCampaignHandler::class)) {
1843+
$this->assertEmpty(
1844+
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
1845+
'addtocampaign action has no form when page is published'
1846+
);
1847+
}
18181848
// END PUBLISHED
18191849

18201850
// BEGIN DRAFT AFTER PUBLISHED
@@ -1838,6 +1868,12 @@ public function testGetCMSActionsWithoutForms()
18381868
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(),
18391869
'rollback action has no form when page is draft after published'
18401870
);
1871+
if (class_exists(AddToCampaignHandler::class)) {
1872+
$this->assertEmpty(
1873+
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
1874+
'addtocampaign action has no form when page is draft after published'
1875+
);
1876+
}
18411877
// END DRAFT AFTER PUBLISHED
18421878

18431879
// BEGIN ARCHIVED

0 commit comments

Comments
 (0)