Entity Reference Views Limit not working

Created on 26 July 2016, over 8 years ago
Updated 19 July 2024, 5 months ago

Problem/Motivation

Hello,

The limit of entity reference when I use views is not working it's aways 10 instead of use the views pager

Steps to reproduce

  • Create a new views and create a display type entity reference
  • Select 50 items on pager
  • Go to any content type and create an entity reference field
  • On reference method select views after that select your view
  • Create a new content type, fill out anything that have more than 10 contents on reference field, it will show just 10 items

Proposed resolution

If a limit is set on the view via a pager, use that setting. If no pager is set on the view, add a pager with a limit of 10 so users don't unexpectedly dig themselves into a huge performance hit when removing the pager from the view.

Remaining tasks


User interface changes

None, UI settings are now actually used instead of ignored.

API changes

none

Data model changes

none

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Viewsย  โ†’

Last updated about 3 hours ago

Created by

๐Ÿ‡ง๐Ÿ‡ทBrazil guilopes

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly kopeboy Milan

    It's a shame this isn't fixed yet after years in core.
    Any site builder CANNOT force an entity reference selection: even if his custom logic defined in a View results in 1 item, a checkbox on the entity form will list multiple options, that he cannot even see in the Views' preview!

    Also, why can't this be fixed in 10.1.x instead of 11?!

  • last update about 1 year ago
    Patch Failed to Apply
  • I ran into this small issue using webforms to make a more visual selection of nodes. The patches are not working for 10.2.x. Would be great if this could be fixed , because showing ALL the results on a single page will result in performance issues.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly kopeboy Milan

    I was able to fix this just by adding these lines to /core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php

    (after the $this->view->setDisplay($display_name);, before the $entity_reference_options = [)

        $this->view->initPager();
        $items_per_page = $this->view->getItemsPerPage();
        if ($items_per_page > 0) {
          $limit = $items_per_page;
        }
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia anchal_gupta

    I have uploaded the patch
    Address #53 comment
    Please review

  • #53 and patch from #54 seem to be working

  • Status changed to RTBC 10 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly kopeboy Milan

    What do you mean?
    There is no paging in entity references and if you set a limit in the View with "Display a specified number of items", you are explicitly removing the pager.
    I just tested that the pager on another display (of type page) of the same View works.

  • Status changed to Needs work 10 months ago
  • The Needs Review Queue Bot โ†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request โ†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Prem Suthar โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 10 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Create the Mr For Issue. Please Review

  • Pipeline finished with Success
    10 months ago
    Total: 628s
    #102038
  • Status changed to Needs work 10 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This will need test coverage

    #54 appears to have dropped a good portion of the original patch, how come? @Prem Suthar see you opened an MR for that too so maybe you know too?

  • #54 appears to have dropped a good portion of the original patch

    And this removal brought back the problem when the pager is not set, in which case the view returns all the results, instead of the specified limit in the widget.

  • I believe that in any case we should override the pager with parameters from the EntityReferenceSelection plugin.

    And the implementation of what is described in the problem will cause confusion for users who want to determine the limit of results at the widget level.

    I opened a new merge request that solves the problem where if a view doesn't have a pager set, all results are displayed.

  • Pipeline finished with Failed
    6 months ago
    Total: 167s
    #202383
  • Pipeline finished with Success
    6 months ago
    Total: 540s
    #202581
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    smustgrave โ†’ changed the visibility of the branch 2772523-entity-reference-views to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Thanks @kksandr for restoring what was removed in 54 and previous MR

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
    1) Drupal\Tests\field\Kernel\EntityReference\Views\ViewsSelectionLimitTest::testLimitedOutput
    Failed asserting that actual size 20 matches expected size 10.
    /builds/issue/drupal-2772523/core/modules/field/tests/src/Kernel/EntityReference/Views/ViewsSelectionLimitTest.php:84
    FAILURES!
    Tests: 1, Assertions: 8, Failures: 1.

    Shows the test coverage so removing that tag.

    Left some small comments on MR

    Appears to be close!

  • Pipeline finished with Canceled
    6 months ago
    Total: 185s
    #203480
  • Pipeline finished with Success
    6 months ago
    Total: 550s
    #203488
  • Status changed to Needs review 6 months ago
  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Feedback appears to be addressed thanks!

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    The proposed resolution doesn't match the MR.

    Also instead of dynamically changing the pager type, why not validate it when a view is selected?

Production build 0.71.5 2024