src/Controllers/BetterButtonsCustomActionRequest.php
public function handleCustomAction(HTTPRequest $r)
    {
        $action = $r->param('Action');
        if (!$this->record->isCustomActionAllowed($action)) {
            return $this->httpError(403);
        }

        $formAction = $this->record->findActionByName($action);
        if (!$formAction) {
            return $this->httpError(403, "Action $action doesn't exist");
        }

        $message = $this->record->$action($formAction, $this->controller, $r);

        Controller::curr()->getResponse()->addHeader("X-Pjax", "Content");
        Controller::curr()->getResponse()->addHeader('X-Status', $message);

        if ($formAction->getRedirectURL()) {
            return Controller::curr()->redirect($formAction->getRedirectURL());
        }

        if ($formAction->getRedirectType() == BetterButtonCustomAction::GOBACK) {
            return Controller::curr()->redirect(preg_replace('/\?.*/', '', $this->parent->getBackLink()));
        }

        return Controller::curr()->redirect(
            $this->controller->getEditLink($this->record->ID)
        );
    }
public function handleCustomAction(HTTPRequest $r)
    {
        $action = $r->param('Action');
        if (!$this->record->isCustomActionAllowed($action)) {
            return $this->httpError(403);
        }

        $formAction = $this->record->findActionByName($action);
        if (!$formAction) {
            return $this->httpError(403, "Action $action doesn't exist");
        }

        $message = $this->record->$action($formAction, $this->controller, $r);

        Controller::curr()->getResponse()->addHeader("X-Pjax", "Content");
        Controller::curr()->getResponse()->addHeader('X-Status', $message);

        if ($formAction->getRedirectURL()) {
            return Controller::curr()->redirect($formAction->getRedirectURL());
        }

        if ($formAction->getRedirectType() == BetterButtonCustomAction::GOBACK) {
            return Controller::curr()->redirect(preg_replace('/\?.*/', '', $this->parent->getBackLink()));
        }

        return Controller::curr()->redirect(
            $this->controller->getEditLink($this->record->ID)
        );
    }
public function handleCustomAction ( HTTPRequest $ r ) { $ action = $ r -> param ( 'Action' ) ; if ( ! $ this -> record -> isCustomActionAllowed ( $ action ) ) { return $ this -> httpError ( 403 ) ; } $ formAction = $ this -> record -> findActionByName ( $ action ) ; if ( ! $ formAction ) { return $ this -> httpError ( 403 , "Action $action doesn't exist" ) ; } $ message = $ this -> record -> $ action ( $ formAction , $ this -> controller , $ r ) ; Controller :: curr ( ) -> getResponse ( ) -> addHeader ( "X-Pjax" , "Content" ) ; Controller :: curr ( ) -> getResponse ( ) -> addHeader ( 'X-Status' , $ message ) ; if ( $ formAction -> getRedirectURL ( ) ) { return Controller :: curr ( ) -> redirect ( $ formAction -> getRedirectURL ( ) ) ; } if ( $ formAction -> getRedirectType ( ) == BetterButtonCustomAction :: GOBACK ) { return Controller :: curr ( ) -> redirect ( preg_replace ( '/\?.*/' , '' , $ this -> parent -> getBackLink ( ) ) ) ; } return Controller :: curr ( ) -> redirect ( $ this -> controller -> getEditLink ( $ this -> record -> ID ) ) ; }
Takes the action at /customaction/my-action-name and feeds it to the DataObject.
Checks to see if the method is allowed to be invoked first.

@param  HTTPRequest $r
@return HTTPResponse
Takes the action at / customaction / my - action - name and feeds it to the DataObject . Checks to see if the method is allowed to be invoked first .