field_ui_existing_field_options

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 field_ui_existing_field_options($entity_type, $bundle)

Return an array of existing field to be added to a bundle.

Code

modules/field_ui/field_ui.admin.inc, line 1489

<?php
function field_ui_existing_field_options($entity_type, $bundle) {
  $options = array();
  $field_types = field_info_field_types();

  foreach (field_info_instances() as $existing_entity_type => $bundles) {
    foreach ($bundles as $existing_bundle => $instances) {
      // No need to look in the current bundle.
      if (!($existing_bundle == $bundle && $existing_entity_type == $entity_type)) {
        foreach ($instances as $instance) {
          $field = field_info_field($instance['field_name']);
          // Don't show
          // - locked fields,
          // - fields already in the current bundle,
          // - fields that cannot be added to the entity type,
          // - fields that that shoud not be added via user interface.

          if (empty($field['locked'])
             && !field_info_instance($entity_type, $field['field_name'], $bundle)
             && (empty($field['entity_types']) || in_array($entity_type, $field['entity_types']))
             && empty($field_types[$field['type']]['no_ui'])) {
            $text = t('@type: @field (@label)', array(
              '@type' => $field_types[$field['type']]['label'], 
              '@label' => t($instance['label']), 
              '@field' => $instance['field_name'],
            ));
            $options[$instance['field_name']] = (drupal_strlen($text) > 80 ? truncate_utf8($text, 77) . '...' : $text);
          }
        }
      }
    }
  }
  // Sort the list by field name.
  asort($options);
  return $options;
}
?>