Entity Reference Views Limit not working

Created on 26 July 2016, over 8 years ago
Updated 24 September 2023, over 1 year 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 10 hours ago

Created by

๐Ÿ‡ง๐Ÿ‡ทBrazil guilopes

Live updates comments and jobs are added and updated live.
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 over 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 about 1 year 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 about 1 year 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 about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Create the Mr For Issue. Please Review

  • Pipeline finished with Success
    about 1 year ago
    Total: 628s
    #102038
  • Status changed to Needs work about 1 year 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
    10 months ago
    Total: 167s
    #202383
  • Pipeline finished with Success
    10 months ago
    Total: 540s
    #202581
  • Status changed to Needs review 10 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 10 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
    10 months ago
    Total: 185s
    #203480
  • Pipeline finished with Success
    10 months ago
    Total: 550s
    #203488
  • Status changed to Needs review 10 months ago
  • Status changed to RTBC 10 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Feedback appears to be addressed thanks!

  • Status changed to Needs work 9 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?

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

    Just ran into this "Entity Reference Views Limit not working". I want no pager, specific number of items 4, skipping 1, whereas I think this issue is focused on displaying greater than the default 10.

    I'm trying to make it easy for a user to manage the display of a past event (image, title and metrics) by an entity reference select.

    I want the user to only see the past 4 events, skipping the current one which has yet to take place.

    The problem is that in Form Display, the entity reference is displaying all events. However, it is honoring skipping 1 (the current scheduled one).

    The View Preview is displaying it correctly, only 4 items, skipping 1.

Production build 0.71.5 2024