Change record status: 
Project: 
Introduced in branch: 
8.x-2.x
Introduced in version: 
8.x-2.12
Description: 

Commerce sites have previously used the inline_entity_form element to embed an entity form into another form.
This can now be done in a nicer way, without the Inline Entity Form dependency, using the content_entity inline form.

Example for buildForm():

// Load or create the $entity that you want to edit. Then create an inline form and pass it.
// The second parameter is $configuration, and can contain "skip_save" and "form_mode" settings.
$inline_form = $this->inlineFormManager->createInstance('content_entity', [], $entity);
 
$form['entity'] = [
  '#parents' => ['entity'],
  '#inline_form' => $inline_form,
];
$element['entity'] = $inline_form->buildInlineForm($element['entity'], $form_state);

You can access the entity in validateForm() or submitForm() this way:

/** @var \Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface $inline_form */
$inline_form = $form['entity']['#inline_form'];
$entity = $value = $inline_form->getEntity();

Note that the entity will be automatically saved for you, unless "skip_save" => TRUE is passed to the inline form configuration.

Impacts: 
Module developers