I was trying to figure out how to modify the #default_value of a CCK field inside my own #after_build hook. (See http://drupal.org/node/336355 ).
Without knowing the inner workings of CCK I figured this shouldn't be too tough so I had my function modify $element[0]['value']['#default_value'] to the value I wanted. Ahh... nothing happened.
Looking at the element array I also noticed the element $element[0]['#default_value']['value'] so I tried that. Hmmm... nothing. On a whim, I next tried modifying $element[0]['#value']['value'] and of course zip... nada.
After several more hours of pulling my hair out, I then tried modifying $element[0]['value']['#value'] and voila. It worked.
Let me recap. We have four different very similarly named array elements:
$element[0]['value']['#default_value']; // This doesn't affect the default value.
$element[0]['#default_value']['value']; // Nor does this.
$element[0]['#value']['value']; // Try again!
$element[0]['value']['#value']; // Clearly this is the one!
What's the most frustrating is that neither of the elements with key of '#default_value' ended up having anything to do with the default value. Well, at least at this stage anyhow.
I love CCK and can only being to comprehend the complexities involved with creating such a big module. I also understand this might be partly to blame on FAPI. But, I would like to make the humble suggestion that an effort is made to make things easy as possible for other modules to integrate with CCK.
Besides that, I can't even begin to imagine how you CCK developers manage to have a clue with what's going on when the situation is like this :-) .
Thanks for listening to my rant.
Comments
Comment #1
markus_petrux commentedAFAICT there's no other way to figure out the structure of each prior to coding these things.
PS: rants != f.r. :P