This module was created to handle the ordering by delta using entity reference items, views has a field to do that, but views actually duplicate the result when sorting using a relationship, works if not using a relationship (which makes no sense), but this field is missing on modules like Config Pages that has no proper views integration.

Sandbox link:
https://www.drupal.org/sandbox/mete/2795269

Git:
git clone --branch 8.x-1.x https://git.drupal.org/sandbox/Mete/2795269.git

Comments

Mete created an issue. See original summary.

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

E-MAILiT’s picture

AUTOMATED REVIEW

There is some coding standard errors to fix:
http://pareview.sh/pareview/httpsgitdrupalorgsandboxmete2795269git

Individual user account

No: Please add your firstname and surname to your profile

No duplication

Yes: Does not cause

3rd party assets/code

Yes: Follows

README.txt/README.md

Please add a README.txt or README.md file.

Code long/complex enough for review

Yes. Well documented.

Secure code

None security issue found. Looks good.

anand.toshniwal93’s picture

Automated Review

There are some issues of coding standard try to fix it
http://pareview.sh/pareview/httpsgitdrupalorgsandboxmete2795269git

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Followsthe licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
Code long/complex enough for review
No: Does not follow the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.
Coding style & Drupal API usage
  1. Please add Readme file with help of it most of the people review your module functionality. Readme file template: https://www.drupal.org/node/2181737

This review uses the Project Application Review Template.

anand.toshniwal93’s picture

Status: Needs review » Needs work
Joao Sausen’s picture

Thanks for the reviews, I add the readme file and also properly renamed the module to views_order_by_delta from order_by_delta.

Joao Sausen’s picture

Status: Needs work » Needs review
joachim’s picture

Status: Needs review » Needs work
              // @todo: use a proper method to get the table name for the field.
              $table_name = $field->get('entity_type') . '__' . $field->get('field_name');

I think you can get that from the entity storage handler.

                $data[$entity_info->getBaseTable()][$table_name] = array(

That's wrong. You'll clash with something else, surely. Your key in the views data array should be unique.

 * Defines a custom sort handler.

So does every other handler class... tell us something different ;)

    foreach ($this->query->tables as $table) {
      if (isset($table[$this->realField])) {
        $has_table = TRUE;
        break;
      }
    }

This is wrong. What if the query doesn't have the table for the field -- your handler does nothing!! You need to ensure your table is added. There's a method called something like ensureTable for that.

Overall, code looks good.

But AFAICT this functionality is already in core: I have a multi-valued field on my article nodes, and in Views I see this sort handler:

test text multiple (field_test_multiple:delta) Content Delta - Appears in: article.

Joao Sausen’s picture

Hey Joachim, thanks for your input. The feature exists indeed, but if you try to sort by that you will get duplicated results in case you use a relationship. You will probably be able to use the field without a relationship if you are referencing nodes to nodes, or any other entities, because the field exists in the referencing entity. Bu if you try to do that with different entities the field will exists for the referencing entity only and therefore there will be no way to use this field if not using a relationship, and this will cause duplications. In any case, try to setup that using 2 different entities, or try to use config_pages for that purpose. The issue is a bit difficult to explain, I hope you understand. In any case, I appreciate your review!

Joao Sausen’s picture

Add some comments and renamed the array key.

Joao Sausen’s picture

Status: Needs work » Needs review
joachim’s picture

> The feature exists indeed, but if you try to sort by that you will get duplicated results in case you use a relationship. You will probably be able to use the field without a relationship if you are referencing nodes to nodes, or any other entities, because the field exists in the referencing entity.

I'm really confused by all this!

Can you give me a simple example of when core would give me duplicated results, but your module won't?

Joao Sausen’s picture

Absolutely.

Here are the steps to reproduce the error in a fresh drupal 8 installation:

  • Add some content of type article
  • Go to Structure > Taxonomy > Tags (List Terms) > Manage Fields (/admin/structure/taxonomy/manage/tags/overview/fields) and click on + add field.
  • Create a field of type Reference (Content), use Reference as the label, click save and continue
  • Set the field to unlimited, click Save field settings
  • Go back to /admin/structure/taxonomy/manage/tags/overview and create a new tag
  • Set a name and reference your content on the field Reference
  • Go to Structure > Views > + add new view
  • Give it a name, set Show "Content" of type "Article", click Save & Edit
  • Create a new relationship using the field_reference, the title is "Taxonomy term using field_reference" the category is Content.
  • Set "Require this relationship" and hit "Apply".
  • Delete any existing sort criteria

Now the steps above are different on both cases.

For the drupal core field:

  • Add a sort criteria "Reference (field_reference:delta)"
  • This will already give you duplicated results and this will not order by delta in any way.

For the module field:

  • Add a sort criteria "Order by delta (using field_reference)"
  • This will give the desired results.

This only happens when relating 2 different entities, if you want to go ahead on the tests:

  • Create a field reference on the article content type, use the same machine_name that already exists (field_reference).
  • Go to the view using the core sort field, but on the field criteria set the Relationship to "nothing".
  • This will also works because the field names matches in the SQL query and there is no relationship to duplicate the results.

Note: In these examples, if you remove all sort criterias the content will be ordered like if you ordered by the delta value, you can rearrange the items on your field reference and this will works, but we can't rely on that since there will be no Order By.

joachim’s picture

Ok yup I see the duplicates.

It's because the Views relationship is going *backwards* along the reference. The field is like Term -> Node, but in the View, the relationship is used going Node -> Term.

The sort handler appears to be unaware of this, and is adding the join to {taxonomy_term__field_reference} all over again.

I would say this is a case for a bug report on core rather than a new module to work around it!

Joao Sausen’s picture

I agree, thats a bug for sure, this also exists in Drupal 7. I was trying to debug core to try to solve that, unfortunately I don't have enough knowledge to do that for now...

Joao Sausen’s picture

Will this module be approved?

PA robot’s picture

Status: Needs review » Closed (duplicate)
Multiple Applications
It appears that there have been multiple project applications opened under your username:

Project 1: https://www.drupal.org/node/2873432

Project 2: https://www.drupal.org/node/2796023

As successful completion of the project application process results in the applicant being granted the 'Create Full Projects' permission, there is no need to take multiple applications through the process. Once the first application has been successfully approved, then the applicant can promote other projects without review. Because of this, posting multiple applications is not necessary, and results in additional workload for reviewers ... which in turn results in longer wait times for everyone in the queue. With this in mind, your secondary applications have been marked as 'closed(duplicate)', with only one application left open (chosen at random).

If you prefer that we proceed through this review process with a different application than the one which was left open, then feel free to close the 'open' application as a duplicate, and re-open one of the project applications which had been closed.

I'm a robot and this is an automated message from Project Applications Scraper.

cimo75’s picture

Backporting to D7 please?

Joao Sausen’s picture

Cimo75, leave the sort items blank and it will work as expected.

cimo75’s picture

Hallo, I thinik I don't understand, can I install this module in D7?

Ravi Cmsminds’s picture

I checked your module and found some issues and recommendations that you may be interested in :

FILE: /root/repos/pareviewsh/pareview_temp/views_order_by_delta.views.inc
--------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 6 LINES
--------------------------------------------------------------------------
8 | ERROR | [x] When importing a class with "use", do not include a
| | leading \
9 | ERROR | [x] When importing a class with "use", do not include a
| | leading \
15 | ERROR | [x] Short array syntax must be used to define arrays
39 | ERROR | [x] Short array syntax must be used to define arrays
40 | ERROR | [x] Short array syntax must be used to define arrays
42 | ERROR | [x] Short array syntax must be used to define arrays
--------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------

apaderno’s picture