Can I access field data with PHP code in a custom field using Display Suite Code?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jmaines's picture

Can I get a value in a node field in code? I want to use that code to make a decision on how to render an image or to determine which image will be displayed.

Using tokens doesn't work. I tried token_replace and token_scan, but they don't work. The $node variable is not available. $entity doesn't seem to contain node field data and I am not able to create a fully populated node.

I figured it out. I was making a syntax error while accessing $entity. I found it using Devel.

Thanks

Comments

Dynamic field

Lars Bo Jensen's picture

It sounds very much like a use case for a dynamic field, for which you select a view (assuming you are familiar with Views). Your view should take the id of your node or whatever you are working with as context filter and evaluate your field.

Thanks

jmaines's picture

I was wasn't using the correct syntax for the $entity object. Thanks to Devel, I was able to figure it out.
Thanks for your help.

Display Suite

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week