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
The first error
Is solved by adding ::list in the route
This will trigger
Solved with this TypoScript setup code
The lines
are not important.
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.