Untitled

 avatar
unknown
plain_text
2 years ago
1.1 kB
5
Indexable
$query = db_select('field_config', 'fc')
  ->fields('fc', array('entity_type', 'bundle', 'field_name'))
  ->condition('fc.deleted', 0)
  ->condition('fc.entity_type', 'node')
  ->join('field_config_instance', 'fci', 'fci.field_name = fc.field_name AND fci.deleted = 0')
  ->fields('fci', array('label'))
  ->groupBy('fc.bundle')
  ->orderBy('fc.bundle');

// Execute the query.
$result = $query->execute();

// Process the query result.
$content_types = array();
foreach ($result as $row) {
  $content_type = $row->bundle;
  $field_name = $row->field_name;
  $field_label = $row->label;

  // Store content types and their fields in an array.
  $content_types[$content_type][] = array(
    'field_name' => $field_name,
    'field_label' => $field_label,
  );
}

// Output the content types and their fields.
foreach ($content_types as $content_type => $fields) {
  print "Content Type: $content_type\n";
  foreach ($fields as $field) {
    print "- Field Name: " . $field['field_name'] . "\n";
    print "  Field Label: " . $field['field_label'] . "\n";
  }
  print "\n";
}
Editor is loading...