Greetings,

I feel like it's a bit of an akward design that when in a template you decide to hide a field to render it later it adds an entry in the array: [#printed] => 1.
Because after hidding you cannot use the empty($content['field']) to verifiy if the field is filled or not, as the array will not be empty anymore because of the #printed.

Had to make a function to check that the array was not empty nor equal to Array ('[#printed]' => '1' ).

Comments

mattdanger’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new388 bytes

Agree that the current implementation of hide() could be a little better. I'm experiencing a similar problem where empty($content['field_name']) will return FALSE when the field is empty because hide($content['field_name']) sets the previously empty render array to #printed => TRUE.

I've attached a patch using a method suggested by @arne_hortell in this comment.

Status: Needs review » Needs work

The last submitted patch, 1: drupal-hide_only_existing_elements-1184756-1.patch, failed testing.

Version: 7.0 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.