Last active
September 2, 2016 02:10
-
-
Save Morasta/4e07210209e15e1c4ae5 to your computer and use it in GitHub Desktop.
Drupal 7 - Hide labels for empty display suite fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_field_attach_view_alter(). | |
* | |
* Hide label of display suite fields if field content is empty. | |
*/ | |
function cof_directory_field_attach_view_alter(&$output, $context) { | |
$displaySuiteFields = array("graduate_students","office_location"); | |
foreach ($output as $field_name => $field) { | |
if (!empty($field['#label_display'])) { | |
$fieldText = "1"; | |
if (in_array($field_name, $displaySuiteFields)) { | |
$fieldText = trim(strip_tags($field[0]['#markup'])); | |
} | |
if(empty($fieldText) || (isset($field[0]['#markup']) && empty($field[0]['#markup']) && ($field[0]['#markup'] !== 0))) { | |
unset($output[$field_name]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to hide the entire field so that the empty divs won't be rendered.