Skip to content

Instantly share code, notes, and snippets.

@signalpoint
Created October 29, 2018 17:58
Show Gist options
  • Save signalpoint/35994bf20a4f65649da88bcbb707cfa3 to your computer and use it in GitHub Desktop.
Save signalpoint/35994bf20a4f65649da88bcbb707cfa3 to your computer and use it in GitHub Desktop.
Drupal 7 Check if Body is Empty with EntityMetadataWrapper
<?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