Skip to main content

Field API

Displaying field values with formatting

Submitted by system on
Displaying data for any entity fields with formatting can be achieved with 2 simple drupal api. field_get_items: Returns the field items in the language they currently would be displayed. field_view_value: Returns a renderable array for a single field value. Example: <?php $status_field = field_get_items('node', $node, 'field_status'); print render(field_view_value('node', $node, 'field_status', $status_field[0])); ?> -- Source https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 https://api.drupal.org/api/drupal

Get list options of a field

Submitted by system on
We may want to get the options available for a field in content type. This can be achieved using Field API. <?php $blood_group_field = field_info_field("field_blood_group"); $blood_groups = list_allowed_values($blood_group_field); ?> where "field_blood_group" is the field machine name.

Creating exportable field definitions in Drupal 7

Submitted by amitsedai on
There are times when we would want to create similar data structures across multiple drupal sites for common functionalities. Although this can be done using features but when the effort involves one time exercise and involves just few fields to be exported, using custom code for creating export definitions for importing in the other site can be a simpler alternative. If you want export a field definition, you can use the handy field_info_field and field_info_instance functions.