Drupal 8.6来自控制器中的实体的表格

I'm trying to create the form from Entity in the controller.

This is the code of controller:

class OutOfOfficeController extends ControllerBase
{
    /**
     * @return array
     */
    public function add()
    {
        $event = $this->entityTypeManager()->getStorage('event')->create(['type' => 'out_of_office']);
        $form  = $this->entityFormBuilder()->getForm($event);
        return $form;
    }
}

And this is the error which I get:

Error: Call to a member function getTranslationFromContext() on null in Drupal\Core\Entity\ContentEntityForm->initFormLangcodes() (line 313 of core/lib/Drupal/Core/Entity/ContentEntityForm.php).

  • It seems that the ContentEntityForm do not have any dependencies
  • In ContentEntityForm the $this->entityRepository returns null.

Am I missing something?

There was a problem with Event entity itself.

The Event entity was referring to EventForm, which had a constructor which overrides the ContentEntityForm. The problem is fixed when __constructor was removed from EventForm