How to use inline_entity_form in Drupal 8? I am building 2 custom Content entity types: one is a Node type representing a type of food, called "food". This food may have multiple varieties, which will differ with regards to specific details, so I wish to store information about the varieties in a separate database table, and to accomplish this I have defined a second entity type called "food_type" which serves to provide additional information related to the "food" node.

Within the Food form, I want to also fill out all the fields for the related food_type. I am trying to accomplish this using inline_entity_form.

Following the documentation, I have done the following things for food_type:


Added a dependency of inline_entity_form in food_type.info.yml (there are no other dependencies)
Created food_type/src/Controller/FoodTypeInlineEntityFormController.php, which contains the following code:

namespace Drupal\food_type\Controller;

/**
 * Controller routines for Food Type pages.
 */
class FoodTypeInlineEntityFormController extends EntityInlineEntityFormController {

 /**
   * Overrides EntityInlineEntityFormController::entityForm().
   */
  public function entityForm($entity_form, &amp;$form_state) {

    return parent::entityForm($entity_form, $form_state);
  }
}

Added the following code to food_type_install() in food_type.install:

$entity_info['food_type']['inline entity form'] = array(
    'controller' =&gt; 'FoodTypeInlineEntityFormController',
);

Defined '\Drupal\food_type\Controller\FoodTypeInlineEntityFormController::entityForm' as the _controller default under entity.food_type.form in food_type.routing.yml


I cannot enable the food_type module. Attempting to do so yields the following error:


  Fatal error: Class 'Drupal\food_type\Controller\EntityInlineEntityFormController' not found in {directory}\sites\all\modules\custom\food_type\src\Controller\FoodTypeInlineEntityFormController.php on line 9


I assume this is caused because I do not include a use statement in FoodTypeInlineEntityFormController.php for EntityInlineEntityFormController. From Googling, it seems that such a statement is not used in example code that uses this module at all, and it's supposed to simply work when the inline_entity_form module is enabled. However, I for sure have inline_entity_form enabled and am still getting this error.

I would like to try a use statement, but the EntityInlineEntityFormController class does not seem to exist at all in the module code, as far as I can tell from searching. I am using 8.x-1.0-alpha6.

I am very new to drupal development and believe I am probably doing something else wrong, but I am completely at a loss here as to how to proceed or troubleshoot. Can anyone please help me or point me in the right direction?

Thank you in advance.
In order to implement Inline Entity form in D8, all you need to do is set your entity reference field to use the IEF widget - simple or complex. That is all. No additional work.

Here is how we set it up in Drupal Commerce for products, programmatically.

$form_display = commerce_get_entity_display('commerce_product', $product_type-&gt;id(), 'form');
$form_display-&gt;setComponent('variations', [
  'type' =&gt; 'inline_entity_form_complex',
  'weight' =&gt; 10,
  'settings' =&gt; [
    'override_labels' =&gt; TRUE,
    'label_singular' =&gt; 'variation',
    'label_plural' =&gt; 'variations',
  ],
]);
$form_display-&gt;save();


This tells the variations field, which is a Product Variation entity reference, to use IEF as the way to manage field values.