protected function getGridPagerState(GridField $gridField = null)
    {
        if (!$this->gridFieldState) {
            $state = $this->getGridField()->State->GridFieldConfigurablePaginator;

            // SS 3.1 compatibility (missing __call)
            if (is_object($state->firstShown)) {
                $state->firstShown = 1;
            }
            if (is_object($state->pageSize)) {
                $state->pageSize = $this->getItemsPerPage();
            }

            // Handle free input in the page number field
            $parentState = $this->getGridField()->State->GridFieldPaginator;
            if (is_object($parentState->currentPage)) {
                $parentState->currentPage = 0;
            }

            if ($parentState->currentPage >= 1) {
                $state->firstShown = ($parentState->currentPage - 1) * $this->getItemsPerPage() + 1;
                $parentState->currentPage = null;
            }

            $this->gridFieldState = $state;
        }

        return $this->gridFieldState;
    }