TYPO3 Undefined array key 1 - typo3

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'

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.

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.

Related

Sitemap for events2

I use TYPO3 v10.4.24, events2 v7.1. and the core SEO extension tx_seo.
I configure the sitemap for events2 this way:
plugin.tx_seo {
config {
xmlSitemap {
sitemaps {
events2 {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = tx_events2_domain_model_event
sortField = tstamp
lastModifiedField = tstamp
pid = 2061
recursive = 2
url {
pageId = 917 //PageID Detail Page
fieldToParameterMap {
uid = tx_events2_events[event]
}
additionalGetParameters {
tx_events2_events.controller = Day
tx_events2_events.action = show
}
useCacheHash = 1
}
}
}
}
}
}
}
The sitemap is generated and I can show the detail view. Google accepts the sitemap, too. But the URLs are ugly because the route enhancer is not used. This is my configuration of the route enhancer.
Events2Plugin:
type: Extbase
extension: Events2
plugin: Events
routes:
- { routePath: '', _controller: 'Day::list' }
- { routePath: '/{date}/{event_title}', _controller: 'Day::show', _arguments: { date: 'timestamp', event_title: 'event' }}
- { routePath: '/events/{date}', _controller: 'Day::showByTimestamp', _arguments: { date: 'timestamp' }}
- { routePath: '/{location}', _controller: 'Location::show', _arguments: { location: 'location' }}
- { routePath: '/listpage-{page}', _controller: 'Day::list', _arguments: { page: '#widget_0/currentPage' }}
defaultController: 'Day::list'
defaults:
page: '0'
requirements:
date: '\d+-\d+-\d+_\d+'
event_title: '^[a-zA-Z0-9\-_]+$'
aspects:
date:
type: TimestampMapper
format: Y-m-d_Hi
event_title:
type: PersistedAliasMapper
tableName: tx_events2_domain_model_event
routeFieldName: path_segment
location:
type: PersistedAliasMapper
tableName: tx_events2_domain_model_location
routeFieldName: slug
page:
type: StaticRangeMapper
start: '1'
end: '100'
What can I do that the route enhancer is used as with other extensions.
Your RouteEnhancer configuration for detail view requires a {date}. You only add action and controller to URI in Sitemap configuration.
Please add
tx_events2_events.timestamp = 0
to section „additionalGetParameters“

How can I make 2 search in the one form (vuetify)?

My real case is like this : https://codepen.io/positivethinking639/pen/ZEEaOqy?editors=1010
The vue component like this :
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
selectedCountry: null,
dataCountry: [
{ name: 'England', id: 1 },
{ name: 'Spain', id: 2 },
{ name: 'Italy', id: 3 },
],
selectedClub: null,
dataClub: [
{ name: 'Chelsea', id: 1 },
{ name: 'Madrid', id: 2 },
{ name: 'Juventus', id: 3 },
],
playerName: null,
playerNameRules: [
// v => !!v || 'Name is required',
v => (v && v.length >= 3) || 'Player name at least 3 characters',
],
countryRules: [
v => !!v || 'Country is required',
],
clubRules: [
v => !!v || 'Club is required',
],
validSearch: false,
}),
methods: {
searchPlayer() {
if (this.$refs.formSearch.validate()) {
console.log('validate form success')
}
else
console.log('validate form failed')
}
}
})
so I want the user to be able to search by player name or the user can also search by country and club
if the user enters the player name and clicks the search button, validation is successful. vice versa if the user enters country and club, then click search, it passes validity
so the user can choose one of them to search. but if the user click the search button without selecting one, it displays validation failed
How can I do it?
Use computed property for club and country rules. In function body you can check if another option is selected.
computed: {
clubRules() {
return [
v => (!!v || !!this.selectedCountry) || 'Club is required',
];
}
},
You can have N number of rules for any number inputs in a form, but this a special case where you need to have any one of them to search a player
Instead of form.validate(form validation validates for each input
field based on the rules and independent to the field), In your case
you can manually validate as per your requirements by accessing your
data
methods: {
searchPlayer() {
var playerCondition = this.playerNameRules[0](this.playerName) == true;
var countryClub = this.countryRules[0](this.selectedCountry) == true && this.clubRules[0](this.selectedClub) == true;
if(this.playerName && this.playerName.length < 3) {
playerCondition = false;
countryClub = false;
}
if ((playerCondition) || (countryClub)) {
console.log('validate form success')
}
else
console.log('validate form failed')
}
}
Working codepen here: https://codepen.io/chansv/pen/abbVGRx?editors=1010

