Problem/Motivation

On the field settings, when we select "Search Dialog" and we use "Views" instead of "Simple" (see screenshot) for the entity selection, the following warning/notice is shown:

Notice: Undefined index: type in references_dialog_entityreference_add_link() (Zeile 247 von /var/www/sites/all/modules/contrib/references_dialog/references_dialog.dialog_widgets.inc).
Warning: array_keys() expects parameter 1 to be array, null given in references_dialog_entityreference_add_link() (Zeile 250 von /var/www/sites/all/modules/contrib/references_dialog/references_dialog.dialog_widgets.inc).

Proposed resolution

The filter option has to be checked.

I will provide a patch for that.

Comments

weri’s picture

Status: Active » Needs review
StatusFileSize
new912 bytes
sgdev’s picture

Thank you for the patch... I can confirm this fixes the issue.

recrit’s picture

#1 patch fixes the notices, however, an field configured to use an un-filtered user view still does not get an add link.
The attach patch checks if any bundles were found after all the possible bundle determination logic.

marcopbazz’s picture

StatusFileSize
new417.3 KB

I try patch #3 with an entityreference field with bundle filtered by views. In my case I need to reference a taxonomy term for a specific vocabulary.

The add link appear for each vocabulary instead....

nishruu’s picture

I have the same problem as @MarcoPBazz. I think it's odd that we always check for the "type" bundle key, only because we are using the "view" mode. For example, taxonomy terms use "machine_name" instead of "type".
As we cannot be sure of the bundle key, we should look for the right one instead of retrieving all the bundles as the previous patch does.

Maybe I'm missing something because it's possible the code in "references_dialog_entityreference_views_query" is made for this ? If not, here is my patch.

Status: Needs review » Needs work

The last submitted patch, 5: references_dialog-check_filter_options-2317067-4-D7.patch, failed testing.

marcopbazz’s picture

@Nishruu I try your patch but it didn't work....Maybe i'm missing something with the view? i'ts a simple view filtered by vocabulary (i'm using latest dev version of this module and the latest stable release of entity reference).

nishruu’s picture

You should use a filter on "vocabulary : machine name".

nb : the patch failed testing probably because i'm on dev. I'll submit it for the stable later.

marcopbazz’s picture

Got it, i was filtering by taxonomy term vocabulary. Changing to vocabulary : machine name solved the problem, and now it works!

thank you so much

weri’s picture

@Nishruu: You have to cleanup your patch. The patch uses the full path of your local environment. Change all paths like the following:

a/core/sites/all/modules/contrib/references_dialog/references_dialog.dialog_widgets.inc

to

a/references_dialog.dialog_widgets.inc

nishruu’s picture

Thanks for the tip.

nishruu’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: references_dialog-check_filter_options-2317067-11-D7.patch, failed testing.

nishruu’s picture

Wrong patch again, sorry. I hope this time it's ok.

nishruu’s picture

Status: Needs work » Needs review

WorldFallz’s picture

Status: Fixed » Closed (fixed)

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

donquixote’s picture

Status: Closed (fixed) » Needs work

This introduced a bug.

"Notice: Undefined variable: views_filters in references_dialog_entityreference_add_link()"

function references_dialog_entityreference_add_link($element, $widget_settings, $field, $instance) {
  [..]
    if (isset($views_display[$display]->display_options['filters'][$bundle_key])) {
      $views_filters = $views_display[$display]->display_options['filters'][$bundle_key]['value'];
    }
    else if (!empty($views_display['default']->display_options['filters'][$bundle_key]['value'])) {
      $views_filters = $views_display['default']->display_options['filters'][$bundle_key]['value'];
    }

    $bundles = array_keys($views_filters);

There is no final else { case.
So it is no longer guaranteed that $views_filters is defined.

iamweird’s picture

StatusFileSize
new1.3 KB

It seems I've got #19 fixed by propagating to using all bundles if there are no bundle keys (e.g. user entity doesn't have any) and also using all bundles if there's no filter set by bundle key in the view so $views_filters is left undefined.

WorldFallz’s picture

Looks good to me-- thanks for the patch. Can we get 1 more person to apply the patch and test?

sgdev’s picture

Status: Needs work » Reviewed & tested by the community

Have tested out the addition and seems to work as I would expect. Thanks.

marksmith’s picture

Patch #20 works for me too. Thank you!