I'm interested in generating a list of all fields with a column highlighting the feature that contains the field base setting and another column highlighting the field instance feature, (if the field is defined in a feature).

Something like this...

Field Name     |   Field Base Defined In  | Field Instance Defined In
field_subtitle |   mysite_shared_fields   | blog_story_feature
field_other    |   mysite_shared_fields   | blog_story_feature

Has anyone attempted this? Or can anyone suggest a solution.

  • Have you looked at {field_config} table? And hook_field_schema? It should give you idea where you don't have this data, and where you can have some of it. Not all, mind you. – Mołot Sep 27 '13 at 12:19
  • Thanks Molot, this is useful for getting the initial list. – chim Sep 27 '13 at 12:49

Some useful functions /snippets below


$features_map = features_get_component_map();

foreach (field_info_fields() as $key => $field) {
  $base = isset($features_map['field_base'][$key]) ? join(',',$features_map['field_base'][$key]) : 'NOT IN A FEATURE!';
  $instance = 'todo';
  $rows[] = array($key, $base, $instance);
print theme('table', array('header' => array('machine_name', 'base', 'instance'), 'rows' => $rows));

$components = features_get_components();
$field_base_component = $components['field_base'];
$field_instance_components = $components['field_instance'];
|improve this answer|||||

For older sites where field instances and sites are not stored separately in features

$features_map = features_get_component_map(NULL, TRUE);

// loop through field instances, this gives a deep array of
// content types...
foreach (field_info_instances() as $type => $bundles) {
  // ...containing bundles...
  foreach ($bundles as $bundle => $field) {
    // ...containing fields
    foreach($field as $field_name => $field_info) {
       // the key for the feature is...
       $features_instance_key = $type . '-' . $bundle . '-' . $field_name;  
       if ( isset($features_map['field'][$features_instance_key]) ) {
         $in_feature = join(',', $features_map['field'][$features_instance_key]);
       else {
         $in_feature = 'NOT IN A FEATURE';
       $instance_map[$field_name] = $in_feature;

foreach (field_info_fields() as $key => $field) {
  $rows[] = array($key, $instance_map[$key]);
print theme('table', array('header' => array('machine_name', 'feature'), 'rows' => $rows));
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.