In EntityFieldManager::buildBundleFieldDefinitions(), we have some supporting code for automatically setting a BaseFieldDefinition's name, entity type ID and bundle name. However, we don't do the same in EntityFieldManager::buildFieldStorageDefinitions().

This lead to an annoying "bug" on my end where I tried to declare a bundle field using FieldableEntityInterface::bundleFieldDefinitions() and its storage using hook_entity_field_storage_info(), providing both of them with the same BaseFieldDefinition. The dedicated table that got created for an unlimited cardinality field was named __FIELDNAME instead of ENTITYTYPEID__FIELDNAME because it couldn't find an entity type ID.

When Drupal tried to store data in that dedicated table, it correctly tried to store it in ENTITYTYPEID__FIELDNAME because it was able to properly get the table name from the field definition (not storage definition!) because we properly inform it of the entity type it's attached to in EntityFieldManager::buildBundleFieldDefinitions().

Proposed solution:
Also set the name and entity type ID in EntityFieldManager::buildFieldStorageDefinitions().

Comments

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.12 KB

Not sure if feature request or bug. Also changing the IS because we obviously want to set the entity type ID to the one we're currently retrieving storage definitions for. The only thing we might want to do is put the setName() call in an if-statement checking for any value in getName() and, when there is a name set, leave it like that.

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.

kristen pol’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs tests

I tested the patch on 9.1.x and it still applies cleanly. I see the similar code in EntityFieldManager::buildBundleFieldDefinitions. It seems like the only way to test this is with code so marking for tests.

ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB
new1.71 KB

Adding the required test. Please review! Thanks

Status: Needs review » Needs work

The last submitted patch, 8: 2927500-8.patch, failed testing. View results

kristiaanvandeneynde’s picture

@ridhimaabrol24 What is wrong with that interdiff? It seems like you moved the fix into the wrong place?

ridhimaabrol24’s picture

@kristiaanvandeneynde patch #8 is a reroll to the latest head of 9.1.x branch. The code has changed since drupal 8.4, hence you are seeing that difference.

kristiaanvandeneynde’s picture

Oh wow, never seen an interdiff for a reroll before. Thanks for clearing that up.

ridhimaabrol24’s picture

Yeah my mistake, shouldn't have added an interdiff for a reroll. Apology there.

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.34 KB

This should fix the broken test. I had to mock a base field definition specifically, rather than a generic FieldStorageDefinitionInterface, since the calls we're adding here are only done to base fields (and, indeed, only can be done to base fields).

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.

quietone’s picture

StatusFileSize
new1.62 KB
new2.34 KB

I reviewed the patch and it look good to me. I am uploading a fail patch and re-uploading the successful patch just to double check against 9.2.x

edit: s/reviews/reviewed/

The last submitted patch, 16: 2927500-14-fail.patch, failed testing. View results

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Tests are still passing, so off we go.

  • catch committed 9de43c2 on 9.2.x
    Issue #2927500 by quietone, ridhimaabrol24, kristiaanvandeneynde,...

  • catch committed ebc02f1 on 9.1.x
    Issue #2927500 by quietone, ridhimaabrol24, kristiaanvandeneynde,...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

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