You are here

protected function InlineEntityFormComplex::determineBundle in Inline Entity Form 8

Determines bundle to be used when creating entity.

@TODO - Figure out if can be simplified.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: Current form state.

Return value

string Bundle machine name.

1 call to InlineEntityFormComplex::determineBundle()
InlineEntityFormComplex::formElement in src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php, line 910

Class

InlineEntityFormComplex
Complex inline widget.

Namespace

Drupal\inline_entity_form\Plugin\Field\FieldWidget

Code

protected function determineBundle(FormStateInterface $form_state) {
  $ief_settings = $form_state
    ->get([
    'inline_entity_form',
    $this
      ->getIefId(),
  ]);
  if (!empty($ief_settings['form settings']['bundle'])) {
    return $ief_settings['form settings']['bundle'];
  }
  elseif (!empty($ief_settings['bundle'])) {
    return $ief_settings['bundle'];
  }
  else {
    $target_bundles = $this
      ->getTargetBundles();
    return reset($target_bundles);
  }
}