Problem/Motivation

Steps to reproduce:
1. edit who_s_new view at admin/structure/views/view/who_s_new
2. add relationship "User: Content authored"
3. add filter criteria "Content: Type"
After clicking the button "Add and configure filter criteria" nothing happens. Reloading the page gives an error page "The website has encountered an error. Please try again later.". Dblog shows two errors: "Notice: Trying to get property of non-object in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 706 of /home/s881b53b46578b78/www/core/modules/views/src/Plugin/views/HandlerBase.php)." and "Exception: No entity type for field type on view who_s_new in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 716 of /home/s881b53b46578b78/www/core/modules/views/src/Plugin/views/HandlerBase.php)."

Proposed resolution

Remaining tasks

User interface changes

API changes

Original report by @username

Goal: Filter nodes based on the current user attributes which has the same term in nodes.

This error shows when adding "Content type" in filter area of views.
Uncaught PHP Exception Exception: "No entity type for field type on view test_announcement" at /var/www/drupal8/core/modules/views/src/Plugin/views/HandlerBase.php line 770

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug: Relationships can't be properly configured in the UI/td>
Issue priority Major, because its a key functionality of views, but its not a broken site for everyone
Disruption No disruption, just internal fixes.
CommentFileSizeAuthor
#20 2322457-20.patch4.15 KBpcambra
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,912 pass(es). View
#17 interdiff.txt2.08 KBolli
#17 2322457-17.patch4.11 KBolli
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,762 pass(es). View
#15 2322457-15.patch2.86 KBandypost
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,440 pass(es), 5 fail(s), and 1 exception(s). View
#5 2322457-5.patch2.93 KBolli
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,410 pass(es). View
#5 2322457-test_only.patch2.06 KBolli
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 79,097 pass(es), 5 fail(s), and 1 exception(s). View
2_2.png149.67 KBadrian.ravis
1_1.png163.44 KBadrian.ravis

Comments

dawehner’s picture

Version: 8.0.0-alpha14 » 8.0.x-dev
Status: Needs work » Postponed (maintainer needs more info)

It would be kind of cool if you could provide an export of that view. This seems to be no straightforward view to rebuild.

adrian.ravis’s picture

I can't get the export data of the view. When I apply the "Content type" in filter it hangs only in image "2_2.png" that I provided. I tried to reload it but it returns "Error: The website has encountered an error. Please try again later" and I've tried it many times.

dawehner’s picture

Well, please enable error display under "logging and errors" under admin/config

olli’s picture

Component: entity system » views.module
Status: Postponed (maintainer needs more info) » Active
Issue tags: +VDC

I was able to reproduce this by adding a content view with a relationship using field_tags and then tried to add a vocabulary filter. I can't edit my view anymore.

Error
The website has encountered an error. Please try again later.
Error message

Notice: Trying to get property of non-object in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 760 of core/modules/views/src/Plugin/views/HandlerBase.php).


    Drupal\views\Plugin\views\HandlerBase->getEntityType()
    Drupal\views\Plugin\views\filter\Bundle->init(Object, Object, Array)
    Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers('filter')
    Drupal\views\Plugin\views\display\DisplayPluginBase->getHandler('filter', 'vid_1')
    Drupal\views_ui\Form\Ajax\ConfigHandler->buildForm(Array, Object)
    call_user_func_array(Array, Array)
    Drupal\Core\Form\FormBuilder->retrieveForm('views_ui_config_item_form', Object)
    Drupal\Core\Form\FormBuilder->buildForm('Drupal\views_ui\Form\Ajax\ConfigHandler', Object)
    views_ajax_form_wrapper('Drupal\views_ui\Form\Ajax\ConfigHandler', Object)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object, 'default', 'nojs')
    Drupal\views_ui\Form\Ajax\ConfigHandler->getForm(Object, 'default', 'nojs', 'filter', 'vid_1')
    call_user_func_array(Array, Array)
    Drupal\Core\Controller\HtmlPageController->getContentResult(Object, '\Drupal\views_ui\Form\Ajax\ConfigHandler::getForm')
    Drupal\Core\Controller\HtmlPageController->content(Object, '\Drupal\views_ui\Form\Ajax\ConfigHandler::getForm')
    call_user_func_array(Array, Array)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
    Drupal\Core\DrupalKernel->handle(Object)

