-2

Whenever i use classname extends FormBase the clear cache crashes and whenever i remove it it works again.


<?php

namespace Drupal\API_crud\Form;


use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class ApiCrud extends FormBase {
    public function getFormId() {
        return 'api_form';
    }

    public function buidForm(array $form, FormStateInterface $form_state) {
        $form['title'] = [
            '#type' => 'textfield',
            '#title' => $this->t('API: '),
            '#required' => TRUE,
        ];
        $form['actions'] = [
            '#type' => 'actions',
        ];
        $form['actions']['submit'] = [
            '#type' => 'submit',
            '#value' => $this->t('Submit'),
        ];
        return $form;
    }

}

apiAuth.form:
  path: '/apiAuth'
  defaults:
    _form: '\Drupal\API_crud\Form\ApiCrud'
    # _controller: '\Drupal\API_crud\Controller\apiCrudController::Welcome'
    _title: 'API_Authentication'
  requirements:
    _permission: 'access content'



enter image description here

2
  • See drupal.stackexchange.com/questions/127182/…
    – 4uk4
    Commented Oct 4, 2022 at 9:39
  • 2
    It's worth investing time (and/or money) in learning to use a good IDE. VS code is a nice free one, PHPStorm is a nice paid one, for example. If you were using such an IDE it would have altered you to the fact your form class is missing methods from FormInterface, and you would've fixed it quickly.
    – Clive
    Commented Oct 4, 2022 at 9:47

1 Answer 1

2

As Clive is hinting in his comment some methods are missing in your class. You need to add at least the methods "buildForm" and "submitForm" to you class. (you also have a typo in buidForm)

This should work:

<?php

namespace Drupal\API_crud\Form;


use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class ApiCrud extends FormBase {
  public function getFormId() {
    return 'api_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['title'] = [
      '#type' => 'textfield',
      '#title' => $this->t('API: '),
      '#required' => TRUE,
    ];
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
    ];
    return $form;
  }

  public function submitForm(array &$form, FormStateInterface $form_state) {
    // TODO: Implement submitForm() method.
  }

}

Not the answer you're looking for? Browse other questions tagged or ask your own question.