I don't get which condition should be applied when checking uniqueness of field which is a single value, which is inside multi value field collection item.

Setup--
Field collection Item - field_developer
----Name -field_name - EntityReference - Autocomplete - single value for each fci delta.
----Role in Module - Term Reference - AutoComplete - Multi value

Ex.
FCI[0]
----Name - tedbow
----Role - Intial Developer,Maintainer
FCI[1]
----Name - g089h515r806
----Role - Commiter
FCI[3]
----Name - himerus
----Role - Themer, Commiter
FCI[4]
----Name - g089h515r806 <-- this value should not be set here, as it breaks unique validation.
----Role - Tester

What I tested?

I have checked by applying
1. Field Collection Unique to field_name - Not Triggering error allowing unique values.
2. Unique values to field_name with scope bundle - Doesn't trigger allowing unique values, but not allowing to submit more than once(forcefully making it global).
3. Unique values to field_name with scope entity - Doesn't trigger allowing unique values but not allowing next node creation(forcefully making it global)

Some Observation
for above (2)
dpm($this->entity) inside field_validation_unique_validator.inc showing FieldCollectionItemEntity field_developer , although validation is applied to it's child field_name .

Comments

nithinkolekar’s picture

Issue summary: View changes
nithinkolekar’s picture

Issue summary: View changes
nithinkolekar’s picture

Issue summary: View changes
nithinkolekar’s picture

By checking field_validation_field_collection_unique_validator.inc it found out that FieldCollectionItem delta is passing for validation.
Before call was made from field_validation.module, only delta element are chosen making it unaware of possible duplicate values on other delta items.

foreach ($items as $delta => $item) {
          $value = isset($item[$rule->col]) ? $item[$rule->col] : '';
          $validator = new $class($entity_type, $entity, $field, $instance, $langcode, $items, $delta, $item, $value, $rule, $errors);
          if ($validator->bypass_validation()) {
             break;
          }
          $break = $validator->validate();
          if (!empty($break)) {
            break;
          }

I tried using "PHP code" method to traverse back to get parent item and iterate through Field collection items but couldn't success :(.

As field collection itself is a field and if it set to hold multiple or umlimited values,then while applying validation it should be good to set something like
value of field_name under this field collection delta(ex. fci[0]) should not hold same value more than once throughout the scope of multiple field collection (ex all remaining deltas like fci[1]...fci[n]).

adriancid’s picture

nithinkolekar’s picture

@adriancid That solution is working fine and good for limited no field collections. If no of fields increases then we have add machine name of that field manually which is hardcoded.
As for this module is concern field_validation_unique_validator.inc which is for "unique values", which has almost everything which is needed ie
Entity type - Field Collection
Bundle - field_collection_field
Field - Er reference field
Value - target_id
Scope - Bundle

This is only checking validation to
all ER reference field values inside current field_collection_item[delta]
instead of
every ER reference field that is available in all field_collection_item[0] .... field_collection_item[n]

Another validation "Field collection unique" is available but it not for checking child field values and there is no scope option either.

Kris77’s picture

@nithinkolekar you have find a solution?

I have the same problem too.

Thanks