Support Inline Entity Form

Created on 21 July 2020, over 4 years ago
Updated 16 August 2024, 3 months ago

It would be good to support for Inline Entity Forms similar to how the Field Group module does it.

hook_inline_entity_form_entity_form_alter() seems to be fired after hook_form_alter().

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia imclean Tasmania

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.

  • πŸ‡©πŸ‡ͺGermany donquixote

    For me this is not working correctly yet.
    If I use the "simple" widget from inline entity form, for a required single-value reference, then the value is lost when I navigate to a new step.

  • πŸ‡΅πŸ‡°Pakistan sajideen

    It's not working in the inline entity form simple widget. If I navigate to a new step, the previous step's form_state values are lost.

  • Assigned to sajideen
  • πŸ‡΅πŸ‡°Pakistan sajideen

    If We use the "simple" widget from inline entity form, for a required single-value reference, then the value is lost when we navigate to a new step.
    we can achieve this issue if we use tempstore.

    Set form state values in tempstore like:

    $entity = $entity_form->getEntity();
    if( $entity ) {
    $entity_type_id = $entity->getEntityTypeId();
    $entity_type_id = $entity_type_id."_data";
    $value = $form_state->getValues();
    $tempstore = \Drupal::service('tempstore.private')->get('simple_multistep');
    $tempstore->set($entity_type_id, $value);
    }

    and then use inline entity form alter to set the form state values.
    $tempstore = \Drupal::service('tempstore.private')->get('simple_multistep');
    $stored_data = $tempstore->get($entity_type);
    // Get the entity field manager service.
    $entity_field_manager = \Drupal::service('entity_field.manager');
    // Get the field definitions for the entity type.
    $fields = $entity_field_manager->getFieldDefinitions($entity_form['#entity_type'], NULL);
    // Process the fields as needed.
    foreach ($fields as $field_name => $field_definition) {
    // Check if the field is an inline entity form field.
    if (isset($stored_data[$field_name][0]["inline_entity_form"])) {
    $field_data = $stored_data[$field_name][0]["inline_entity_form"];
    if (!empty($field_data)) {
    foreach ($field_data as $delta => $field_values) {
    // Set default values for the field.
    if (isset($entity_form[$field_name][$delta]['widget'][0]['value'])) {
    $entity_form[$field_name][$delta]['widget'][0]['value']['#default_value'] = isset($field_values[0]['value']) ? $field_values[0]['value'] : NULL;
    }
    }
    }
    }
    }

  • πŸ‡ΊπŸ‡ΈUnited States jvogt Seattle, WA

    #14 did not work for me with version 2.0.2. However, I'm also using a Workflow and the workflow_buttons module, so that may have something to do with it.

    I was able to make everything work just by adding the IEF-related elements from the main submit button ($form['actions']['submit']) to the Next button definition in FormButton.php. I can't guarantee that this is the right way to fix it, but patch is attached if others want to test.

      private function showNextButton(array &$form) {
        $step_format_settings = $this->stepSettings->format_settings;
    
        if (count($this->steps) - 1 !== $this->currentStep) {
          $form['actions']['next'] = [
            '#limit_validation_errors' => [],
            '#type' => 'submit',
            '#value' => $step_format_settings['next_button_text'],
            // Change the #submit to this.
            '#submit' => [
              ['\Drupal\inline_entity_form\ElementSubmit', 'trigger'],
              'simple_multistep_register_next_step',
            ],
            '#weight' => 0.1,
            // Add the following two lines.
            '#ief_submit_trigger' => TRUE,
            '#ief_submit_trigger_all' => TRUE,
          ];
          $form['actions']['submit']['#access'] = FALSE;
        }
      }
    
Production build 0.71.5 2024