Exception: No entity type for field vid on view bundletest in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 770 of core/modules/views/src/Plugin/views/HandlerBase.php).

    Drupal\views\Plugin\views\HandlerBase->getEntityType()
    Drupal\views\Plugin\views\filter\Bundle->init(Drupal\views\ViewExecutable, Drupal\views\Plugin\views\display\DefaultDisplay, [Array])
    Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers(filter)
    Drupal\views\Plugin\views\display\DisplayPluginBase->getHandler(filter, vid_1)
    Drupal\views_ui\Form\Ajax\ConfigHandler->buildForm([Array], Drupal\Core\Form\FormState)
    call_user_func_array([Array], [Array])
    Drupal\Core\Form\FormBuilder->retrieveForm(views_ui_config_item_form, Drupal\Core\Form\FormState)
    Drupal\Core\Form\FormBuilder->buildForm(Drupal\views_ui\Form\Ajax\ConfigHandler, Drupal\Core\Form\FormState)
    views_ajax_form_wrapper(Drupal\views_ui\Form\Ajax\ConfigHandler, Drupal\Core\Form\FormState)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Drupal\views_ui\ViewUI, default, nojs)
    Drupal\views_ui\Form\Ajax\ConfigHandler->getForm(Drupal\views_ui\ViewUI, default, nojs, filter, vid_1)
    call_user_func_array([Array], [Array])
    Drupal\Core\Controller\HtmlPageController->getContentResult(Symfony\Component\HttpFoundation\Request, \Drupal\views_ui\Form\Ajax\ConfigHandler::getForm)
    Drupal\Core\Controller\HtmlPageController->content(Symfony\Component\HttpFoundation\Request, \Drupal\views_ui\Form\Ajax\ConfigHandler::getForm)
    call_user_func_array([Array], [Array])
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Symfony\Component\HttpFoundation\Request, 1)
    Symfony\Component\HttpKernel\HttpKernel->handle(Symfony\Component\HttpFoundation\Request, 1, TRUE)
    Drupal\Core\DrupalKernel->handle(Symfony\Component\HttpFoundation\Request)

olli’s picture

Status: Active » Needs review
FileSize
2.06 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 79,097 pass(es), 5 fail(s), and 1 exception(s). View
2.93 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,410 pass(es). View

Here's a patch that uses this->table instead of this->view->relationships which are not available.

The last submitted patch, 5: 2322457-test_only.patch, failed testing.

olli queued 5: 2322457-test_only.patch for re-testing.

The last submitted patch, 5: 2322457-test_only.patch, failed testing.

olli’s picture

Priority: Normal » Major
Issue summary: View changes

Added steps to reproduce to issue summary.

13rac1’s picture

Status: Needs review » Reviewed & tested by the community

Yes. This fixes the issue and applies cleanly. I can edit a View with a broken handler now!

dawehner’s picture

Are we really sure this is the proper fix? $this->table could point to something like node_field_data, which might or might not have 'entity type' on there.
Using the base tables (which is what the previous code did, feels much more secure.

Afaik we could also fix this issue by using $this->view->relationship[$relationship_name]->table instead.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Setting back to "needs review" to get answers to #11

olli’s picture

#11: Good points.

Are we really sure this is the proper fix? $this->table could point to something like node_field_data, which might or might not have 'entity type' on there.
Using the base tables (which is what the previous code did, feels much more secure.

Isn't it the same problem with base tables?

Afaik we could also fix this issue by using $this->view->relationship[$relationship_name]->table instead.

That was my first thought but this method is invoked from an init() and having relationship[X]->table ready sounded like the init() of that relationship should be called before this one so went with something simple.

andypost’s picture

The same problems with related issue - I need to find the relation that used for the handler so

+++ b/core/modules/views/src/Plugin/views/HandlerBase.php
@@ -700,10 +700,8 @@ public static function getTableJoin($table, $base_table) {
+    if ($this->table !== NULL) {

This does not work for related, it returns "comment_entity_statistics" but I need to know the entity type of the relation

andypost’s picture

FileSize
2.86 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,440 pass(es), 5 fail(s), and 1 exception(s). View

Suppose the proper fix as said #13

Status: Needs review » Needs work

The last submitted patch, 15: 2322457-15.patch, failed testing.

olli’s picture

Status: Needs work » Needs review
FileSize
4.11 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 81,762 pass(es). View
2.08 KB

Maybe this?

Status: Needs review » Needs work

The last submitted patch, 17: 2322457-17.patch, failed testing.

olli queued 17: 2322457-17.patch for re-testing.

pcambra’s picture

Status: Needs work » Needs review
FileSize
4.15 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,912 pass(es). View

Plain re roll of this, fixes the problem described with the relationships and filters.

dawehner’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Nice work!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed f51b029 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed f51b029 on 8.0.x
    Issue #2322457 by olli, adrian.ravis, andypost, pcambra: Error in Views...

Status: Fixed » Closed (fixed)

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