georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
265 stars 355 forks source link

Category filter without routeEnhancer throws exception #1658

Open bavarianbytes opened 2 years ago

bavarianbytes commented 2 years ago

Bug Report

Current Behavior If a place a categories plugin for filtering on the same page as the list view plugin, the generated links to the categories are either:

  1. throwing an exception if i don't define a routeEnhancer for categories, or
  2. do not work cause of issue #1640

Cause of case 2. i use case 1. Here are the details: The exception is:

(1/1) #1573047338 InvalidArgumentException
Argument $currentPageNumber must be greater than 0

Seems that the generated links via

<f:link.page pageUid="{settings.listPid}" additionalParams="{tx_news_pi1:{overwriteDemand:{categories: category.item.uid}}}">{category.item.title}</f:link.page>

(single filter), or

<f:link.page pageUid="{settings.listPid}" additionalParams="{n:multiCategoryLink.arguments(mode: 'add', item: filterId, list: overwriteDemand.categories)}">{category.item.title}</f:link.page>

(multi-filter)

have problems with paging. The paging routeEnhancer keyword seite ist used without a number. In my case the urls look like this: domain.de/news (list view) domain.de/news/seite-2 (paged list view) domain.de/news/seite?tx_news_pi1%5BoverwriteDemand%5D%5Bcategories%5D=29&cHash=154fcbe5069cfdb109b73cd394e2f637 (generated link from category filter)

My site config:

    routes:
      - routePath: '/'
        _controller: 'News::list'
      -
        routePath: '/{page-label}-{page}'
        _controller: 'News::list'
        _arguments:
          page: 'currentPage'
      # -
      #   routePath: '/{category-name}'
      #   _controller: 'News::list'
      #   _arguments:
      #     category-name: overwriteDemand/categories
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      page-label:
        type: LocaleModifier
        default: seite
        localeMap:
...

Expected behavior/output Generated category links should look like this: domain.de/news?tx_news_pi1%5BoverwriteDemand%5D%5Bcategories%5D=29&cHash=154fcbe5069cfdb109b73cd394e2f637

Environment

georgringer commented 2 years ago

Thanks for creating the issue

(1/1) #1573047338 InvalidArgumentException Argument $currentPageNumber must be greater than 0

can you add some more stacktrace?

bavarianbytes commented 2 years ago
(1/1) #1573047338 InvalidArgumentException
Argument $currentPageNumber must be greater than 0

in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/core/Classes/Pagination/AbstractPaginator.php line 177

    protected function setCurrentPageNumber(int $currentPageNumber): void
    {
        if ($currentPageNumber < 1) {
            throw new \InvalidArgumentException(
                'Argument $currentPageNumber must be greater than 0',
                1573047338
            );
        }
at TYPO3\CMS\Core\Pagination\AbstractPaginator->setCurrentPageNumber(0)
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Pagination/QueryResultPaginator.php line 41
        int $currentPageNumber = 1,
        int $itemsPerPage = 10
    ) {
        $this->queryResult = $queryResult;
        $this->setCurrentPageNumber($currentPageNumber);
        $this->setItemsPerPage($itemsPerPage);

        $this->updateInternalState();
    }
at TYPO3\CMS\Extbase\Pagination\QueryResultPaginator->__construct(object(TYPO3\CMS\Extbase\Persistence\Generic\QueryResult), 0, 2)
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/core/Classes/Utility/GeneralUtility.php line 3477
            return self::$container->get($className);
        }

        // Create new instance and call constructor with parameters
        $instance = new $finalClassName(...$constructorArguments);
        // Register new singleton instance, but only if it is not a known PSR-11 container service
        if ($instance instanceof SingletonInterface && !(self::$container !== null && self::$container->has($className))) {
            self::$singletonInstances[$finalClassName] = $instance;
        }
at TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Pagination\\QueryResultPaginator', object(TYPO3\CMS\Extbase\Persistence\Generic\QueryResult), 0, 2)
in /Users/christoph/Git/cd_sitebase/myproject/typo3conf/ext/news/Classes/Controller/NewsController.php line 244
        $itemsPerPage = (int)($paginationConfiguration['itemsPerPage'] ?: 10);
        $maximumNumberOfLinks = (int)($paginationConfiguration['maximumNumberOfLinks'] ?? 0);

        $currentPage = $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1;
        $paginator = GeneralUtility::makeInstance(QueryResultPaginator::class, $newsRecords, $currentPage, $itemsPerPage);
        $paginationClass = $paginationConfiguration['class'] ?? SimplePagination::class;
        if ($paginationClass === NumberedPagination::class && $maximumNumberOfLinks && class_exists(NumberedPagination::class)) {
            $pagination = GeneralUtility::makeInstance(NumberedPagination::class, $paginator, $maximumNumberOfLinks);
        } elseif (class_exists($paginationClass)) {
at GeorgRinger\News\Controller\NewsController->listAction(array('categories' => '30'))
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php line 498
        }
        $validationResult = $this->arguments->validate();
        if (!$validationResult->hasErrors()) {
            $this->eventDispatcher->dispatch(new BeforeActionCallEvent(static::class, $this->actionMethodName, $preparedArguments));
            $actionResult = $this->{$this->actionMethodName}(...$preparedArguments);
        } else {
            $actionResult = $this->{$this->errorMethodName}();
        }

