Problem/Motivation

#2232465: Deprecate table names from entity definitions will deprecate all the $entity_type->get(Base|Data|Revision|RevisionData)Table() methods, so we need to provide a replacement for them.

Proposed resolution

Add a getPrimaryTableName() method to TableMappingInterface.

Remaining tasks

Review/discuss.

User interface changes

Nope.

API changes

API addition, a new method on TableMappingInterface and an implementation in the default base class: DefaultTableMapping.

Data model changes

Nope.

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
StatusFileSize
new5.24 KB

Here's an initial patch.

Status: Needs review » Needs work

The last submitted patch, 2: 2960037.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new28.3 KB

This issue also depends on #2916018: Allow the table mapping to be initialized from outside the storage, so we need a combined patch for now.

tstoeckler’s picture

Wow, this is an AWESOME issue! Being able to condense our complex table setup into a single method call is pretty genius. Yay! This will be very very useful for Views but also Entity Query, etc.

+++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php
@@ -182,6 +182,19 @@ public function getFieldTableName($field_name) {
+    $primary_table_name = $this->dataTable ?: $this->baseTable;
+
+    if ($all_revisions && $this->entityType->isRevisionable()) {

Two thoughts:

  1. I think it's strange to "compute" the non-revision primary table name even if it's not going to be used. I think a if-else would be more readable here.
  2. I think the isRevisionable() is strange as we do not check isTranslatable() before using the (revision) data table. So I think we should either check both or neither.
amateescu’s picture

StatusFileSize
new5.19 KB
new28.26 KB
new847 bytes

Thanks @tstoeckler! It was actually @plach's idea in #2955442-10: Add a way to get all the tables in which a field is stored from TableMappingInterface.3, so I don't deserve all the credit :)

Re #5:

1. Sure thing, I don't mind doing an if-else instead.

2. The isRevisionable() check is needed because if you call this method on a non-revisionable entity type and pass $all_revisions = TRUE, the method will return an empty string. So I thought it should be more developer friendly and always return the correct table name.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 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.

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.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new152 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

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

arunkumark’s picture

Status: Needs work » Needs review
StatusFileSize
new5.32 KB

The patch has been rerolled for Drupal 10.1.x version.

smustgrave’s picture

Priority: Major » Normal
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs change record

Not sure this is a major anymore.

The new functions will need to be typehinted.

Also change record will be needed to announce the new function.

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.

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.