Score:0

Form tries to process submit field as entity property

fk flag

I want to create a simple admin CRUD form. I am using the default form.

class TestForm extends EntityForm {

  public function form(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;
    $form['name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Name'),
      '#default_value' => $entity->get('name')->getString(),
      '#size' => 30,
      '#required' => TRUE,
      '#maxlength' => 64
    ];
    
    $form['description'] = [
      '#type' => 'textfield',
      '#default_value' => $entity->get('description')->getString(),
      '#required' => FALSE
    ];
    
    return parent::form($form, $form_state);
  }

}

It renders just fine, but when I click on the Save button, I get the following error.

InvalidArgumentException: Field submit is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 587 of core/lib/Drupal/Core/Entity/ContentEntityBase.php). Drupal\Core\Entity\ContentEntityBase->get('submit') (Line: 628)
Drupal\Core\Entity\ContentEntityBase->set('submit', Object) (Line: 331)

It looks like Drupal is trying to process the "submit" field as the entity property. Obviously, I do not have such property, but I do not understand why this happens. I do not have any additional form processing, hooks or anything else. I do not work with the submit button at all.

guest avatar
fk flag
I need to extend from ContentEntityForm instead of EntityForm, then it works. Curious what needs to be added.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.