AddToCampaignHandler
class AddToCampaignHandler (View source)
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
Traits
A class that can be instantiated or replaced via DI
Methods
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
AddToCampaignHandler constructor.
Perform the action. Either returns a Form or performs the action, as per the class doc
Builds a Form that mirrors the parent editForm, but with an extra field to collect the ChangeSet ID
Performs the actual action of adding the object to the ChangeSet, once the ChangeSet ID is known
Details
static Injectable
create(mixed ...$args)
An implementation of the factory method, allows you to create an instance of a class
This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.
This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();
static Injectable
singleton(string $class = null)
Creates a class instance by the "singleton" design pattern.
It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).
__construct(Controller $controller = null, array|DataObject $data = [], string $name = 'AddToCampaignForm')
AddToCampaignHandler constructor.
DBHTMLText|HTTPResponse
handle()
deprecated
deprecated
Perform the action. Either returns a Form or performs the action, as per the class doc
Form
Form(DataObject $object)
Builds a Form that mirrors the parent editForm, but with an extra field to collect the ChangeSet ID
HTTPResponse
addToCampaign(DataObject $object, array|int $data)
Performs the actual action of adding the object to the ChangeSet, once the ChangeSet ID is known