[support] Entity_metadata_wrapper: Does field have data?

Lucas D Hedding lucashedding at gmail.com
Mon Aug 12 17:48:58 UTC 2013


Nancy, I tend to do the following (using body as an example) in pseudo
standard data import script.

$body = $wrapper->body->value();
if (empty($body)) {
  // Do something, for example set a value to avoid Undefined variable
notices
  $wrapper->body->set(array('value' => ''));
}
// Now I can deal with the data as if it were populated.
if ($wrapper->body->value->raw() != $this->Body) {
  $wrapper->body->set(array('value' => $this->Body, 'format' =>
'full_html'));
}


Lucas
MTech, LLC <http://www.mtechinformationsolutions.com>


On Mon, Aug 12, 2013 at 12:25 PM, Nancy Wichmann <nan_wich at bellsouth.net>wrote:

> With fields I often do:
>   if ($vca = field_get_items('node', $node, 'field_corresponding_vca')) {
>
> This makes sure there is some data before trying to do anything with it.
>
> But I've searched all over the place and even dug into the code. How do
> you do this with entity_metadata_wrapper? I want to give the users an error
> message that means something to them, and sometimes just set the value to
> zero.
>
> I see that the Entity module has a protected function called
> "dataAvailable" but I can't use a protected function.
>
> *Nancy*
> Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L.
> King, Jr.
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20130812/e68ba4ea/attachment.html 


More information about the support mailing list