function _ref_field_field_settings_bundles in (Entity)Reference Field Synchronization 7
Set the bundle field for a ref_field
Parameters
$element: The form element to set field on
$entity: The entity which bundles are going to be the options
$has_data: (boolean) Whether the field has data any data. @see field_has_data().
3 calls to _ref_field_field_settings_bundles()
File
- ./
ref_field.module, line 122
Code
function _ref_field_field_settings_bundles(&$element, $entity, $has_data) {
$options = array();
$entity_info = entity_get_info($entity);
switch ($entity) {
case FALSE || NULL:
case 'comment':
break;
case 'taxonomy_term':
// Special case for taxonomy_term
// http://api.drupal.org/api/drupal/includes--entity.inc/function/EntityFieldQuery%3A%3AentityCondition/7
foreach ($entity_info['bundles'] as $bundle => $data) {
$vocabulary = taxonomy_vocabulary_machine_name_load($bundle);
$options[$vocabulary->vid] = $data['label'];
}
break;
default:
foreach ($entity_info['bundles'] as $bundle => $data) {
$options[$bundle] = $data['label'];
}
break;
}
if ($options) {
$warning = t('Changes made here might cause loss of data, use with caution.');
$description = t('Select the bundles you want to reference with this field. If none is selected, every bundle will be referenceable.');
$element = array(
'#title' => t('Bundles'),
'#description' => $has_data ? $warning . ' ' . $description : $description,
'#type' => 'select',
'#multiple' => TRUE,
'#default_value' => isset($field['settings']['bundles']) ? $field['settings']['bundles'] : '',
'#element_validate' => array(
'_ref_field_field_bundles_settings_form_validate',
),
'#options' => $options,
);
}
else {
$element = array();
}
}