diff --git a/config/schema/inline_entity_form.schema.yml b/config/schema/inline_entity_form.schema.yml index b962119ea2482055cfa6f80fe97fc47dd2f1b3a7..78ddce0e30a8a57f52a6b670d53808d99eaacd3d 100644 --- a/config/schema/inline_entity_form.schema.yml +++ b/config/schema/inline_entity_form.schema.yml @@ -51,6 +51,9 @@ field.widget.settings.inline_entity_form_complex: label_plural: type: label label: "Label (plural)" + auto_open: + type: boolean + label: "Automatically open entity creation form" allow_new: type: boolean label: "Allow new" diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php index 12cff2c117c0ac558617c78c133dea624b16b135..74ca1d7fffd4c81ed20c1de17d637c8490d29603 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php @@ -105,6 +105,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF 'allow_existing' => FALSE, 'match_operator' => 'CONTAINS', 'allow_duplicate' => FALSE, + 'auto_open' => TRUE, ]; return $defaults; @@ -118,6 +119,13 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $labels = $this->getEntityTypeLabels(); $states_prefix = 'fields[' . $this->fieldDefinition->getName() . '][settings_edit_form][settings]'; + if ($this->fieldDefinition->isRequired()) { + $element['auto_open'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Automatically open entity creation form'), + '#default_value' => $this->getSetting('auto_open'), + ]; + } $element['allow_new'] = [ '#type' => 'checkbox', '#title' => $this->t('Allow users to add new @label.', ['@label' => $labels['plural']]), @@ -181,6 +189,10 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $summary[] = $this->t('@label can not be duplicated.', ['@label' => $labels['plural']]); } + if ($this->getSetting('auto_open') && $this->fieldDefinition->isRequired()) { + $summary[] = $this->t('Automatically open creation form'); + } + return $summary; } @@ -439,7 +451,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $allow_new = $settings['allow_new'] && !empty($create_bundles); $hide_cancel = FALSE; // If the field is required and empty try to open one of the forms. - if (empty($entities) && $this->fieldDefinition->isRequired()) { + if (empty($entities) && $this->getSetting('auto_open') && $this->fieldDefinition->isRequired()) { if ($settings['allow_existing'] && !$allow_new) { $form_state->set(['inline_entity_form', $this->getIefId(), 'form'], 'ief_add_existing'); $hide_cancel = TRUE;