SilverStripe\CampaignAdmin\AddToCampaignHandler
Class AddToCampaignHandler - handle the AddToCampaign action.
This is a class designed to be delegated to by a Form action handler method in the EditForm of a LeftAndMain
child class.
Add To Campaign can be seen as an item action like "publish" or "rollback", but unlike those actions
it needs one additional piece of information to execute, the ChangeSet ID.
So this handler does one of two things to respond to the action request, depending on whether the ChangeSet ID
was included in the submitted data
- If it was, perform the Add To Campaign action (as per any other action)
- If it wasn't, return a form to get the ChangeSet ID and then repeat this action submission
To use, you'd add an action to your LeftAndMain subclass, like this:
function addtocampaign($data, $form) {
$handler = AddToCampaignHandler::create($form, $data);
return $handler->handle();
}
and add an AddToCampaignHandler_FormAction to the EditForm, possibly through getCMSActions
Synopsis
- // members
- protected Controller $controller;
- protected $data;
- protected $name;
- // methods
- public void __construct()
- public DBHTMLText|HTTPResponse handle()
- protected array getAvailableChangeSets()
- protected ArrayList[ChangeSet] getInChangeSets()
- protected DataObject getObject()
- public Form Form()
- public HTTPResponse addToCampaign()
- protected string getFormAlert()
- protected int getOrCreateCampaign()
- protected ValidationException validationResult()
Hierarchy
Uses
- SilverStripe\Core\Injector\Injectable
Members
protected
- $controller
—
SilverStripe\Control\Controller
Parent controller for this form - $data
—
array
The submitted form data - $name
—
string
Form name to use
Methods
protected
- getAvailableChangeSets() — Get what ChangeSets are available for an item to be added to by this user
- getFormAlert() — Get descriptive alert to display at the top of the form
- getInChangeSets() — Get changesets that a given object is already in
- getObject() — Safely get a DataObject from a client-supplied ID and ClassName, checking: argument validity; existence; and canView permissions.
- getOrCreateCampaign() — Find or build campaign from posted data
- validationResult() — Raise validation error
public
- __construct() — AddToCampaignHandler constructor.
- Form() — Builds a Form that mirrors the parent editForm, but with an extra field to collect the ChangeSet ID
- addToCampaign() — Performs the actual action of adding the object to the ChangeSet, once the ChangeSet ID is known
- handle() — Perform the action. Either returns a Form or performs the action, as per the class doc