You are here

protected function InlineEntityFormBase::makeIefId in Inline Entity Form 8

Makes an IEF ID from array parents.

IEF ID is used a) for element ID, b) for form state keys. We need the IEF form ID to reflect the tree structure of IEFs, so that the form state keys can be sorted to ensure inside-out saving of entities.

Also, "add" and "edit" IEFs have different array parents, which messes up form state, so we fixup this here with a, errrm, pragmatic hack.

Parameters

string[] $parents: The array parents.

Return value

string The resulting inline entity form ID.

See also

\Drupal\inline_entity_form\WidgetSubmit::doSubmit

4 calls to InlineEntityFormBase::makeIefId()
InlineEntityFormComplex::extractFormValues in src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
Extracts field values from submitted form values.
InlineEntityFormComplex::formElement in src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
Returns the form for a single field widget.
InlineEntityFormSimple::extractFormValues in src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php
Extracts field values from submitted form values.
InlineEntityFormSimple::formElement in src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/InlineEntityFormBase.php, line 167

Class

InlineEntityFormBase
Inline entity form widget base class.

Namespace

Drupal\inline_entity_form\Plugin\Field\FieldWidget

Code

protected function makeIefId(array $parents) {
  $iefId = implode('-', $parents);
  $iefId = preg_replace('#-inline_entity_form-entities-([0-9]+)-form-#', '-$1-', $iefId);
  return $iefId;
}