In previous dev versions of Conditional Fields, I was able to make a field unavailable using the "Field Permissions" module and ensuring that "Hide the dependent if the dependee is not in the form" was checked.

In the current dev version, I get the following errors when I try to to add content to an affected content type when the dependee is unavailable to the role in question:

Notice: Undefined index: field_target_or_actual in conditional_fields_form_after_build() (line 436 of /var/www/dev/ppnyc/sites/all/modules/conditional_fields/conditional_fields.module).
Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be an array, null given, called in /var/www/dev/ppnyc/sites/all/modules/conditional_fields/conditional_fields.module on line 437 and defined in drupal_array_get_nested_value() (line 6348 of /var/www/dev/ppnyc/includes/common.inc).
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

Status: Active » Needs review
FileSize
3.63 KB

I have the same issue (with OG field access).
This patch fixes this. I've changed:

<?php
$dependee = $dependency['dependee'];
$dependee_info = $form['#conditional_fields'][$dependee];
?>

Into:

<?php
$dependee = $dependency['dependee'];
// If the dependee is not part of the form (due to permissions),
// continue to the next conditional field.
if (!isset($form['#conditional_fields'][$dependee])) {
  continue;
}
$dependee_info = $form['#conditional_fields'][$dependee];
?>

The rest of the patch is just Drupal Code styling (removed unneeded spaces after some lines).

peterpoe’s picture

Status: Needs review » Fixed

This was fixed in commit 890c237.

Status: Fixed » Closed (fixed)

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

warmth’s picture

Status: Closed (fixed) » Active

Sorry but this doesn't seem to be completely fixed. I hid the main dependee (using Field Permissions) for all the users but anonymous so they can only select that option when they are signing up but no longer change it when they try to edit their profiles, because that auto assign the role.

The registration process go perfectly but when they go to edit their profile, where the main dependee is hidden, the dependents are all showed and if they are required the user won't be able to save their profile changes without filling them up. I tested making the dependee visible and then all the depedents are correctly hidden and toggled when editing but that way the users can change the main dependee but their role won't change, so I will be in troubles. Please help me.

albert9000’s picture

Okay this sounds simple but it works.

Broken example:

[required dependent] is invisible when [dependee] has at least one of the values: option1, option2.

Working example:

[required dependent] is visible when [dependee] has none of the values: option1, option2.

This is a reversal of thinking but it works.

theo_’s picture

I faced a similar issue where conditional fields doesn't apply when user doesn't have edit access to the dependent field.

To reproduce:
* Setup a conditional field: dependent field is be visible when dependee field has value [option1], also check "Hide the dependent if the dependee is not in the form"
* Using Field Permissions, remove access to edit own dependent field
* Go to creation form, notice that (dependent) field is always displayed and conditional fields doesn't applied even when dependee field has value [option1]

I found that this bug occur in conditional_fields_form_after_build() this function is in charge of applying conditional field on creation forms. It uses drupal_array_get_nested_value() to retrieve and alter the dependent field but it his not modified back into the form using drupal_array_set_nested_value() because when you don't have access to the field is just skip this step.

Here is a patch which fix the issue

theo_’s picture

Component: Compatibility w/ other modules » Code
Status: Active » Needs review

The last submitted patch, 1: conditional_fields-1269602-field_level_permissions.patch, failed testing.

kenorb’s picture

kenorb’s picture

omarlopesino’s picture

Patch #6 worked for me.
I upload a reroll from last version and add a change: wrap the states mapping into a condition which check states are not empty.

Thanks!

kenorb’s picture

Patch #12 seems to work. It suppress the mentioned fatal error.

kenorb’s picture

Potential workaround in conditional_fields.module:

@@ -1038,7 +1038,7 @@ function conditional_fields_evaluate_dependencies($dependent, $form, $form_state
     // part of the value. So we find the depth of the field inside the form
     // structure and use the parents only up to that depth.
     $dependee_parents_keys = array_flip($dependee_parents);
-    $dependee_parent = drupal_array_get_nested_value($form, array_slice($dependee_parents, 0, $dependee_parents_keys[$dependee]));
+    $dependee_parent = drupal_array_get_nested_value($form, (array) array_slice($dependee_parents, 0, $dependee_parents_keys[$dependee]));
     $values = conditional_fields_form_field_get_values($dependee_parent[$dependee], $form_state);
anrikun’s picture

Status: Needs review » Needs work

Patch at #12 doesn't work for me.
Without the patch, all the dependents are visible.
But with the patch, all the dependents are hidden, even the ones that should be visible based on the value of the non-accessible dependee.

svimjam’s picture

The patch is not working for me.

My issue is :

1. I have created a KBArticle (Custom content-type), this KBArticle has 4 domains (D1, D2,D3, D4) & 4 taxonomies (T1, T2, T3, T4).
I have used conditional Fields to show taxonomy. When user selects Domain D1, then T1 taxonomy should be shown to user.
When the user selects D2 domain, then T2 should be visible. I have created a role which has access to only D1 domain. my expectation is when the user tries to create a KBArticle user is seeing T2, T3, T4 along with T1.
The expectation is user should only see T1 since D2, D3, D4 are not even there on the Form.

Can someone please help me.

Thanks
Srikanth

svimjam’s picture

FileSize
56.56 KB
MustangGB’s picture

Why not just move drupal_array_set_nested_value() a bit higher, so the $dependent_form_field['#access'] = FALSE; gets set?

i.e.

  function conditional_fields_form_after_build($form, &$form_state) {
    ...
    unset($behaviors);

+   // Save the modified field back into the form.
+   drupal_array_set_nested_value($form, $dependent_location, $dependent_form_field);

    if (empty($states)) {
      continue;
    }

-   // Save the modified field back into the form.
-   drupal_array_set_nested_value($form, $dependent_location, $dependent_form_field);

    // Map the states based on the conjunctions.
    $states_new = array();
    ...
  }
dqd’s picture

Status: Needs work » Closed (outdated)

Thanks for the report and all the efforts in here. But due to inactivity in this issue for some years and because of the upcoming EOL of Drupal 7, I will close this issue on the way by cleaning up the issue queue.

Feel free to re-open as "Needs review" if you found a solution or have a patch to be reported to help others on this outdated version.

If you think this issue or missing feature should be addressed in a newer Drupal core 8 and above compatible version of this project, then please file a new issue to the latest dev.