<?php
namespace Drupal\my_custom_module\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class DefaultForm.
*/
class DefaultForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'default_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['test'] = [
'#type' => 'textfield',
'#title' => $this->t('Test'),
'#maxlength' => 64,
'#size' => 64,
'#weight' => '0',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
$form_state->setErrorByName('test', 'error');
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state->setErrorByName('test', 'error');
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRebuild(TRUE);
}
}
When using setError
, setErrorByName
or setRebuild
methods, wether it be in validateForm or submitForm, it breaks my form by giving me a Allowed memory size of XXX bytes exhausted error when I submit the form.
Problem is, I don't see anything in the logs except thousands of "404" errors, as if I've something that trigger an infinite loop.
In the example, I have both setErrorByName
and setRebuild
, but it happens even with only one of them.
Can you think of anything that can trigger this error ?