Exposed Entity reference filter criteria gives internal server error on edit in the Views UI.

Filter criteria was successfully added and works when filtering the View.

But when I try to edit the filter criteria, I see an error in the browser console.
Also, the admin UI doesn't display the selected value, it just says 'exposed'.

Steps to reproduce:
- Create a View of content
- Add a filter on 'Authored by'
- Expose the filter
- Set the default value to a user (admin (1))
- Apply
- Try to open the edit dialog for the filter

Expected result: Dialog opens

Actual result: Dialog doesn't open and throws a server error:

POST http:///example.com/admin/structure/views/ajax/h..._export_1/filter/uid?_wrapper_format=drupal_ajax 500 Internal Server Error 324ms	
"NetworkError: 500 Internal Server Error - http://example.com/admin/structure/views/ajax/handler/articleslistexport/rest_export_1/filter/uid?_wrapper_format=drupal_ajax"
uid?_wr...al_ajax
AjaxError: 
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/structure/views/ajax/handler/articleslistexport/rest_export_1/filter/uid
StatusText: Internal Server Error
ResponseText: {}
administration-reports-recent log messages shows-
Location 	http://example.com/admin/structure/views/ajax/handler/articleslistexport/rest_export_1/filter/uid?_wrapper_format=drupal_ajax
Referrer 	http://example.com/admin/structure/views/view/articleslistexport/edit/rest_export_1
Message 	InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects. in Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback() (line 68 of /home/ubuntu/projects/drupal/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php).
Severity 	Error
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ruplah created an issue. See original summary.

ruplah’s picture

Issue summary: View changes
ruplah’s picture

Issue summary: View changes
cilefen’s picture

Title: Exposed filter criteria gives internal server error on edit in rest view » Exposed filter criteria gives InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects. in Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback()
Component: ajax system » views.module
cilefen’s picture

Usually with something like this we like to see attached a copy of the view definition exported from configuration management.

Lendude’s picture

Version: 8.2.4 » 8.2.x-dev
Component: views.module » views_ui.module
Issue summary: View changes
Issue tags: -views

Updated the IS with steps to reproduce (Some additional clicking at some point made it work again, couldn't reproduce the steps to make it work though).

When it was working $element['#process_default_value'] in \Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback was FALSE, for some reason, it is TRUE when using the steps to reproduce.

Lendude’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
605 bytes

This is an attempt at a fix. Fixes the issue in the Views UI.

Did a quick manual test for filtering a View and it seemed to work as expected. So don't know why that setting should ever be TRUE here.

Adding a Javascript test for this might be tricky at the moment, since PhantomJS doesn't play nice with exposing the filter currently, see #2754985: [backport] Add JavaScript test coverage for adding an exposed filter in Views UI

asghar’s picture

I have tested with the patch and now expose filter working fine. Thanks

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Pavan B S’s picture

Rerolled the patch, please review

asghar’s picture

Hi @Pavan B S

I cannot see the difference between your patch and @Lendude patch.

Pavan B S’s picture

@asghar when i applied the patch, it showed error message, so i rerolled the patch with the latest git update(8.3.x).

Lendude’s picture

+++ b/core/modules/user/src/Plugin/views/filter/Name.php
@@ -28,7 +28,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
     ];

Reroll was needed for #2776975: March 3, 2017: Convert core to array syntax coding standards for Drupal 8.3.x RC phase, changed one ) to a ]

balagan’s picture

I applied patch #10 on 8.4.0-dev, and it solves the problem. Tests are still needed.

balagan’s picture

Status: Needs review » Needs work
cilefen’s picture

Issue tags: -Triaged core major

I removed the "Triaged D8 major" tag because that is not the correct tag following a triage session. @balagan comment #14 seems to be an ordinary comment rather than the results of a triage.

cilefen’s picture

@balagan That's good work so far on triage. I could give you credit if you complete and document the rest of the triage steps (even if brief). It is the only way to know if the triage has actually been completed. Here are some made-up examples of documented triage steps:

  • I tested the steps to reproduce and they did (or did not) work (so I am tagging it "Needs issue summary update").
  • I searched for duplicate issues but could not find any.
  • I checked the issue summary and it is accurate and up-to-date.
  • Etc...

Thank you!

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

longwave’s picture

Status: Needs work » Reviewed & tested by the community

I know this is "needs tests" but going to go ahead and mark this trivial patch as RTBC anyway. I can reproduce by following the steps in the IS and the patch fixes the issue for me.

As per #2754985: [backport] Add JavaScript test coverage for adding an exposed filter in Views UI we have no exposed filter test coverage at the moment and I don't see that being fixed any time soon, but this is a simple fix that can be manually tested quite quickly - maybe we can make an exception to the "needs tests" rule here?

Lendude’s picture

Status: Reviewed & tested by the community » Needs work

I don't think we should do #22. Now there is some incentive to add it in. Before it was just adding coverage for existing functionality, which is always going to be low priority.

The last time we worked on adding that coverage was back in de PhantomJs days. Hopefully things should be easier now. Unpostponed the other issue, and will take a fresh look at that.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Matroskeen’s picture

I just closed exactly the same issue that I created recently: #3250352: Username views filter should not process default value twice in favor of #2920039: Views' User Name exposed group filter validation because it introduced a test that won't pass without this fix. I believe we can close this one as well, which is nice because it's Major!

@lendude, you'll probably want to transfer some issue credits before we go. It's so funny to find such duplicates ;)

Lendude’s picture

Status: Needs work » Closed (duplicate)

Yes lets continue this in #2920039: Views' User Name exposed group filter validation, that has more activity and also contains this fix.