function get_fields($bundle_name) { $fields = field_read_fields(array('entity_type' => 'node', 'bundle' => $bundle_name)); $result = array(); foreach ($fields as $name => $field) { $result[$name] = array('type' => $field['type'], 'card' => $field['cardinality']); // FIELD_CARDINALITY_UNLIMITED = -1 $f_type = trim($field['type']); $vocab = ""; $sub = ""; $active = ""; if ($f_type == 'taxonomy_term_reference') { $vocab = $field['settings']['allowed_values'][0]['vocabulary']; if (!empty($vocab)) { $result[$name]['vocab'] = $vocab; } $sub = empty($field['settings']['subtype']) ? get_taxon_subtype($name) : $field['settings']['subtype']; //$sub = $field['settings']['subtype']; //if(empty($sub)) $sub = get_taxon_subtype($name); } if ($f_type == 'text') { $sub = empty($field['settings']['subtype']) ? get_text_subtype($name) : $field['settings']['subtype']; //if(empty($sub)) $sub = get_text_subtype($name); } $result[$name]['subtype'] = $sub; // for every field $active_value = empty($field['settings']['active']) ? get_active($name) : $field['settings']['active']; //$active_value = $field['settings']['active']; //if(empty($active_value)) $active_value = get_active($name); if ($active_value == 'enable') { $result[$name]['active'] = true; } else { $result[$name]['active'] = false; } $instance = _get_field_instance($bundle_name, $name); $result[$name]['label'] = $instance['label']; } //mylog(print_r($fields, true), 'fields.txt'); //mylog(print_r($result, true), 'result.txt'); return $result; }
/** * Private callback to process compact and teaser node view modes. * * @param array $variables * Standard variables array */ function _govcms_zen_process_node_compact_teaser(&$variables) { $fields = field_read_fields(array('entity_type' => 'node', 'bundle' => $variables['type'])); foreach ($fields as $field_name => $field_settings) { if ($field_settings['type'] == 'image') { if (isset($variables['content'][$field_name])) { $children = element_children($variables['content'][$field_name]); if (!empty($children)) { $limited = $variables['content'][$field_name][0]; foreach ($children as $child_index) { unset($variables['content'][$field_name][$child_index]); } $variables['content'][$field_name][0] = $limited; } } } } }
public static function readFieldByID($id, $include_deleted = TRUE, $include_inactive = TRUE) { $fields = field_read_fields(array('id' => $id), array('include_deleted' => $include_deleted, 'include_inactive' => $include_inactive)); return !empty($fields) ? reset($fields) : FALSE; }