I am writing a module that needs to change the label for specific fields, without changing the database value for the label of the fields.

This can easily be done with hook_nodeapi().
When changing the field settings while $op = 'view', whatever value I try to put in '#title' does not end up on the resulting page.
I was able to confirm that if I changed other fields settings, such as '#label_display', the change does end up on the resulting page.

After some extended research, I found out that the problem is that the content_preprocess_content_field() function does not use the title field that is stored in the $element variable, but instead a fresh copy pulled from the database (while #label_display is pulled from the #element variable). This means that no module is currently allowed to change the label for a given field for the view operation.

I have supplied a patch that uses the $element variable just like the '#label_display' uses the $element variable.
Please Review and consider applying.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grayside’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Makes sense. Wish I had it now.

Yes, I could create a template just to override the label, but that's a lot of work where a very simple hook_nodeapi() can tweak the different usability needs of content creators and content viewers.

sradomski’s picture

I second the need for this. It is at least unintuitive, that you can use hook_nodeapi($op = view) to alter the title of "native" fields, but not for cck widgets. I run into this problem constantly e.g. for plural/singular distinctions.

micahw156’s picture

Patch applied cleanly to 6.x-2.9 and worked as expected.

It makes sense that the behavior of #title and #label_display would be consistent, and this patch makes it so.