From 7218f544f5cccc269421a0db7514df4e1139c85c Mon Sep 17 00:00:00 2001 From: Bharath Kondeti <bharath122334@gmail.com> Date: Thu, 11 May 2023 18:36:36 +0530 Subject: [PATCH] Updated the patch changes for 2.0.x branch --- config/schema/inline_entity_form.schema.yml | 3 +++ .../Field/FieldWidget/InlineEntityFormComplex.php | 8 +++++++- tests/src/FunctionalJavascript/ComplexWidgetTest.php | 10 ++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config/schema/inline_entity_form.schema.yml b/config/schema/inline_entity_form.schema.yml index a54733d4..43b5d652 100644 --- a/config/schema/inline_entity_form.schema.yml +++ b/config/schema/inline_entity_form.schema.yml @@ -69,6 +69,9 @@ field.widget.settings.inline_entity_form_complex: allow_existing: type: boolean label: "Allow existing" + allow_edit: + type: boolean + label: "Allow edit" match_operator: type: string label: "Match operator" diff --git a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php index 229cef73..57a0ae1e 100644 --- a/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php +++ b/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php @@ -119,6 +119,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF $defaults += [ 'allow_new' => TRUE, 'allow_existing' => FALSE, + 'allow_edit' => TRUE, 'removed_reference' => self::REMOVED_OPTIONAL, 'match_operator' => 'CONTAINS', 'allow_duplicate' => FALSE, @@ -153,6 +154,11 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF '#title' => $this->t('Allow users to add existing @label.', ['@label' => $labels['plural']]), '#default_value' => $this->getSetting('allow_existing'), ]; + $element['allow_edit'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Allow users to edit existing @label.', ['@label' => $labels['plural']]), + '#default_value' => $this->getSetting('allow_edit'), + ]; $element['match_operator'] = [ '#type' => 'select', '#title' => $this->t('Autocomplete matching'), @@ -465,7 +471,7 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF // Make sure entity_access is not checked for unsaved entities. $entity_id = $entity->id(); - if (empty($entity_id) || $entity->access('update')) { + if (empty($entity_id) || ($settings['allow_edit'] && $entity->access('update'))) { $row['actions']['ief_entity_edit'] = [ '#type' => 'submit', '#value' => $this->t('Edit'), diff --git a/tests/src/FunctionalJavascript/ComplexWidgetTest.php b/tests/src/FunctionalJavascript/ComplexWidgetTest.php index 0c1e173d..df6e4bf5 100644 --- a/tests/src/FunctionalJavascript/ComplexWidgetTest.php +++ b/tests/src/FunctionalJavascript/ComplexWidgetTest.php @@ -105,8 +105,9 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $assert_session->elementExists('xpath', $last_name_field_xpath); $assert_session->buttonExists('Create node'); - // Allow addition of existing nodes. + // Allow addition of existing nodes and disable edition. $this->updateSetting('allow_existing', TRUE); + $this->updateSetting('allow_edit', FALSE); // Asserts 'Add new node' form elements. $this->drupalGet($this->formContentAddUrl); @@ -355,7 +356,12 @@ class ComplexWidgetTest extends InlineEntityFormTestBase { $parent_node = $this->drupalGetNodeByTitle('Some title'); - // Edit the second entity. + // Unable to edit second entity, feature disabled. + $this->drupalGet('node/' . $parent_node->id() . '/edit'); + $assert_session->elementNotExists('xpath', '(//input[@value="Edit"])[2]'); + + // Edit the second entity once edit is enabled. + $this->updateSetting('allow_edit', TRUE); $this->drupalGet('node/' . $parent_node->id() . '/edit'); $assert_session->elementExists('xpath', '(//input[@value="Edit"])[2]')->press(); $this->assertNotEmpty($assert_session->waitForElement('xpath', $inner_title_field_xpath)); -- GitLab