Make prepopulating entities easier

Created on 9 September 2018, about 6 years ago
Updated 17 February 2024, 10 months ago

I'd like to refer to #2855769: Prepopulate entity in D8 β†’ which shows a way to prepopulate entities through a form alter. The conclusion of the issue was the following:

There's definitely room for improvement, so perhaps a separate feature request is due.

This is that separate issue :-) I'm willing to provide a patch for this, but first would like to know the direction we should go at.

In Drupal\inline_entity_form\Element\InlineEntityForm::processEntityForm() there's the following piece of code:

// This is an add operation, create a new entity.
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_form['#entity_type']);
$storage = \Drupal::entityTypeManager()->getStorage($entity_form['#entity_type']);
$values = [];
if ($langcode_key = $entity_type->getKey('langcode')) {
  if (!empty($entity_form['#langcode'])) {
    $values[$langcode_key] = $entity_form['#langcode'];
  }
}
if ($bundle_key = $entity_type->getKey('bundle')) {
  $values[$bundle_key] = $entity_form['#bundle'];
}
$entity_form['#entity'] = $storage->create($values);

Allowing modules to alter the $values array right before passing it to the entity storage handler looks to me like an elegant solution? The alter hook would provide some context, for example the $form_state and $complete_form.

✨ Feature request
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium rp7

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dcam

    Due to limited developer time old feature requests for IEF are being closed. If you still have a need for this functionality, then you may feel free to reopen the issue.

Production build 0.71.5 2024