Problem/Motivation

In settings of entity reference field, the entity type is marked as required, but the validation allows this to be empty.
A desired feature, as contained in Drupal 7, is when this option are left empty, all bundles are allowed to be referenced.

Steps to reproduce

  1. On a new drupal installation, add a new field(admin/structure/types/manage/article/fields) to the Article content type
  2. On Add a new field select Reference > Content
  3. Choose any name for the field label
  4. On the next screen just click on Save field settings
  5. A new form screen will open and on the Reference Type fieldset you'll see a Content type required field

Proposed resolution

Make the entity type requirement as FALSE and add a short description to notice the users about de behavior when this setting is leave as empty.

Comments

lucass created an issue. See original summary.

lucass’s picture

damiengr’s picture

Status: Active » Needs review
hchonov’s picture

Issue tags: +Needs tests

We need a test coverage for this. But I agree that we need this feature.

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.

swentel’s picture

Rerolled for 9.3.x, also using $this->t(

DefaultSelection::validateConfigurationForm already has a comment which explains why the storage either contains array or NULL. So the API itself allows it already (and tested it manually). Couldn't find a test immediately that actively tests this feature.

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.

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

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Seems like a great feature.

#7 still applies to 10.1 too!

Was previously tagged for tests which still need to happen

Thanks!

murilohp’s picture

Issue summary: View changes
Issue tags: -Needs tests
StatusFileSize
new1.49 KB
new1.3 KB
new2.42 KB

I was taking a look at the bug and I've written a new test for it, the test will try to save a new reference field without checking any bundles and then validate the new description. I think this will cover the feature.

PS: I've also updated the IS with some steps to reproduce.

smustgrave’s picture

Status: Needs work » Needs review

Lets see to review and see what happens!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Great job on the tests!

amateescu’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Entity Reference, -target bundles +Needs usability review

The target bundles selector was made required based on UX review of the Entity Reference, very soon after it went into 8.x core, see #1953444: Make 'target bundles' required on the Entity reference instance settings form and #1847596-119: Remove Taxonomy term reference field in favor of Entity reference.

We shouldn't undo that change without going through a discussion with the usability team.

simohell’s picture

What happens if we have content types
- Dog
- Horse
- Kennel
- Stable

In Kennel we have field referencing Dog and in Stable we reference Horses.

Content type Dog is deleted.

Will Kennel start referencing Horses as no content type is selected?

We add content type Fence material.

Will Kennel then reference Horses and Fence materials?

benjifisher’s picture

Status: Needs review » Needs work
Issue tags: -Needs usability review
Related issues: +#2986958: Add support for negating user role condition for block visibility

Usability review

We discussed this issue at #3340893: Drupal Usability Meeting 2023-02-17. That issue has a link to a recording of the meeting.

For the record, the attendees at the usability meeting were @AaronMcHale, @BlackBamboo, @benjifisher, @gaurav mahlawat, @lauriii, @rkoller, @shaal, and @simohell.

The points raised in #16 and #17 are valid. We agreed not to follow this approach.

An alternative to consider is adding an explicit option to toggle between "allow only the selected types" and "allow any but the selected types". This would be similar to the way page restrictions work when configuring block visibility. The other block visibility options do not follow this pattern, but perhaps they should. (See #2986958: Add support for negating user role condition for block visibility, for example. I am adding that as a related issue.)

Another alternative would be to add an "All" option at the top of the list. If that is selected, then hide the other options.

Before implementing either alternative, it would help a lot to do some user testing and consider other places in Drupal core that folllow similar patterns.

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.

jonathanshaw’s picture

Title: Entity reference: leave empty to allow all bundles » Entity reference: allow specifiying that every bundle is allowed

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.