In #1801726: EntityFieldQuery v2 AddMetaData() was removed from EFQ.

In #1801304: Add Entity reference field we need to be able to add the Selection handler to the EFQ object, as later on in hook_query_TAG_alter() we want to let the Selection handler alter the sqlQuery for entity-access:

/**
 * Implements hook_query_TAG_alter().
 */
function entity_reference_query_entity_reference_alter(AlterableInterface $query) {
  $handler = $query->getMetadata('entity_reference_selection_handler');
  $handler->entityFieldQueryAlter($query);
}

Here's a gist with a clearer flow.

chx via IRC asked to file an issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

Title: Re-add AddMetaData to EFQ » Re-add addTag() and AddMetaData() to EFQ

Better title, to indicate addTag() is also required as we want to act only on "entity_reference" related queries.

chx’s picture

I hoped you will actually file a patch :) I will see what i can do.

amitaibu’s picture

Status: Active » Needs work
FileSize
2.19 KB

Very naive implementation. addMetadata seems to work, but addTag() not. Gonna dive a bit more into the code..

amitaibu’s picture

Status: Needs work » Needs review
FileSize
3.11 KB

Am I in the right direction? :)

chx’s picture

That looks quite good. It seems you are not adding metadata yet, it seems. And, do you think you could write a test for this? Perhaps flip a global in a field_test hook (because that module is already on) ?

amitaibu’s picture

FileSize
2.68 KB
5.09 KB

> do you think you could write a test for this?

Of course, that was the plan :) Patch with test.

Fabianx’s picture

Status: Needs review » Reviewed & tested by the community

Looks really good. Easy to see, test is good as well, works, same implementation as Select.php. => RTBC

One doc nitpick:

core/lib/Drupal/Core/Database/Query/Select.php has:

  /* Implementations of Drupal\Core\Database\Query\AlterableInterface. */

  public function addTag($tag) {

instead of:

+++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.phpundefined
@@ -239,4 +239,48 @@ public function tableSort(&$headers) {
+  /**
+   * Implements Drupal\Core\Entity\Query\QueryInterface::addTag().
+   */
+  public function addTag($tag) {

for each of those. I think it is nicer to know this is the implementation of the AlterableInterface than of the QueryInterface and it should be consistent.

amitaibu’s picture

FileSize
1.96 KB
5.13 KB

Addressing #7 -- @Fabianx, that's what you meant, right?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1828408-efq-tag-7.patch, failed testing.

amitaibu’s picture

Status: Needs work » Needs review
chx’s picture

Status: Needs review » Reviewed & tested by the community

Seems good.

Fabianx’s picture

Yup, #8: That was what I meant.

+1 for RTBC

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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