at TYPO3\CMS\Extbase\Mvc\Controller\ActionController->callActionMethod()
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php line 426
        $this->view = $this->resolveView();
        if ($this->view !== null) {
            $this->initializeView($this->view);
        }
        $this->callActionMethod();
        $this->renderAssetsForRequest($request);
    }

    /**
at TYPO3\CMS\Extbase\Mvc\Controller\ActionController->processRequest(object(TYPO3\CMS\Extbase\Mvc\Web\Request), object(TYPO3\CMS\Extbase\Mvc\Web\Response))
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Mvc/Dispatcher.php line 89
                throw new InfiniteLoopException('Could not ultimately dispatch the request after ' . $dispatchLoopCount . ' iterations. Most probably, a @' . IgnoreValidation::class . ' annotation is missing on re-displaying a form with validation errors.', 1217839467);
            }
            $controller = $this->resolveController($request);
            try {
                $controller->processRequest($request, $response);
            } catch (StopActionException $ignoredException) {
            }
        }

at TYPO3\CMS\Extbase\Mvc\Dispatcher->dispatch(object(TYPO3\CMS\Extbase\Mvc\Web\Request), object(TYPO3\CMS\Extbase\Mvc\Web\Response))
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Mvc/Web/FrontendRequestHandler.php line 66
        }

        /** @var \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response */
        $response = $this->objectManager->get(Response::class);
        $this->dispatcher->dispatch($request, $response);
        return $response;
    }

    /**
at TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler->handleRequest()
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Core/Bootstrap.php line 183
    protected function handleRequest(): string
    {
        $requestHandler = $this->requestHandlerResolver->resolveRequestHandler();

        $response = $requestHandler->handleRequest();
        // If response is NULL after handling the request we need to stop
        // This happens for instance, when a USER object was converted to a USER_INT
        // @see TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::handleRequest()
        if ($response === null) {
at TYPO3\CMS\Extbase\Core\Bootstrap->handleRequest()
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/extbase/Classes/Core/Bootstrap.php line 173
     */
    public function run(string $content, array $configuration): string
    {
        $this->initialize($configuration);
        return $this->handleRequest();
    }

    /**
     * @return string
at TYPO3\CMS\Extbase\Core\Bootstrap->run('', array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1'))
at call_user_func_array(array(object(TYPO3\CMS\Extbase\Core\Bootstrap), 'run'), array('', array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1')))
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 5690
                if (is_object($classObj) && method_exists($classObj, $parts[1]) && is_callable($callable)) {
                    $classObj->cObj = $this;
                    $content = call_user_func_array($callable, [
                        $content,
                        $conf
                    ]);
                } else {
                    $this->getTimeTracker()->setTSlogMessage('Method "' . $parts[1] . '" did not exist in class "' . $parts[0] . '"', 3);
                }
at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->callUserFunction('TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1'), '')
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/frontend/Classes/ContentObject/UserContentObject.php line 43
        if ($this->cObj->getUserObjectType() === false) {
            // Come here only if we are not called from $TSFE->processNonCacheableContentPartsAndSubstituteContentMarkers()!
            $this->cObj->setUserObjectType(ContentObjectRenderer::OBJECTTYPE_USER);
        }
        $tempContent = $this->cObj->callUserFunction($conf['userFunc'], $conf, '');
        if ($this->cObj->doConvertToUserIntObject) {
            $this->cObj->doConvertToUserIntObject = false;
            $content = $this->cObj->cObjGetSingle('USER_INT', $conf);
        } else {
at TYPO3\CMS\Frontend\ContentObject\UserContentObject->render(array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1'))
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 828
        }

        // Render content
        try {
            $content .= $contentObject->render($configuration);
        } catch (ContentRenderingException $exception) {
            // Content rendering Exceptions indicate a critical problem which should not be
            // caught e.g. when something went wrong with Exception handling itself
            throw $exception;
at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->render(object(TYPO3\CMS\Frontend\ContentObject\UserContentObject), array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1'))
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 742
                }
                if (!$hooked) {
                    $contentObject = $this->getContentObject($name);
                    if ($contentObject) {
                        $content .= $this->render($contentObject, $conf);
                    } else {
                        // Call hook functions for extra processing
                        if ($name) {
                            if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault'])) {
at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->cObjGetSingle('USER', array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1'), 'tt_content.list.20.news_pi1')
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php line 193
        if ($timeTracker->LR) {
            $timeTracker->push('/f:cObject/', '<' . $typoscriptObjectPath);
        }
        $timeTracker->incStackPointer();
        $content = $contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.'] ?? [], $typoscriptObjectPath);
        $timeTracker->decStackPointer();
        if ($timeTracker->LR) {
            $timeTracker->pull($content);
        }
at TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper::renderContentObject(object(TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer), array('indexedsearch_pi2' => 'USER', 'indexedsearch_pi2.' => array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'IndexedSearch', 'pluginName' => 'Pi2'), 'calendarize_calendar' => 'USER', 'calendarize_calendar.' => array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'Calendarize', 'pluginName' => 'Calendar'), 'news_pi1' => 'USER', 'news_pi1.' => array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'News', 'pluginName' => 'Pi1'), 'dce_dce' => 'USER', 'dce_dce.' => array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'Dce', 'pluginName' => 'Dce'), 'powermail_pi1' => 'USER', 'powermail_pi1.' => array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'Powermail', 'pluginName' => 'Pi1'), 'powermail_pi2' => 'USER', 'powermail_pi2.' => array('userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run', 'extensionName' => 'Powermail', 'pluginName' => 'Pi2')), 'tt_content.list.20.news_pi1', 'news_pi1')
in /Users/christoph/Git/cd_sitebase/_sitebase_src/typo3/typo3_src-10.4.21/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php line 170
                'No Content Object definition found at TypoScript object path "' . $typoscriptObjectPath . '"',
                1540246570
            );
        }
        $content = self::renderContentObject($contentObjectRenderer, $setup, $typoscriptObjectPath, $lastSegment);
        if (!isset($GLOBALS['TSFE']) || !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)) {
            static::resetFrontendEnvironment();
        }
        return $content;