ECA Views appears to not honour View Relationship

Created on 5 September 2023, over 1 year ago
Updated 5 January 2024, about 1 year ago

Problem/Motivation

I have a simple ECA which is intended to intercept (Pre-save) a content type B to look up which instance of content type A references B.

I have a simple View which performs the reverse lookup using a Contextual filter and a Relationship.
If I feed a type B node ID to the view, it correctly returns the node ID of the type A node.

For context...

My content types are:
A is known as an Explainer. (a students' version)
B is known as an Explainer whiteboard (a teachers' version)

It's very simple scenario, Explainers (a) point to one and one only instance of Explainer whiteboard (B) via an entity reference field 'field_teacher_explainer'.

Problem with ECA usage

I have created an ECA that intercepts (Pre-save) of B and I extract the node ID (nid) of B and feed it as an Argument to the view...

Observation
The ECA returns the original nid that was sent in as a argument instead of the 'reverse looked up' one?

It is essentially as though when calling the view through ECA, the (mandatory) View Relationship is simply not kicking in!?

I have tested the view extensively and there really isn't anything wrong there, it does seem like an issue with ECA and Views with relationships to me.

For completeness, here is the task setting for the View communication...

And here is the final debug output message which seems to confirm what I think I'm seeing...

Finally, I attach a .yml export of the ECA in case that might help.

Any advise gratefully.

Thanks

πŸ’¬ Support request
Status

Fixed

Version

1.1

Component

Miscellaneous

Created by

πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SirClickALot
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Views queries are intentionally returning a list of found entities from the main table of the view, regardless of relationships or fields. This is due to the views architecture:

    1. the view gets built and queried: this takes all the relationships, context, sorts and filters into account and creates a list of found entities; this is always entities of the view's main table
    2. the view result gets rendered: here, the display plugin and all the fields (if defined) are taken into account

    So, the view query is only about step 1, and it doesn't return anything else than the list of found entities. And that's what the ECA action plugin is supposed to be doing.

    It might be possible to provide additional action plugins, that go a step further and also render the view to return the rendered result. But that's not yet on the roadmap and would require some resources to be developed.

  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

    OK, thanks for the response here @jurgenhaas β†’ but I'm not sure that I fully I understand you correctly.

    May I re-phrase in order to try to help...

    I know that my view works in the views UI because sending it 8526 as an argument in the UI preview returns 8525 which is correct because nid:8525 refers to nid:8526.

    I think that my view IS being sent the correct argument in the ECA as [this-whiteboard:nid] because if I temporarily replace the [this-whiteboard:nid] with an actual nid:8526 gives the same result.

    However, when called from within the ECA, the view returns 8526 instead of 8525.

    If I understand you correctly, when the view is called inside the ECA, it (the view) does all its usual contextual filtering / relationships etc. and indeed return a LIST of all candidate entities - which I assume from what you've said is a list of entity IDS?

    If that is so (contextual filtering and relationships are all used as expected) then why I am seeing SIX (8526) being returned - that was the original nid to it.
    From what you've confirmed, I should surely being seeing a list (1 entry only) identifying nid:8525?

    If I got back the correct ID then I could load the node and get on with the rest but I'm not being sent it.

    I'm certain that the correct nid is being sent to the view from within the ECA because if I temporarily replace the [this-whiteboard:nid] with an actual nid:8526 gives the same result.

    Sorry to be a continued bother here but I'm a bit stumped.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I can't review all the configurations that we receive in context of support. That's just too time consuming.

    When you refer to "it works in views UI", that's comparing apples and pies. The view UI goes through all the steps that I described: it queries the database and then renders the results.

    But ECA does only the first step: it queries the DB and DOES NOT render the result. It receives the raw result from the DB query. And if that DB query delivers the wrong result, then either the view is not configured correctly or the arguments provided to the context filter are not correct.

    If, instead, you want to receive the rendered result from a view, then you may be interested in the Render: Views action plugin. A nice example was posted in πŸ’¬ [eca_views]: How to get the actual View result in ECA Fixed yesterday.

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    @SirClickalot is the result you expect in the "main" views table, or in the "relationship" table?

    From your results, I'm guessing that argument you're passing in is for the "main" table, and you're using the views relationship to get the related nodes.

    If so, you should be able to flip this around -- make the main content type the ones you want to return, make the relationship go the other direction, and then in the argument handler, tell it to use the relationship. This should give ECA the related node instead of the original node...

  • Status changed to Fixed about 1 year ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    It sounds as if marking this fixed is appropriate. If not, please re-open and let us know what's missing.

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

Production build 0.71.5 2024