I'm experiencing an error using Unique Field. I have a content type which contains a multiple value select list field where I've set it to be Unique. The module works as expected as long as you only use a single value, but the field for the content type can have multiple values.Unique Field stops checking that field and let's it through, even though it's not unique.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

umangamu created an issue. See original summary.

umangamu’s picture

Issue tags: +unique field
umangamu’s picture

umangamu’s picture

Status: Active » Needs review
rakesh.gectcr’s picture

Status: Needs review » Needs work

Thanks for the patch, Please add a little comment above your changes.

@@ -281,10 +281,25 @@ function unique_field_match_value($field, $values, $scope, $ntype = NULL, $nlang
         if (!strlen($val) || !is_scalar($val)) {
           continue;
         }
-        $efq->fieldCondition($field, $key, $val);
+        $field_values[] = array('key' => $key, 'val' => $val);
       }
     }
   }
+  if ($field_info->cardinality) {
+    $field_values = reset($field_values);
+    $val = $field_values['val'];
+    $key = $field_values['key'];
+    $efq->fieldCondition($field, $key, $val);
+  }
+  else {
+    $val = array();
+    $key = '';
+    foreach ($field_values as $k => $v) {
+      $val[] = $v['val'];
+      $key = $v['key'];
+    }
+    $efq->fieldCondition($field, $key, $val, 'IN');
+  }

and

foreach ($field_values as $k => $v) {

Please use little more descriptive varibales

aditya_anurag’s picture

Assigned: Unassigned » aditya_anurag
umangamu’s picture

umangamu’s picture