Created
October 29, 2018 17:58
-
-
Save signalpoint/35994bf20a4f65649da88bcbb707cfa3 to your computer and use it in GitHub Desktop.
Drupal 7 Check if Body is Empty with EntityMetadataWrapper
This file contains 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
<?php | |
// Load the node and wrap it. | |
$node = node_load(123); | |
$wrap = entity_metadata_wrapper('node', $node); | |
// Make sure the body isn't empty, and then sanitize it. | |
// We use field_get_items() because we couldn't figure out how to use EMW's __isset() on the body field. | |
$body = field_get_items('node', $node, 'body') ? | |
$wrap->body->value->value(array('sanitize' => TRUE)) : ''; | |
drupal_set_message($body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment