Returns an array of existing fields to be added to a bundle.
array An array of existing fields keyed by field name.
protected function getExistingFieldOptions() {
$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 == $this->bundle && $existing_entity_type == $this->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($this->entity_type, $field['field_name'], $this->bundle) && (empty($field['entity_types']) || in_array($this->entity_type, $field['entity_types'])) && empty($field_types[$field['type']]['no_ui'])) {
$widget = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')
->getComponent($instance['field_name']);
$info[$instance['field_name']] = array(
'type' => $field['type'],
'type_label' => $field_types[$field['type']]['label'],
'field' => $field['field_name'],
'label' => $instance['label'],
'widget_type' => $widget['type'],
);
}
}
}
}
}
return $info;
}