You are here

function inline_entity_form_open_form in Inline Entity Form 8

Same name and namespace in other branches
  1. 7 inline_entity_form.module \inline_entity_form_open_form()

Button #submit callback: Opens a form in the IEF widget.

The form is shown below the entity table, at the bottom of the widget.

Parameters

$form: The complete parent form.

$form_state: The form state of the parent form.

1 string reference to 'inline_entity_form_open_form'
InlineEntityFormComplex::formElement in src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
Returns the form for a single field widget.

File

./inline_entity_form.module, line 206
Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (for example, order -> line items), where the child entities are never managed outside the…

Code

function inline_entity_form_open_form($form, FormStateInterface $form_state) {
  $element = inline_entity_form_get_element($form, $form_state);
  $ief_id = $element['#ief_id'];
  $form_state
    ->setRebuild();

  // Get the current form values.
  $parents = array_merge($element['#field_parents'], [
    $element['#field_name'],
  ]);
  $form_values = NestedArray::getValue($form_state
    ->getUserInput(), $parents);
  $triggering_element = $form_state
    ->getTriggeringElement();
  $form_state
    ->set([
    'inline_entity_form',
    $ief_id,
    'form',
  ], $triggering_element['#ief_form']);
  if (!empty($form_values['actions']['bundle'])) {
    $form_state
      ->set([
      'inline_entity_form',
      $ief_id,
      'form settings',
    ], [
      'bundle' => $form_values['actions']['bundle'],
    ]);
  }
}