Problem/Motivation

Creating a node with a entity reference field refer to a file got an error (on js console):
Fatal error: Call to a member function range() on a non-object in /core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php on line 184

Steps To Reproduce

Create a content type "File", with a file field "File"
Content Type File

Add some contents to "File"
Add some files

Add reference field "File Reference" to "Article", then set "Type of item to reference" to "File" ("File" entity type, not "Content" entity type with bundle "File")
Add file reference field
Set type of reference

Open javascript console, then add new "Article"
Add new article

Expected: autocomple work, with a list of file including sample.jpg
Actual: autocomple does not work, with an error:
Error on console

Issue fork drupal-2353881

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tien.xuan.vo’s picture

StatusFileSize
new8.94 KB
new648 bytes

Here is a fix. Bellow is the autocomple results after apply the patch:
autocomple results

tien.xuan.vo’s picture

Status: Active » Needs review

Change status

primsi’s picture

Status: Needs review » Reviewed & tested by the community

Reproduced the error, applied patch and tested.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Nice find. We should be able to add an automated test for this.

tien.xuan.vo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

Here is the patch that contains tests. Please review it for me.

berdir’s picture

Title: Call to a member function range() on a non-object in Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase in line 184 » Add test coverage for file entity reference selection plugin
Category: Bug report » Task
Priority: Major » Normal
Status: Needs review » Needs work
Issue tags: -#file, -#entity reference, -Needs tests +Needs reroll

I didn't know about this issue, recently got a fix in that didn't add tests however. Changing this to a task to add those tests.

vedpareek’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB

Rerolled

Status: Needs review » Needs work

The last submitted patch, 7: 2353881_7.patch, failed testing.

sharique’s picture

  1. +++ b/core/modules/file/src/Tests/FileSelectionTest.php
    @@ -0,0 +1,109 @@
    +    $field_storage = entity_create('field_storage_config', array(
    

    entity_create is deprecated.

  2. +++ b/core/modules/file/src/Tests/FileSelectionTest.php
    @@ -0,0 +1,109 @@
    +    $field = entity_create('field_config', array(
    

    entity_create is deprecated.

  3. +++ b/core/modules/file/src/Tests/FileSelectionTest.php
    @@ -0,0 +1,109 @@
    +    $this->handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($field);
    

    This causing test to fail.

  4. +++ b/core/modules/file/src/Tests/FileSelectionTest.php
    @@ -0,0 +1,109 @@
    +      $file = entity_create('file', (array) $data);
    

    entity_create is deprecated.

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new3.15 KB

Please review.

Status: Needs review » Needs work

The last submitted patch, 10: 2353881-10.patch, failed testing.

sharique’s picture

+++ b/core/modules/file/src/Tests/FileSelectionTest.php
@@ -0,0 +1,112 @@
+      $expected_result[$file->id()] = String::checkPlain($file->label());

Fatal error: Class 'Drupal\Component\Utility\String' not found in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/file/src/Tests/FileSelectionTest.php on line 65

googletorp’s picture

Issue tags: -Needs reroll
rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new874 bytes
new3.16 KB

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

This seems outdated and possibly a reroll.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new3.15 KB
new2.91 KB

Patch #14 doesn't needed reroll, I've fixed Drupal CS issues of patch #14.

smustgrave’s picture

Did you test this?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Thinking I got tickets crossed in #28?

But ran #27 for D10 tests and had CI failures.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera made their first commit to this issue’s fork.

mohit_aghera’s picture

Assigned: tien.xuan.vo » Unassigned
Status: Needs work » Needs review

- Updated a new kernel test to validate the entity query results.
- Using other general practices for creating fields etc.

Code is already fixed so no changes are required in EntityReference handler plugin.
Hiding existing patches in favour of MR.

Tests are passing on local.

smustgrave’s picture

Status: Needs review » Needs work

Thanks for working on this!

Test failures seem related to this change.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative

MR is green now.
Moving back to NR

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for fixing that, seems like good test coverage. LGTM.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mohit_aghera’s picture

Status: Needs work » Reviewed & tested by the community

Moving back to RTBC since the MR is already green.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mohit_aghera’s picture

Status: Needs work » Reviewed & tested by the community

Updated the branch with latest 11.x
Though "needs-review-queue-bot" commented, however, I didn't noticed any merge conflicts though.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mohit_aghera’s picture

Status: Needs work » Reviewed & tested by the community

Updated branch with latest 11.x
MR is green.
Moving back to RTBC again.

  • alexpott committed f795f242 on 11.x
    Issue #2353881 by berdir, sharique, rpayanm, smustgrave, mohit_aghera,...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed f795f24 and pushed to 11.x. Thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

catch’s picture

Pushed a commit to switch from the phpunit annotation to attribute to unbreak head.

  • catch committed ff7a292f on 11.x
    Issue #2353881: follow-up - use phpunit attribute instead of annotation.
    
nicxvan’s picture

This broke head there is an annotation.
Edit, I missed it was already fixed

Status: Fixed » Closed (fixed)

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