Skip to content

Instantly share code, notes, and snippets.

@slattery
Created February 6, 2025 15:52
Show Gist options
  • Save slattery/c4f2625300b0a4a39d154f4e2f0145e2 to your computer and use it in GitHub Desktop.
Save slattery/c4f2625300b0a4a39d154f4e2f0145e2 to your computer and use it in GitHub Desktop.
Inline_entity_form_save_entity_rc17.patch
diff --git a/config/schema/inline_entity_form.schema.yml b/config/schema/inline_entity_form.schema.yml
index 2d7a8f2..d1b22fb 100644
--- a/config/schema/inline_entity_form.schema.yml
+++ b/config/schema/inline_entity_form.schema.yml
@@ -34,6 +34,9 @@ field.widget.settings.inline_entity_form_simple:
revision:
type: boolean
label: "Create new revision"
+ save_entity:
+ type: boolean
+ label: "Save entity"
removed_reference:
type: string
label: "Keep or delete unreferenced items"
@@ -75,6 +78,9 @@ field.widget.settings.inline_entity_form_complex:
revision:
type: boolean
label: "Create new revision"
+ save_entity:
+ type: boolean
+ label: "Save entity"
removed_reference:
type: string
label: "Keep or delete unreferenced items"
diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php b/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php
index 450fcd9..b703913 100644
--- a/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php
+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php
@@ -217,6 +217,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
return [
'form_mode' => 'default',
'revision' => FALSE,
+ 'save_entity' => FALSE,
'override_labels' => FALSE,
'label_singular' => '',
'label_plural' => '',
@@ -244,6 +245,11 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
'#title' => $this->t('Create new revision'),
'#default_value' => $this->getSetting('revision'),
];
+ $element['save_entity'] = [
+ '#type' => 'checkbox',
+ '#title' => $this->t('Save inline entities as soon as the \'Update\' button is pressed.'),
+ '#default_value' => $this->getSetting('save_entity'),
+ ];
$element['override_labels'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override labels'),
@@ -317,6 +323,13 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
$summary[] = $this->t('Create new revision');
}
+ if ($this->getSetting('save_entity')) {
+ $summary[] = $this->t('Changes will be saved immediately upon submit of the inline form.');
+ }
+ else {
+ $summary[] = $this->t('Inline changes will not be saved until containing form is submitted.');
+ }
+
if ($this->getSetting('collapsible')) {
$summary[] = $this->getSetting('collapsed') ? $this->t('Collapsible, collapsed by default') : $this->t('Collapsible');
}
@@ -434,7 +447,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
'#op' => $operation,
'#form_mode' => $this->getSetting('form_mode'),
'#revision' => $this->getSetting('revision'),
- '#save_entity' => FALSE,
+ '#save_entity' => $this->getSetting('save_entity'),
'#ief_row_delta' => $delta,
// Used by Field API and controller methods to find the relevant
// values in $form_state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment