I created a module with Drupal 8 beta11 which defines an content entity and a form (contentEntityForm) with custom submit callback.When I tried using the same module with Drupal 8 beta 14 it raise the following error.

Fatal error: Call to a member function extractFormValues() on null in C:\xampp\htdocs\drupalbeta14\core\lib\Drupal\Core\Entity\ContentEntityForm.php on line 219

Form definition are like this:

public function buildForm(array $form, FormStateInterface $form_state) {

        $form['employee']['first_name'] = array(
            '#type' => 'textfield',
            '#title' => 'First Name',
        '#required' => true,

     $form['employee']['last_name'] = array(
            '#type' => 'textfield',
            '#title' => 'Last Name',
        '#required' => true,

  $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
        '#name' => 'employee-data',
        '#submit' => array('::submitEmployeeData')

return $form
// callback

public function submitEmployeeData(array $form, FormStateInterface $form_state){
     /some code here

After form submission it raises the error mentioned above.

I checked the contentEntityForm.php also on both beta11 and beta 14 and seems to have similar function definition for extractFormValues() function.


This question is old but I stumbled across this issue as well, so posting the solution for future googlers..

Basically, you need to init the form_state within the buildForm method with:

if (!$form_state->has('entity_form_initialized')) {

I found this solution here: https://withpulp.com/blog/drupal-forms-api/#initialize-the-form-state

When extending the ContentEntityForm class the parent buildForm normally handles this for you, but if for some reason you choose not to extend the buildForm you will need to init the form_state yourself.

Your Answer

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

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