Notice: Undefined index: field in realname_field_widget_form_alter() (line 448 of D:\Webserver\drupal\modules\realname\realname.module).

CommentFileSizeAuthor
#28 emptyrecords-before-after-autocomplete.png26.92 KBramreddy.kancherla
#26 empty-result.png17.13 KBramreddy.kancherla
#25 support_for_autocomplete--2705279-25.patch5 KBRonald van Belzen
#18 support_for_autocomplete--2705279-18.patch4.66 KBRonald van Belzen
#13 support_for-2705279-13.patch17.64 KB7thkey
#8 support_for-2705279-8.patch24.73 KBgokulnk
#7 support_for-2705279-6.patch11.31 KBgrahl
#3 support_for_autocomplete--2705279-3.patch9.64 KBgrahl
#2 notice_undefined-2705279-2.patch1.09 KBgrahl
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ronald van Belzen created an issue. See original summary.

grahl’s picture

Status: Active » Needs work
FileSize
1.09 KB

The attached patch is a band-aid to get rid of the error message. Entity reference has been moved into core and this hook needs to be rewritten to support the autocomplete handler correctly.

grahl’s picture

Title: Notice: Undefined index: field in realname_field_widget_form_alter() » Support for autocomplete widget in D8
Status: Needs work » Needs review
FileSize
9.64 KB

As far as I can tell, the code regarding the form widget was still as in D7 and attached is a port of it. Since I am not sure that it is even possible to robustly override hook_widget_form_alter() as happened in D7 I chose to write a separate widget. If someone wants to try to make that work that's fine by me but the attached solution works fine for me at least.

If the RealNameController will be committed to the project I'm willing to provide unit tests for it.

hass’s picture

Great, but what about:

Autocomplete matching

  • Starts with
  • Contains
hass’s picture

Status: Needs review » Needs work

A configured match operator "Contains" is not working.

hass’s picture

Priority: Minor » Major

This patch confuses me a lot. EntityReferenceAutocompleteWidget.php is completly different and I guess this may not work properly in all cases.

$element += array(
      '#type' => 'entity_autocomplete',
      '#target_type' => $this->getFieldSetting('target_type'),
      '#selection_handler' => $this->getFieldSetting('handler'),
      '#selection_settings' => $this->getFieldSetting('handler_settings'),
      // Entity reference field items are handling validation themselves via
      // the 'ValidReference' constraint.
      '#validate_reference' => FALSE,
      '#maxlength' => 1024,
      '#default_value' => isset($referenced_entities[$delta]) ? $referenced_entities[$delta] : NULL,
      '#size' => $this->getSetting('size'),
      '#placeholder' => $this->getSetting('placeholder'),
    );

you changed the type, maxlength and other stuff.

grahl’s picture

Hi

Due to another module I couldn't work on this anymore. The comment you are referring to is a left-over, entity_autocomplete isn't used in that variant, I just used it as a starting point.

That being said, there is a bug in the loader for it. You can find and save users but editing the page with that again will cause an error.

To solve this more generally I started extending entity_autocomplete again but haven't gotten very far. I've attached that work-in-progess but that isn't nearly done, I just won't have the time to work on this as much as I'd like this month.

gokulnk’s picture

Combined both the patches and rerolled it as the patch was not applying to the latest head.

With this patch I am getting the following error.

Uncaught PHP Exception Symfony\\Component\\Routing\\Exception\\InvalidParameterException: "Parameter "bundle_type" for route "realname.real_name_controller_autocomplete" must match "[^/]++" ("" given) to generate a corresponding URL." at /core/lib/Drupal/Core/Routing/UrlGenerator.php line 199,

gokulnk’s picture

Any update on this? Currently I think this is the major issue that is holding back the adoption of this module in Drupal8. If this is fixed the module should be good for an alpha release.

Christopher Riley’s picture

Patch works great for me even patching via composer.

hass’s picture

#4, 5, 6, 8 look not like a committable patch.

Christopher Riley’s picture

Patch no longer applies to the latest version and error is back.

7thkey’s picture

Updated and cleaned #9 patch. No errors but still needs work.
When i start fillin into "Authored by" the full name the autocomplete does not work at all. The autocomplete list shows the Full Name but the search does not match by "Full Name".

hass’s picture

Status: Needs work » Needs review

The last submitted patch, 7: support_for-2705279-6.patch, failed testing.

The last submitted patch, 8: support_for-2705279-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 13: support_for-2705279-13.patch, failed testing.

Ronald van Belzen’s picture

Maybe this approach is viable.

hass’s picture

Status: Needs review » Needs work
+++ b/src/Controller/AutocompleteController.php
@@ -0,0 +1,75 @@
+      $matches = $this->getMatched($typed_string);

Why is this not using EntityAutocompleteMatcher? The getMatches() shows how to implement the match param CONTAINS or start with.

+++ b/src/Controller/AutocompleteController.php
@@ -0,0 +1,75 @@
+      $query->condition('r.realname', '%' . $connection->escapeLike($string) . '%', 'LIKE');

This is a CONTAINS only. In D7 we also had "START WITH".

  • Has this tested with Entity References?
  • I'm wondering how the patch can go down from 25KB to 5KB...
Ronald van Belzen’s picture

The data in the db table realname is not represented by a ContentEntity (yet). This prevents the use of the EntityAutocompleteMatcher to retrieve the data. Maybe creating a ContentEntity for Realname is a good idea?

In the patch 18 the query contains a unnecessary join for that solution, btw.

I will make a patch that makes the CONTAINS and START WITH distinction.

  • hass committed 3149b73 on 8.x-1.x authored by Ronald van Belzen
    Issue #2705279 by grahl, Ronald van Belzen, gokulnk, 7thkey: Support for...
hass’s picture

@Ronald: I worked on your patch and implemented the missing START WITH. As it works fine, I just committed it. If you know how to implement this ContentEntity I'm happy to see your patch to move this forward. Let's move this to a follow up case.

hass’s picture

Status: Needs work » Fixed

Thanks all for the hard work.

Ronald van Belzen’s picture

Just for reference the improvement I talked about in #21.

ramreddy.kancherla’s picture

Status: Fixed » Active
FileSize
17.13 KB

I tested both dev and beta1 modules, When user's realname token values are empty, getting empty result in autocomplete widget.

hass’s picture

Status: Active » Fixed

Not sure how this is possible with #2874168: Empty realname bubble into site

ramreddy.kancherla’s picture

Thank you for the quick response @hass.
Getting empty realname in autocomplete widget.
I followed these steps.
1) Installed latest dev module.
2) In realname configuration page, I changed token values. For this token some users have values and some users do not have any value.
3) In node add page, at Author Information section, I searched for the users using auto complete and getting empty result along with realname values.
Strange thing is before performing autocomplete in node add/edit page, realname table has values for users who have token value and after searching for users in autocomplete widget in the table there are empty records for users.

hass’s picture

Please post your realname token string in code tags in the referenced case.

ramreddy.kancherla’s picture

Here is token [user:field_first_name] [user:field_last_name].
I created two text fields in the /admin/config/people/accounts/fields with "field_first_name", "field_last_name" machine names.

hass’s picture

Can you post this to #2874168: Empty realname bubble into site please!!! It has nothing to do with the issue here.

Status: Fixed » Closed (fixed)

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