0

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.

1
  • I need to extend from ContentEntityForm instead of EntityForm, then it works. Curious what needs to be added.
    – guest
    Feb 11 at 22:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.