skip to Main Content

I have an extbase extension. If I add a new item then I see this error:

PHP Warning: Undefined array key 1 in
/var/www/html/typo3/typo3_src-11.5.13/typo3/sysext/extbase/Classes/Routing/ExtbasePluginEnhancer.php line 202

My method:

public function listAction(): ResponseInterface
{
    // List
    if ($this->settings['display'] == '0') {
        if ($this->settings['categories'] != '') {
            if ($this->settings['important'] != '0') {
                $articles = $this->getImportantFromCategories();
            } else {
                $articles = $this->getFromCategories();
            }
        } else {
            if ($this->settings['important'] != '0') {
                $articles = $this->getImportantArticles();
            } else {
                $articles = $this->getArticles();
            }
        }
    }
    // Archive
    if ($this->settings['display'] == '2') {
        $articles = $this->getArchivedArticles();
    }
    // If not details
    if ($this->settings['display'] != '1') {
        // Pagination
        $articlesArray = $articles->toArray();
        $currentPage = $this->request->hasArgument('currentPage') ? $this->request->getArgument('currentPage') : 1;
        $paginator = new ArrayPaginator($articlesArray, intval($currentPage), intval($this->settings['perpage']));
        $simplePagination = new SimplePagination($paginator);
        $articles = $this->articleRepository->findAll();
        $this->view->assignMultiple(
            [
                'articles' => $articles,
                'paginator' => $paginator,
                'pagination' =>
                    [
                        'lastPageNumber' => $simplePagination->getLastPageNumber(),
                        'firstPageNumber' => $simplePagination->getFirstPageNumber(),
                        'nextPageNumber' => $simplePagination->getNextPageNumber(),
                        'previousPageNumber' => $simplePagination->getPreviousPageNumber(),
                        'startRecordNumber' => $simplePagination->getStartRecordNumber(),
                        'endRecordNumber' => $simplePagination->getEndRecordNumber(),
                        'currentPageNumber' => $paginator->getCurrentPageNumber(),
                        'pages' => $simplePagination->getAllPageNumbers(),
                        'article_counter' => $this->article_counter,
                    ],
                'article_counter' => $this->article_counter,
            ]
        );
    }
    return $this->htmlResponse();
}

and the getArticles() method:

public function getArticles()
    {
        $table = 'tx_extension_domain_model_article';
        $query = $this->articleRepository->createQuery();
        if ($this->settings['sorting'] == 'list') {
            $query->statement('SELECT * FROM ' . $table . ' WHERE archived != 1');
        } else {
            $query->statement('SELECT * FROM ' . $table . ' WHERE archived != 1 ORDER BY crdate DESC');
        }
        $this->article_counter = $query->count();
        return $query->execute();
    }

I don’t know why this error message is triggered.

The only change is the PHP Version from 7.4 to 8.0.21.

My route enhancer

routeEnhancers:
  Plugin:
    type: Extbase
    extension: Plugin
    plugin: News
    routes:
      - routePath: '/{slug}'
        _controller: 'Article::show'
        _arguments:
          slug: article
      - routePath: '/page/{page}'
        _controller: 'Article'
        _arguments:
          page: currentPage
    defaultController: 'Article::list'
    requirements:
      slug: '^[a-zA-Z0-9].*$'
      page: 'd+'
    aspects:
      slug:
        type: PersistedAliasMapper
        tableName: tx_extension_domain_model_article
        routeFieldName: slug
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'

2

Answers


  1. Chosen as BEST ANSWER

    The first error

    PHP Warning: Undefined array key 1 in /var/www/html/typo3/typo3_src-11.5.13/typo3/sysext/extbase/Classes/Routing/ExtbasePluginEnhancer.php line 202

    Is solved by adding ::list in the route

    - routePath: '/page/{page}'
      _controller: 'Article::list'
      _arguments:
        page: currentPage
    

    This will trigger

    PHP Warning: Undefined array key "nonWrappedTag" in /var/www/html/typo3/typo3_src-11.5.14/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 3812

    Solved with this TypoScript setup code

    lib.parseFunc_teaser < lib.parseFunc_RTE
    lib.parseFunc_teaser.nonTypoTagStdWrap.encapsLines >
    lib.parseFunc_teaser.nonTypoTagStdWrap.encapsLines {
      encapsTagList = p
      remapTag.P =
      nonWrappedTag =
    }
    

    The lines

    encapsTagList = p
    remapTag.P =
    

    are not important.


  2. You should look up your extbase plugin route enhancer configuration in your site configuration.

    Reading the given error, and look into the corresponding code, it seems that you have a invalid value for a ‘_controller’ or ‘defaultController’ configuration in there.

    It should be something like MyController::myaction .. and taken the error, the second part "::myaction" seems to be missing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search