Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bulat’s picture

bulat’s picture

joachim’s picture

Status: Needs review » Needs work

What's the difference between the two patches you've posted?

bulat’s picture

No difference, second has my drupal username and email. Unfortunately I don't know of a way to delete a comment here.

joachim’s picture

Status: Needs work » Needs review

Ah right. Will review when I have a bit more time then :)

(For future reference, you can edit one of your own comments, for instance to say that it's posted in error.)

bulat’s picture

Good tip, thanks

joachim’s picture

Status: Needs review » Needs work

I'm actually rather confused by what this patch is changing:

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
-    // Convert flag machine names to flag IDs.
-    $flags = flag_get_flags();
-    $fids = array();
-    if (is_array($conditions['bundle']['value'])) {
-      foreach ($conditions['bundle']['value'] as $flag_name) {
-        $fids[] = $flags[$flag_name]->fid;
-      }
-    }
-    else {
-      $flag_name = $conditions['bundle']['value'];
-      $fids = $flags[$flag_name]->fid;
-    }
-
-    $query->propertyCondition('fid', $fids, $conditions['bundle']['operator']);

Why is this getting removed?

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
+    $query->addTag('flagging_flag_names');
...
+ * Implements hook_query_TAG_alter() for flagging_flag_names tag.
+ */
+function flag_query_flagging_flag_names_alter (QueryAlterableInterface $query) {
+    $value = $query->getMetaData('flag_name_value');
+    $operator = $query->getMetaData('flag_name_operator');
+    $query->join('flag', 'f', 'flagging.fid = f.fid');
+    $query->condition('f.name', $value, $operator);  ¶
 }

I don't understand what this is all about. Needs comments!

+++ b/tests/flag.test
@@ -860,3 +860,91 @@ class FlagHookFlagAccessTestCase extends FlagTestCaseBase {
+class FlagEntityFieldQueryTestCase extends FlagTestCaseBase {

Class needs a docblock, and so do its functions and properties. Spacing is needed between them.

Also, your patch has a lot of whitespace issues!

bulat’s picture

Well, I guess I will try to explain it here before adding comments and fixing whitespace.

1. code is removed because it is not working for LIKE operator.
2. flag_query_flagging_flag_names_alter joins query object build by EntityFieldQuery to flag table and adds condition from 'bundle' of EFQ to name field of flag table.

joachim’s picture

> 1. code is removed because it is not working for LIKE operator.

Yes, but it's needed for other reasons!

bulat’s picture

I wrote test to show that it works without this code.

bulat’s picture

Status: Needs work » Needs review
FileSize
5.25 KB

Trailing spaces removed.

joachim’s picture

Getting there!

Still needs comments. As a maintainer, I want to be able to look at this code in a year's time when I get a bug report about it, and read the comments to understand what it does -- not interpret the code like I'm a human PHP compiler!

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
  * Converts EntityFieldQuery instances on flaggings that have an entity
  * condition on bundles (flag machine names).

This is no longer strictly true.

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
+    $query->addMetaData('flag_name_value', $conditions['bundle']['value']);
+    $query->addMetaData('flag_name_operator', $conditions['bundle']['operator']);
+    $query->addTag('flagging_flag_names');

These lines seem to be:

- adding the query tag for hook_query_TAG_alter() to act on
- adding metadata for that function to find.

They should also go in the more logical order of adding the tag first, then the things it needs.

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
+/**
+ * Implements hook_query_TAG_alter() for flagging_flag_names tag.
+ */
+function flag_query_flagging_flag_names_alter (QueryAlterableInterface $query) {

This should say that it does the work for allowing fids to be used in EFQs.

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
+    $value = $query->getMetaData('flag_name_value');
+    $operator = $query->getMetaData('flag_name_operator');

These lines are pulling the metadata out of the query that we stashed back in flag_entity_query_alter().

+++ b/flag.module
@@ -142,30 +142,28 @@ function flagging_save($flagging) {
+    $query->join('flag', 'f', 'flagging.fid = f.fid');
+    $query->condition('f.name', $value, $operator);

This joins onto the {flag} table so we can add the query conditions on the flag fid.

bulat’s picture

bulat’s picture

@joachim is there any chance for this patch to be integrated?

joachim’s picture

Status: Needs review » Fixed
FileSize
5.73 KB

Yup, sorry for the delay.

I fixed a few things:

- added @see statements to the two hook implementations, as they work in tandem
- missing docblocks on class and methods in the test
- indentation problems
- typos
- removed the private $flag1 in the test class, as there's also $flag2 and $flag3 which aren't declared, so it seems inconsistent.

Here's the modified patch, which I've committed.

Thanks!

git commit -m "Issue #2021191 by bulat: Added support for LIKE and IN operators on flagging entity bundle condition in EntityFieldQuery." --author="bulat "

bulat’s picture

Cool, thanks!

Status: Fixed » Closed (fixed)

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