function user_reference_field_settings_form in References 7.2
Implements hook_field_settings_form().
File
- user_reference/
user_reference.module, line 52 - Defines a field type for referencing a user from a node.
Code
function user_reference_field_settings_form($field, $instance, $has_data) {
$path = drupal_get_path('module', 'references');
drupal_add_js($path . '/js/references.admin.js');
$settings = $field['settings'];
$options['user_reference_config_select_all_roles'] = t('Select all/none');
$options = $options + user_roles(TRUE);
$form = array();
$form['referenceable_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('User roles that can be referenced'),
'#default_value' => is_array($settings['referenceable_roles']) ? array_filter($settings['referenceable_roles']) : array(),
'#options' => $options,
);
$form['referenceable_status'] = array(
'#type' => 'checkboxes',
'#title' => t('User status that can be referenced'),
'#default_value' => is_array($settings['referenceable_status']) ? array_filter($settings['referenceable_status']) : array(
1,
),
'#options' => array(
1 => t('Active'),
0 => t('Blocked'),
),
);
if (module_exists('views')) {
$view_settings = $settings['view'];
$description = '<p>' . t('The list of users that can be referenced can provided by a view (Views module) using the "References" display type.') . '</p>';
// Special note for legacy fields migrated from D6.
if (!empty($view_settings['view_name']) && $view_settings['display_name'] == 'default') {
$description .= '<p><strong><span class="admin-missing">' . t("Important D6 migration note:") . '</span></strong>';
$description .= '<br/>' . t("The field is currently configured to use the 'Master' display of the view %view_name.", array(
'%view_name' => $view_settings['view_name'],
));
$description .= '<br/>' . t("It is highly recommended that you: <br/>- edit this view and create a new display using the 'References' display type, <br/>- update the field settings to explicitly select the correct view and display.");
$description .= '<br/>' . t("The field will work correctly until then, but submitting this form might inadvertently change the field settings.") . '</p>';
}
$form['view'] = array(
'#type' => 'fieldset',
'#title' => t('Views - Users that can be referenced'),
'#collapsible' => TRUE,
'#collapsed' => empty($view_settings['view_name']),
'#description' => $description,
);
$views_options = references_get_views_options('user');
if ($views_options) {
// The value of the 'view_and_display' select below will need to be split
// into 'view_name' and 'view_display' in the final submitted values, so
// we massage the data at validate time on the wrapping element (not
// ideal).
$form['view']['#element_validate'] = array(
'_user_reference_view_settings_validate',
);
$views_options = array(
'' => '<' . t('none') . '>',
) + $views_options;
$default = empty($view_settings['view_name']) ? '' : $view_settings['view_name'] . ':' . $view_settings['display_name'];
$form['view']['view_and_display'] = array(
'#type' => 'select',
'#title' => t('View used to select the users'),
'#options' => $views_options,
'#default_value' => $default,
'#description' => '<p>' . t('Choose the view and display that select the nodes that can be referenced.<br />Only views with a display of type "References" are eligible.') . '</p>' . t('Note:<ul><li>This will discard the "Referenceable Roles" and "Referenceable Status" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate users on user creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate users will be displayed.</li></ul>'),
);
$default = implode(', ', $view_settings['args']);
$form['view']['args'] = array(
'#type' => 'textfield',
'#title' => t('View arguments'),
'#default_value' => $default,
'#required' => FALSE,
'#description' => t('Provide a comma separated list of arguments to pass to the view.'),
);
}
else {
$form['view']['no_view_help'] = array(
'#markup' => '<p>' . t('No eligible view was found.') . '</p>',
);
}
}
return $form;
}