src/Forms/GridField/GridField.php
public function gridFieldAlterAction($data, $form, HTTPRequest $request)
    {
        $data = $request->requestVars();

        // Protection against CSRF attacks
        $token = $this
            ->getForm()
            ->getSecurityToken();
        if (!$token->checkRequest($request)) {
            $this->httpError(400, _t(
                "SilverStripe\\Forms\\Form.CSRF_FAILED_MESSAGE",
                "There seems to have been a technical problem. Please click the back button, " . "refresh your browser, and try again."
            ));
        }

        $name = $this->getName();

        $fieldData = null;

        if (isset($data[$name])) {
            $fieldData = $data[$name];
        }

        $state = $this->getState(false);

        /** @skipUpgrade */
        if (isset($fieldData['GridState'])) {
            $state->setValue($fieldData['GridState']);
        }

        // Fetch the store for the "state" of actions (not the GridField)
        /** @var StateStore $store */
        $store = Injector::inst()->create(StateStore::class . '.' . $this->getName());

        foreach ($data as $dataKey => $dataValue) {
            if (preg_match('/^action_gridFieldAlterAction\?StateID=(.*)/', $dataKey, $matches)) {
                $stateChange = $store->load($matches[1]);

                $actionName = $stateChange['actionName'];

                $arguments = array();

                if (isset($stateChange['args'])) {
                    $arguments = $stateChange['args'];
                };

                $html = $this->handleAlterAction($actionName, $arguments, $data);

                if ($html) {
                    return $html;
                }
            }
        }

        if ($request->getHeader('X-Pjax') === 'CurrentField') {
            if ($this->getState()->Readonly === true) {
                $this->performDisabledTransformation();
            }
            return $this->FieldHolder();
        }

        return $form->forTemplate();
    }
public function gridFieldAlterAction($data, $form, HTTPRequest $request)
    {
        $data = $request->requestVars();

        // Protection against CSRF attacks
        $token = $this
            ->getForm()
            ->getSecurityToken();
        if (!$token->checkRequest($request)) {
            $this->httpError(400, _t(
                "SilverStripe\\Forms\\Form.CSRF_FAILED_MESSAGE",
                "There seems to have been a technical problem. Please click the back button, " . "refresh your browser, and try again."
            ));
        }

        $name = $this->getName();

        $fieldData = null;

        if (isset($data[$name])) {
            $fieldData = $data[$name];
        }

        $state = $this->getState(false);

        /** @skipUpgrade */
        if (isset($fieldData['GridState'])) {
            $state->setValue($fieldData['GridState']);
        }

        // Fetch the store for the "state" of actions (not the GridField)
        /** @var StateStore $store */
        $store = Injector::inst()->create(StateStore::class . '.' . $this->getName());

        foreach ($data as $dataKey => $dataValue) {
            if (preg_match('/^action_gridFieldAlterAction\?StateID=(.*)/', $dataKey, $matches)) {
                $stateChange = $store->load($matches[1]);

                $actionName = $stateChange['actionName'];

                $arguments = array();

                if (isset($stateChange['args'])) {
                    $arguments = $stateChange['args'];
                };

                $html = $this->handleAlterAction($actionName, $arguments, $data);

                if ($html) {
                    return $html;
                }
            }
        }

        if ($request->getHeader('X-Pjax') === 'CurrentField') {
            if ($this->getState()->Readonly === true) {
                $this->performDisabledTransformation();
            }
            return $this->FieldHolder();
        }

        return $form->forTemplate();
    }
public function gridFieldAlterAction ( $ data , $ form , HTTPRequest $ request ) { $ data = $ request -> requestVars ( ) ; // Protection against CSRF attacks $ token = $ this -> getForm ( ) -> getSecurityToken ( ) ; if ( ! $ token -> checkRequest ( $ request ) ) { $ this -> httpError ( 400 , _t ( "SilverStripe\\Forms\\Form.CSRF_FAILED_MESSAGE" , "There seems to have been a technical problem. Please click the back button, " . "refresh your browser, and try again." ) ) ; } $ name = $ this -> getName ( ) ; $ fieldData = null ; if ( isset ( $ data [ $ name ] ) ) { $ fieldData = $ data [ $ name ] ; } $ state = $ this -> getState ( false ) ; /** @skipUpgrade */ if ( isset ( $ fieldData [ 'GridState' ] ) ) { $ state -> setValue ( $ fieldData [ 'GridState' ] ) ; } // Fetch the store for the "state" of actions (not the GridField) /** @var StateStore $store */ $ store = Injector :: inst ( ) -> create ( StateStore :: class . '.' . $ this -> getName ( ) ) ; foreach ( $ data as $ dataKey => $ dataValue ) { if ( preg_match ( '/^action_gridFieldAlterAction\?StateID=(.*)/' , $ dataKey , $ matches ) ) { $ stateChange = $ store -> load ( $ matches [ 1 ] ) ; $ actionName = $ stateChange [ 'actionName' ] ; $ arguments = array ( ) ; if ( isset ( $ stateChange [ 'args' ] ) ) { $ arguments = $ stateChange [ 'args' ] ; } ; $ html = $ this -> handleAlterAction ( $ actionName , $ arguments , $ data ) ; if ( $ html ) { return $ html ; } } } if ( $ request -> getHeader ( 'X-Pjax' ) === 'CurrentField' ) { if ( $ this -> getState ( ) -> Readonly === true ) { $ this -> performDisabledTransformation ( ) ; } return $ this -> FieldHolder ( ) ; } return $ form -> forTemplate ( ) ; }
This is the action that gets executed when a GridField_AlterAction gets clicked.

@param array $data
@param Form $form
@param HTTPRequest $request

@return string
This is the action that gets executed when a GridField_AlterAction gets clicked .