Skip to content
Snippets Groups Projects
Commit 02d7f6db authored by Oleh Shevchuk's avatar Oleh Shevchuk
Browse files

Added the option to not open the default creation form for the required field

parent 6e491f65
No related branches found
No related tags found
2 merge requests!99Closes #3359875,!39Issue #3260881: Automatically open entity creation form.
......@@ -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"
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment