Problem/Motivation

In #2852067: Add support for rendering computed fields to the "field" views field handler a fix was added for computed fields in the views field handler. The filter handler needs this fix as well to be able to filter views on computed fields.

I ran into this while creating a search API based view that indexes a computed entity reference field. While trying to filter on the computed entity reference field, the filter options for entity references are not very useful. It would be nice to make the entity references work like TaxonomyIndexTid. This is being fixed in #2429699: Add Views EntityReference filter to be available for all entity reference fields.

This does not automatically work for computed entity reference fields. I traced this to \Drupal\views\FieldAPIHandlerTrait::getFieldStorageDefinition(). This method should also return the computedd base fields.

Proposed resolution

Work for this started in #2852067: Add support for rendering computed fields to the "field" views field handler but since that issue originally intended to fix only the field handler, this is a follow up to make the fix more generic. I would propose the move the code in EntityField::getFieldStorageDefinition() to FieldAPIHandlerTrait::getFieldStorageDefinition().

Remaining tasks

Discuss the proposed patch.
Add tests.

User interface changes

API changes

Data model changes

Comments

seanB created an issue. See original summary.

seanb’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new4.27 KB

Proposed solution.

lendude’s picture

Component: views.module » field system
Issue tags: +VDC
+++ b/core/modules/views/src/FieldAPIHandlerTrait.php
@@ -45,17 +45,37 @@ protected function getFieldDefinition() {
-   * @return \Drupal\field\FieldStorageConfigInterface
...
+   * @return \Drupal\Core\Field\FieldStorageDefinitionInterface

So we are changing the return type here, but we are just making it a little more generic since FieldStorageConfigInterface extends FieldStorageDefinitionInterface. Since the method name already promises getFieldStorageDefinition, making it return a FieldStorageDefinition sounds very reasonable to me.
But it is an API change I guess. So that would need a CR.

The fix doesn't really align well with the title and IS here. It's nice that this also fixes the described issue but the fix does more then that. I would update the title and point out that this is removing a workaround in one Views plugin and making it a generic fix.

Since this is currently a fix in field, lets move it there to start with.

seanb’s picture

Title: Useful filtering like TaxonomyIndexTid for computed entity reference fields » Return computed fields in FieldAPIHandlerTrait::getFieldStorageDefinition()
Issue summary: View changes

Updated the IS and title. Todo:

  • Add tests
  • Create CR
borisson_’s picture

Status: Needs review » Needs work

NW based on #4.

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.

twod’s picture

This also needs to support bundle fields like in #2981047: Allow adding computed bundle fields in Views.

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.

rjacobs’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Needs work » Needs review
StatusFileSize
new4.28 KB

Re-rolling #2 for interim reference against 8.7.x-dev. Temporarily adjusting version and status to trigger testbot.

Status: Needs review » Needs work

The last submitted patch, 9: 2936737-9.patch, failed testing. View results

rjacobs’s picture

StatusFileSize
new5.04 KB

Oops. It looks like service support for the Entity Manager was dropped in views test classes for 8.7 onward. Here's another attempt at re-rolling #2 against 8.7.x-dev.

rjacobs’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Needs work » Needs review
StatusFileSize
new4.31 KB

Back to 8.8.x-dev. Here's a re-roll of #2 for that as well.

rjacobs’s picture

Status: Needs review » Needs work

Back to needs work based on #3-5

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.

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.

chewi3’s picture

StatusFileSize
new5.26 KB

Rerolled latest patch for 10.3.

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.