Problem/Motivation

inline_entity_form_reference_form ("Use existing" entity functionality) uses a textfield for autocomplete. I think we can refactor this part and use the new autocomplete element from core.

Core change record for more info: http://drupal.org/node/2418529.

Proposed resolution

Replace textfield for autocomplete in "Use existing" part of IEF.

To get to the field we're changing here:
- Create entity reference field on any node type
- Go to "Manage form display" page
- Find newly created field
- Use "Inline entity form complex" widget
- Configure IEF complex to allow referencing existing entities
- Navigate to node add page for this type
- Click "Add existing" button
- Autocomplete field appears

Comments

woprrr’s picture

Status: Active » Needs work

Okay I go look this. @see https://www.drupal.org/node/2418529

slashrsm’s picture

Issue tags: +Media Initiative, +sprint
slashrsm’s picture

Issue tags: -sprint +D8Media
bojanz’s picture

Status: Needs work » Active

There's no patch here.

woprrr’s picture

Its true ! yersterday i propose a patch promise ;)

slashrsm’s picture

Issue summary: View changes
thenchev’s picture

Status: Active » Needs review
StatusFileSize
new6.54 KB

Here is first patch.

bojanz’s picture

+
+  $target = $instance->getConfigTarget();
+  $settings = $instance->getSettings();
+  $settings2 = entity_get_form_display('node', 'page', 'default')
+    ->getComponent('field_reference')['settings'];
+  $targetType = $instance->getSetting('target_type');
+  $targetBundle = $instance->getSetting('handler_settings')['target_bundles'];
+

- You are adding an extra newline.
- Variables must be snake_case, not camelCase. So $target_type, not $targetType
- You can't name a variable $settings2 :) Maybe go with $instance_settings and $widget_settings.

thenchev’s picture

Status: Needs review » Needs work

Oh actually that was some debugging code :/ missed that this morning will make a fix quick

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new6.08 KB
new934 bytes

Should look better now.

bojanz’s picture

Thanks! This looks almost ready to go.

+    '#selection_settings' => ['target_bundles' => $instance->getSetting('handler_settings')['target_bundles']],

We need to confirm this behaves properly for the "all bundles allowed" use case.

The selection handler that receives these settings has the following comment:

      // For the 'target_bundles' setting, a NULL value is equivalent to "allow
      // entities from any bundle to be referenced" and an empty array value is
      // equivalent to "no entities from any bundle can be referenced".

The test would be to create an entity reference field with no bundles selected, test IEF with this patch to confirm the autocomplete still works.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Thank you!

slashrsm’s picture

Status: Reviewed & tested by the community » Needs work

:)

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new6.54 KB
new12.62 KB

Created a separate content type for test, if that's overkill i can maybe work on adding the field to the already available content types.

The last submitted patch, 10: use_autocomplete-2490914-10.patch, failed testing.

thenchev’s picture

StatusFileSize
new10.84 KB
new13.06 KB

Status: Needs review » Needs work

The last submitted patch, 16: use_autocomplete-2490914-16.patch, failed testing.

The last submitted patch, 16: use_autocomplete-2490914-16.patch, failed testing.

The last submitted patch, 16: use_autocomplete-2490914-16.patch, failed testing.

The last submitted patch, 16: use_autocomplete-2490914-16.patch, failed testing.

The last submitted patch, 16: use_autocomplete-2490914-16.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new16.9 KB
new4.77 KB

So didn't go over other tests before. Now targets the right button and changed my added field to not be required or i would had to made more changes and additions.

slashrsm’s picture

Status: Needs review » Needs work
+++ b/src/Tests/InlineEntityFormComplexWebTest.php
@@ -293,6 +299,16 @@ class InlineEntityFormComplexWebTest extends WebTestBase {
+    // Add all remaining nodes from all bundles.
+    for ($i = key($bundle_nodes) + 1; $i < count($bundle_nodes) + key($bundle_nodes); $i++) {
+      $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @value="Add existing node" and @data-drupal-selector="edit-all-bundles-actions-ief-add-existing"]'));
+      $this->assertResponse(200, 'Opening reference form was successful.');

This for loop assumes NIDs increment by 1. Since this is usually the case we can't assume it will always be so.

This test will fail in environment where database will be configured to use different PK increment step.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new16.95 KB
new2.47 KB

Addressed #23.

slashrsm’s picture

Status: Needs review » Fixed

Committed. Thank you.

  • slashrsm committed a8ea328 on 8.x-1.x authored by Denchev
    Issue #2490914 by Denchev: Use autocomplete element for autocomplete...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.