Controlling field must be visible on 'view' to hide the controlled fields

marcp - September 23, 2009 - 04:55
Project:Conditional Fields
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:fixed
Description

This block of code in hook_nodeapi() has some logic that I'm trying to understand:

<?php
     
// The controlled field is not in a group and is not in the form for other reasons. Skip.
     
if (!$controlled_group && !$node->content[$field['field_name']]) {
        continue;
      }

     
// The controlling field is not in a group and is not the form for other reasons. Skip.
     
if (!$controlling_group && !$node->content[$field['control_field_name']]) {
        continue;
      }

     
// The controlled field is in a group and is not the form for other reasons. Skip.
     
if ($controlled_group && !$node->content[$controlled_group]['group'][$field['field_name']]) {
        continue;
      }

     
// The controlling field is in a group and is not the form for other reasons. Skip.
     
if ($controlling_group && !$node->content[$controlling_group]['group'][$field['control_field_name']]) {
        continue;
      }
?>

I think the code is doing what it was designed to do -- if either the controlling field or the controlled field isn't visible in the form, then the code that follows, which hides controlled fields, doesn't get a chance to run.

The case that I'm concerned about is the one where the controlling field isn't visible (because it's configured in CCK not to appear in full node and/or teaser view). Even though it's not visible, I still want it to control the visibility of the controlled fields that are configured.

Now that I'm thinking about it -- why would any of those "skip" conditionals make sense? If a controlled field already isn't in the $node->content array, why would it matter if control passed down to the checks below? I suppose it's a performance gain in that case...

So, the question really is -- why must the controlling field be visible in order to hide the controlled fields?

And one last thing -- this module is AWESOME. I was making a last ditch effort to find some code to heist while implementing a small subset when I found this thing. Thanks for taking the time to contribute this module -- it is much appreciated.

#1

marcp - September 24, 2009 - 23:31

To simplify this -- I'm wondering about the 2 "controlling field" comments and their related logic:

      // The controlling field is not in a group and is not the form for other reasons. Skip.

and

      // The controlling field is in a group and is not the form for other reasons. Skip.

I think there's a missing word so "not the form" should read "not on the form" -- but what I'm wondering about is -- why should we care if the controlling field isn't being displayed on 'node view' (this code's not dealing with the form)?

#2

marcp - September 25, 2009 - 14:32
Category:support request» bug report

As I think about this I still can't come up with a good answer, so I'm pretty sure this is a bug. I will provide a patch.

#3

marcp - September 25, 2009 - 14:32
Title:Why must the controlling field be visible on 'view' to hide the controlled fields?» Controlling field be visible on 'view' to hide the controlled fields

#4

marcp - September 25, 2009 - 14:33
Title:Controlling field be visible on 'view' to hide the controlled fields» Controlling field must be visible on 'view' to hide the controlled fields

#5

marcp - October 27, 2009 - 22:06

Anyone care about this besides little ol' me?

#6

marcp - October 27, 2009 - 22:18
Status:active» needs review

Attached is a patch that fixes this bug ... if indeed it is a bug, which it seems like to me.

AttachmentSize
conditional_fields_issue_585280.patch 1.78 KB

#7

bonobo - October 30, 2009 - 04:47
Status:needs review» reviewed & tested by the community

The patch from #6 is working perfectly.

Changing status to reflect the testing we have put it through.

Is this module actively maintained? Some response in this thread would be a good sign.

#8

peterpoe - November 27, 2009 - 23:28
Status:reviewed & tested by the community» fixed

Fixed in dev, thanks. Don't even know why I put those two checks there.

@marcp: sorry for not mentioning your patch in CVS, I regret that I had forgotten that you had provided it already (I found the issue by myself when hunting another bug).
@bonobo: yes, the module is maintained, but not very frequently. I try to keep updating cycles once every few months. I hope in the near future to be able to update it more frequently.

#9

rburgundy - November 28, 2009 - 01:56

peterpoe - you are on a roll this week, thanks for all the updates/fixes!

 
 

Drupal is a registered trademark of Dries Buytaert.