function field_ui_existing_field_options

Returns an array of existing fields to be added to a bundle.

1 call to field_ui_existing_field_options()
field_ui_field_overview_form in modules/field_ui/field_ui.admin.inc
Form constructor for the 'Manage fields' form of a bundle.

File

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

Code

function field_ui_existing_field_options($entity_type, $bundle) {
    $info = 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 should 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'])) {
                        $info[$instance['field_name']] = array(
                            'type' => $field['type'],
                            'type_label' => $field_types[$field['type']]['label'],
                            'field' => $field['field_name'],
                            'label' => $instance['label'],
                            'widget_type' => $instance['widget']['type'],
                        );
                    }
                }
            }
        }
    }
    return $info;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.