Octobercms, redirect to home from component not working

i'm trying to redirect from component if id from slug is wrong.
Running from layout
function onBeforePageStart(){ $this->Contentloader->getMeta(); }
In component i have:
public function getMeta(){
//id checking logic goes here
if ($id == null) return Redirect::to('/'); }
Inspecting the dd(Redirect::to('/')) object I see
But it's not redirecting.
Please advice
Thanks
try this
in your component :
public function getMeta()
{
if ($id == null) return false;
}
in your layout :
function onBeforePageStart()
{
$meta = $this->Contentloader->getMeta();
if(!$meta)
return Redirect::to('/');
}
I hope help you :)
Components should be able to handle redirects without having onBeforePageStart(). This is just a quick example. Here I am checking to see if a component field is null. If it is null then return to '/'.
You can do this in a component: Make sure to utilize the Redirect class use Redirect;
public function defineProperties()
{
return [
'useSomething' => [
'title' => 'Something',
'description' => 'Testing Testing',
'default' => '',
'type' => 'text',
]
];
}
public function onRun()
{
if ($this->property('useSomething') == null) {
return Redirect::to('/');
} else {
$this->page['something'] = $this->property('useSomething');
}
}

Inaccessible site Symfony routing

Can anyone please help me I'm desperate here !!!
I am working on a symfony 3 project and I have different actions to persist data to database or to update it but none of them is working. The code is fine I'm guessing it's a problem with the routing. This one is the action to add element to database
public function newAction(Request $request)
{
...
if($request->isMethod('POST')) {
...
return $this->redirectToRoute('meeting_new', array(
'meeting' => $meeting
));
...
}
return $this->render('SocialProMeetingBundle::ajoutMeeting.html.twig', array('users'=>$users));
}
and this is the updating action
public function editAction(Request $request, Meeting $meeting)
{
...
if($request->isMethod('POST')) {
...
return $this->redirectToRoute('meeting_edit', array(
'id' => $meeting->getId()
));
}
return $this->render('meeting/edit.html.twig', array(
'meeting' => $meeting,
));
}
and this is my routing file
meeting_index:
path: /
defaults: { _controller: "SocialProMeetingBundle:Meeting:index" }
methods: GET
meeting_show:
path: /show
defaults: { _controller: "SocialProMeetingBundle:Meeting:show" }
methods: [GET, POST]
meeting_new:
path: /new
defaults: { _controller: "SocialProMeetingBundle:Meeting:new" }
methods: [GET, POST]
meeting_edit:
path: /{id}/edit
defaults: { _controller: "SocialProMeetingBundle:Meeting:edit" }
methods: [GET, POST]
meeting_delete:
path: /{id}/delete
defaults: { _controller: "SocialProMeetingBundle:Meeting:delete" }
methods: DELETE
One problem is in your function newAction where you are passing in a meeting parameter and the route doesn't handle it. This code:
return $this->redirectToRoute('meeting_new', array(
'meeting' => $meeting
));
Your route needs to handle the parameter like so:
meeting_new:
path: /new/{meeting}
defaults: { _controller: "SocialProMeetingBundle:Meeting:new" }
methods: [GET, POST]

Symfony - how to add embed Forms?

I am trying to create a form Houses and embed the Images forms into it. I have follow the tutorial http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms.
I have the following schema:
houses:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
description: { type: string(5000), notnull: true }
images:
actAs: { Timestampable: ~ }
columns:
url: { type: string(255), notnull: true }
id_house: { type: integer, notnull: true }
relations:
houses: { local: id_house, foreign: id, foreignAlias: HousesImg}
and the code :
//lib/form/doctrine/ImagesCollectionForm
class ImagesCollectionForm extends sfForm
{
public function configure()
{
if(!$house= $this->getOption('house'))
{
throw new InvalidArgumentException('You must provide an house');
}
for ($i = 0; $i < $this->getOption('size',2); $i++)
{
$images = new images();
$images->house = $house;
$form = new imagesForm($images);
$this->embedForm($i, $form);
}
}
}
//lib/form/doctrine/housesForm.class.php
public function configure()
{
$form = new ImagesCollectionForm(null, array('house' => $this->getObject(),'size'=>2));
$this->embedForm('images', $form);
}
The fields are displayed as expected. But, when I press the save button I get a blank page and the data aren't saved in database.
use have not specified alias in Images relation with product
so by default symfony look it for relation name
so u need to change $images->house = $house; to $images->houses = $house;
or u can set alias in relation
hope this will help.