src/Forms/GridField/GridField.php
public function handleRequest(HTTPRequest $request)
    {
        if ($this->brokenOnConstruct) {
            user_error(
                sprintf(
                    "parent::__construct() needs to be called on %s::__construct()",
                    __CLASS__
                ),
                E_USER_WARNING
            );
        }

        $this->setRequest($request);

        $fieldData = $this->getRequest()->requestVar($this->getName());

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

        foreach ($this->getComponents() as $component) {
            if ($component instanceof GridField_URLHandler && $urlHandlers = $component->getURLHandlers($this)) {
                foreach ($urlHandlers as $rule => $action) {
                    if ($params = $request->match($rule, true)) {
                        // Actions can reference URL parameters.
                        // e.g. '$Action/$ID/$OtherID' → '$Action'

                        if ($action[0] == '$') {
                            $action = $params[substr($action, 1)];
                        }

                        if (!method_exists($component, 'checkAccessAction') || $component->checkAccessAction($action)) {
                            if (!$action) {
                                $action = "index";
                            }

                            if (!is_string($action)) {
                                throw new LogicException(sprintf(
                                    'Non-string method name: %s',
                                    var_export($action, true)
                                ));
                            }

                            try {
                                $result = $component->$action($this, $request);
                            } catch (HTTPResponse_Exception $responseException) {
                                $result = $responseException->getResponse();
                            }

                            if ($result instanceof HTTPResponse && $result->isError()) {
                                return $result;
                            }

                            if ($this !== $result &&
                                !$request->isEmptyPattern($rule) &&
                                ($result instanceof RequestHandler || $result instanceof HasRequestHandler)
                            ) {
                                if ($result instanceof HasRequestHandler) {
                                    $result = $result->getRequestHandler();
                                }
                                $returnValue = $result->handleRequest($request);

                                if (is_array($returnValue)) {
                                    throw new LogicException(
                                        'GridField_URLHandler handlers can\'t return arrays'
                                    );
                                }

                                return $returnValue;
                            }

                            if ($request->allParsed()) {
                                return $result;
                            }

                            return $this->httpError(
                                404,
                                sprintf(
                                    'I can\'t handle sub-URLs of a %s object.',
                                    get_class($result)
                                )
                            );
                        }
                    }
                }
            }
        }

        return parent::handleRequest($request);
    }
public function handleRequest(HTTPRequest $request)
    {
        if ($this->brokenOnConstruct) {
            user_error(
                sprintf(
                    "parent::__construct() needs to be called on %s::__construct()",
                    __CLASS__
                ),
                E_USER_WARNING
            );
        }

        $this->setRequest($request);

        $fieldData = $this->getRequest()->requestVar($this->getName());

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

        foreach ($this->getComponents() as $component) {
            if ($component instanceof GridField_URLHandler && $urlHandlers = $component->getURLHandlers($this)) {
                foreach ($urlHandlers as $rule => $action) {
                    if ($params = $request->match($rule, true)) {
                        // Actions can reference URL parameters.
                        // e.g. '$Action/$ID/$OtherID' → '$Action'

                        if ($action[0] == '$') {
                            $action = $params[substr($action, 1)];
                        }

                        if (!method_exists($component, 'checkAccessAction') || $component->checkAccessAction($action)) {
                            if (!$action) {
                                $action = "index";
                            }

                            if (!is_string($action)) {
                                throw new LogicException(sprintf(
                                    'Non-string method name: %s',
                                    var_export($action, true)
                                ));
                            }

                            try {
                                $result = $component->$action($this, $request);
                            } catch (HTTPResponse_Exception $responseException) {
                                $result = $responseException->getResponse();
                            }

                            if ($result instanceof HTTPResponse && $result->isError()) {
                                return $result;
                            }

                            if ($this !== $result &&
                                !$request->isEmptyPattern($rule) &&
                                ($result instanceof RequestHandler || $result instanceof HasRequestHandler)
                            ) {
                                if ($result instanceof HasRequestHandler) {
                                    $result = $result->getRequestHandler();
                                }
                                $returnValue = $result->handleRequest($request);

                                if (is_array($returnValue)) {
                                    throw new LogicException(
                                        'GridField_URLHandler handlers can\'t return arrays'
                                    );
                                }

                                return $returnValue;
                            }

                            if ($request->allParsed()) {
                                return $result;
                            }

                            return $this->httpError(
                                404,
                                sprintf(
                                    'I can\'t handle sub-URLs of a %s object.',
                                    get_class($result)
                                )
                            );
                        }
                    }
                }
            }
        }

        return parent::handleRequest($request);
    }
public function handleRequest ( HTTPRequest $ request ) { if ( $ this -> brokenOnConstruct ) { user_error ( sprintf ( "parent::__construct() needs to be called on %s::__construct()" , __CLASS__ ) , E_USER_WARNING ) ; } $ this -> setRequest ( $ request ) ; $ fieldData = $ this -> getRequest ( ) -> requestVar ( $ this -> getName ( ) ) ; /** @skipUpgrade */ if ( $ fieldData && isset ( $ fieldData [ 'GridState' ] ) ) { $ this -> getState ( false ) -> setValue ( $ fieldData [ 'GridState' ] ) ; } foreach ( $ this -> getComponents ( ) as $ component ) { if ( $ component instanceof GridField_URLHandler && $ urlHandlers = $ component -> getURLHandlers ( $ this ) ) { foreach ( $ urlHandlers as $ rule => $ action ) { if ( $ params = $ request -> match ( $ rule , true ) ) { // Actions can reference URL parameters. // e.g. '$Action/$ID/$OtherID' → '$Action' if ( $ action [ 0 ] == '$' ) { $ action = $ params [ substr ( $ action , 1 ) ] ; } if ( ! method_exists ( $ component , 'checkAccessAction' ) || $ component -> checkAccessAction ( $ action ) ) { if ( ! $ action ) { $ action = "index" ; } if ( ! is_string ( $ action ) ) { throw new LogicException ( sprintf ( 'Non-string method name: %s' , var_export ( $ action , true ) ) ) ; } try { $ result = $ component -> $ action ( $ this , $ request ) ; } catch ( HTTPResponse_Exception $ responseException ) { $ result = $ responseException -> getResponse ( ) ; } if ( $ result instanceof HTTPResponse && $ result -> isError ( ) ) { return $ result ; } if ( $ this !== $ result && ! $ request -> isEmptyPattern ( $ rule ) && ( $ result instanceof RequestHandler || $ result instanceof HasRequestHandler ) ) { if ( $ result instanceof HasRequestHandler ) { $ result = $ result -> getRequestHandler ( ) ; } $ returnValue = $ result -> handleRequest ( $ request ) ; if ( is_array ( $ returnValue ) ) { throw new LogicException ( 'GridField_URLHandler handlers can\'t return arrays' ) ; } return $ returnValue ; } if ( $ request -> allParsed ( ) ) { return $ result ; } return $ this -> httpError ( 404 , sprintf ( 'I can\'t handle sub-URLs of a %s object.' , get_class ( $ result ) ) ) ; } } } } } return parent :: handleRequest ( $ request ) ; }
Custom request handler that will check component handlers before proceeding to the default
implementation.

@todo copy less code from RequestHandler.

@param HTTPRequest $request
@return array|RequestHandler|HTTPResponse|string
@throws HTTPResponse_Exception
Custom request handler that will check component handlers before proceeding to the default implementation .