src/AddToCampaignHandler.php
public function addToCampaign($object, $data)
    {
        // Extract $campaignID from $data
        $campaignID = $this->getOrCreateCampaign($data);

        /** @var ChangeSet $changeSet */
        $changeSet = ChangeSet::get()->byID($campaignID);

        if (!$changeSet) {
            throw new ValidationException(_t(
                __CLASS__ . '.ErrorNotFound',
                'That {Type} couldn\'t be found',
                ['Type' => 'Campaign']
            ));
        }

        if (!$changeSet->canEdit()) {
            throw new ValidationException(_t(
                __CLASS__ . '.ErrorCampaignPermissionDenied',
                'It seems you don\'t have the necessary permissions to add {ObjectTitle} to {CampaignTitle}',
                [
                    'ObjectTitle' => $object->Title,
                    'CampaignTitle' => $changeSet->Title
                ]
            ));
        }

        $changeSet->addObject($object);

        $request = $this->controller->getRequest();
        $message = _t(
            __CLASS__ . '.Success',
            'Successfully added <strong>{ObjectTitle}</strong> to <strong>{CampaignTitle}</strong>',
            [
                'ObjectTitle' => Convert::raw2xml($object->Title),
                'CampaignTitle' => Convert::raw2xml($changeSet->Title)
            ]
        );
        if ($request->getHeader('X-Formschema-Request')) {
            return $message;
        } elseif (Director::is_ajax()) {
            $response = new HTTPResponse($message, 200);

            $response->addHeader('Content-Type', 'text/html; charset=utf-8');
            return $response;
        } else {
            return $this->controller->redirectBack();
        }
    }
public function addToCampaign($object, $data)
    {
        // Extract $campaignID from $data
        $campaignID = $this->getOrCreateCampaign($data);

        /** @var ChangeSet $changeSet */
        $changeSet = ChangeSet::get()->byID($campaignID);

        if (!$changeSet) {
            throw new ValidationException(_t(
                __CLASS__ . '.ErrorNotFound',
                'That {Type} couldn\'t be found',
                ['Type' => 'Campaign']
            ));
        }

        if (!$changeSet->canEdit()) {
            throw new ValidationException(_t(
                __CLASS__ . '.ErrorCampaignPermissionDenied',
                'It seems you don\'t have the necessary permissions to add {ObjectTitle} to {CampaignTitle}',
                [
                    'ObjectTitle' => $object->Title,
                    'CampaignTitle' => $changeSet->Title
                ]
            ));
        }

        $changeSet->addObject($object);

        $request = $this->controller->getRequest();
        $message = _t(
            __CLASS__ . '.Success',
            'Successfully added <strong>{ObjectTitle}</strong> to <strong>{CampaignTitle}</strong>',
            [
                'ObjectTitle' => Convert::raw2xml($object->Title),
                'CampaignTitle' => Convert::raw2xml($changeSet->Title)
            ]
        );
        if ($request->getHeader('X-Formschema-Request')) {
            return $message;
        } elseif (Director::is_ajax()) {
            $response = new HTTPResponse($message, 200);

            $response->addHeader('Content-Type', 'text/html; charset=utf-8');
            return $response;
        } else {
            return $this->controller->redirectBack();
        }
    }
public function addToCampaign ( $ object , $ data ) { // Extract $campaignID from $data $ campaignID = $ this -> getOrCreateCampaign ( $ data ) ; /** @var ChangeSet $changeSet */ $ changeSet = ChangeSet :: get ( ) -> byID ( $ campaignID ) ; if ( ! $ changeSet ) { throw new ValidationException ( _t ( __CLASS__ . '.ErrorNotFound' , 'That {Type} couldn\'t be found' , [ 'Type' => 'Campaign' ] ) ) ; } if ( ! $ changeSet -> canEdit ( ) ) { throw new ValidationException ( _t ( __CLASS__ . '.ErrorCampaignPermissionDenied' , 'It seems you don\'t have the necessary permissions to add {ObjectTitle} to {CampaignTitle}' , [ 'ObjectTitle' => $ object -> Title , 'CampaignTitle' => $ changeSet -> Title ] ) ) ; } $ changeSet -> addObject ( $ object ) ; $ request = $ this -> controller -> getRequest ( ) ; $ message = _t ( __CLASS__ . '.Success' , 'Successfully added <strong>{ObjectTitle}</strong> to <strong>{CampaignTitle}</strong>' , [ 'ObjectTitle' => Convert :: raw2xml ( $ object -> Title ) , 'CampaignTitle' => Convert :: raw2xml ( $ changeSet -> Title ) ] ) ; if ( $ request -> getHeader ( 'X-Formschema-Request' ) ) { return $ message ; } elseif ( Director :: is_ajax ( ) ) { $ response = new HTTPResponse ( $ message , 200 ) ; $ response -> addHeader ( 'Content-Type' , 'text/html; charset=utf-8' ) ; return $ response ; } else { return $ this -> controller -> redirectBack ( ) ; } }
Performs the actual action of adding the object to the ChangeSet, once the ChangeSet ID is known

@param DataObject $object The object to add to the ChangeSet
@param array|int $data Post data for this campaign form, or the ID of the campaign to add to
@return HTTPResponse
@throws ValidationException
Performs the actual action of adding the object to the ChangeSet once the ChangeSet ID is known