Problem/Motivation

In Drupal 7, if I create a field on a content type, I am able to reuse that field for a taxonomy vocabulary.

In Drupal 8, this is not possible. I can only reuse taxonomy fields that I have already created for another taxonomy vocabulary, and content type fields that I have already created for another content type.

This is contrary to the documentation on re-using fields here:

https://www.drupal.org/docs/8/administering-drupal-8-site/managing-conte...

which states (bold added for emphasis):

Once you have defined a field, you can reuse it. For example: if you define a custom image field for one content type, and you need to have an image field with the same parameters on another content type, you can add the same field to the second content type, in the Add existing field area of the user interface. You could also add this field to a taxonomy vocabulary, comments, user accounts, etc.

I can create a new field for use on a taxonomy vocabulary with the same machine name. In the database, there will now be two tables:

node__field_name
taxonomy_term__field_name

Apologies if this is a duplicate - I couldn't find any other issues that discussed this.

Drupal 8.5.5, observed on multiple sites.

Steps to reproduce

Proposed resolution

Update Reusing fields to correct that field can no longer be shared across entity types.

Remaining tasks

Review

User interface changes

API changes

Data model changes

Release notes snippet

Comments

millionleaves created an issue. See original summary.

millionleaves’s picture

Issue summary: View changes
johnpitcairn’s picture

You're certainly not alone noticing this. I think field definitions are now entity-type specific, whereas in Drupal 7 they were not.

The docs were probably just copied from Drupal 7 and need updating to indicate that in Drupal 8 you can only re-use a field among entities of the same type.

Version: 8.5.5 » 8.5.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.5.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. Branches prior to 8.8.x are not supported, and 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.

ey’s picture

Version: 8.9.x-dev » 9.1.x-dev
Priority: Normal » Major

I should state that this change really defeats the purpose of re-using fields, or at least drastically reduces the use cases. I am really disappointed to find out that it doesn't work as it was in Drupal 7 and it broke a lot of architectural designs in the concept that we made before starting to do a Drupal 8 upgrade for a big project.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

giorgio79’s picture

Yeah, why even have a separate entity for taxonomy when all the difference is that it provides a nice hiearchy goodies... Taxonomy is easily like any other node entity.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cilefen’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

Is this just a documentation bug?

ey’s picture

Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active

No, it's not a documentation bug.

Re-using fields between different entity types was possible in D7 and is not working in D8. You cannot, for example, create a field for a content type and reuse the same field on user accounts or taxonomy vocabularies in D8.

johnpitcairn’s picture

It's a regression from D7. Was there an explicit reason or decision to couple field storage or instance config to the parent entity type at some point in D8 development?

cilefen’s picture

Category: Support request » Bug report
Priority: Major » Normal
Issue tags: +Documentation
cilefen’s picture

I have no idea. I have only observed that this has been open for three years with no answer.

Has anyone following this issue perused the change records of that era? If there is a reason it could be recorded there.

johnpitcairn’s picture

Thanks @cilefen. I remember checking at the time and not finding anything:
https://www.drupal.org/list-changes/drupal/published?keywords_descriptio...

The only change notice mentioning "re-use" is this:
https://www.drupal.org/node/2393181

I can't search issues for keywords with a hyphen (no results), but trying to figure out whether there are issues that covered this during the 7.x-8.x development cycle is beyond me.

xurizaemon’s picture

Hi there

Please see changelog entry https://www.drupal.org/node/2078765 ... I guess "shareable" was the spelling of "re-use" you were looking for?!

Fields are no longer handled individually and are bound to an entity type

Fields are now bound to a specific entity type (they are still shareable between bundles) and the storage controller for that entity type handles the CRUD operation of the whole entity. It is possible to create fields named the same on different entity types, these will be completely separate fields not sharing their settings.

This should be remedied in the linked documentation then IMO.

xurizaemon’s picture

Status: Active » Needs work

NW for docs update.

Separately - I can't see how to make change record https://www.drupal.org/node/2078765 appear in the change records view. Maybe it's a bad node or something. The linked display ought to have that CR as the fourth listed item, since we're looking at 8.x records starting from just after that date? Same results searching for "bound", "shareable", "massive" etc.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review

I have updated the wiki page to clarify that sharing field across entity types is no longer possible. I think that covers everything here

I think that some one can review this and mark it fixed if the changes to doc page is sufficient.

lendude’s picture

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

Discussed this with @quiteone in #bugsmash and the new documentation looks good and in line with what Drupal 8+ actually does.

Thanks for reporting this and the feedback everybody.

Status: Fixed » Closed (fixed)

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