Missing global entity support for Views.

Created on 24 May 2024, about 1 month ago
Updated 29 May 2024, 30 days ago

Problem/Motivation

The README specifies:

Add a field of the type "Rate widget" to your view. If your view has 
relationships defined, select the correct one to attach the field to.

I have a view which lists paragraphs. I have a Rate widget assigned to a specific paragraph bundle. Under fields i have no "Rate widget". I do see a lot of Vote Result relationships which I have not added.

This display was previously showing a Flag field (and therefore had a relationship to the flag) and when this relationship was defined, then i did get a "Rate widget" field which was forced to use the flag relationship - but this has nothing to do with my Rate widget.

What am i missing here?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

3.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada liquidcms

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

Comments & Activities

  • Issue created by @liquidcms
  • πŸ‡¨πŸ‡¦Canada liquidcms

    There is no hook_views_data defined. Which poses some questions:

    - not sure why this does seem to work for Nodes, just not other entities (like Paragraphs)
    - project page reports over 2k sites using this module.. is it possible not one of those is on a non core entity?

    Also, i am surprised that the rate.views.inc file is loaded on its own (it does seem to be; just didnt know that was a thing).

    So adding this code to rate.module (or i guess rate.views.inc since it seems to get automatically loaded) does provide the Rate widget field for a Paragraph view:

    /**
     * Implements hook_views_data().
     */
    function rate_views_data() {
      $data['views']['rate_widget_field'] = [
        'title' => t('Rate widget'),
        'help' => t('An instance of a Rate Widget.'),
        'field' => [
          'id' => 'rate_widget_field',
        ],
      ];
      return $data;
    }

    but it still doesn't work as there are no options to set the column which holds entity id. I'll sort that out next.

  • πŸ‡¨πŸ‡¦Canada liquidcms

    i fixed the id not listing the views fields but thee are bigger issues here when trying to render the widget. Basically it looks like the code tries to simplify not requiring relationships.. but then doesnt take into account related data.

    For example, my view is listing paragraphs but i am trying to vote on a paragraph which is a child of that main paragraph. I have the correct pid as my field that i use in the widget settings; but in the render code it doesnt use this and ends up using the parent pid. I'll sort this out on Monday.

  • πŸ‡¨πŸ‡¦Canada liquidcms

    I changed the title to better describe the issue here. Basically 2 issues:

    1. generic entities are not supported (easily fixed with code posted above).

    2. related content not supported.

    For #2 i went through the render code and it is not correct for handling related content. The module's custom views field does have a setting to select which field is used to get attached entity id for the entity which has the rate widget; but this information is not used in the code. It gets the entity from the base entity of the result row. Of course views doesn't make this easy for us to get row result but it is available. I'll see if i can figure out how to properly access it. The other missing piece would be that i am not sure the view result would know the entity type that the id value is for. It may only know the row base entity (which is what the code currently is using).

    My other option would be to try to arrange my setup so that the views base paragraph is the one being voted on rather than its parent; but certainly easier if this module supported related content.

  • Status changed to Needs review 30 days ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 30 days ago
    14 pass
  • πŸ‡¨πŸ‡¦Canada liquidcms

    patch for code from #2

    rather than try to sort out the issue with using the correct data selected in the field config; i created a separate view using the child paragraph as the base. Then using the https://www.drupal.org/project/views_field_view β†’ module to embed this in my original view. Not ideal from a performance perspective; but works well.

Production build 0.69.0 2024