function ctools_fields_get_field_formatter_settings_form in Chaos Tool Suite (ctools) 7
Helper function for calling hook_field_formatter_settings_form() without needing to load an instance of the field.
Parameters
$field: A fully loaded field.
$formatter_type: The formatter key selected from the options provided by field_ui_formatter_options().
$form: The full form from the function that's calling this function.
$form_state: The full form_state from the function that's calling this function.
$view_mode: We're passing a view mode from this function to the fake instance we're creating. Defaults to ctools, but we expect developers to actually name this something meaningful.
1 call to ctools_fields_get_field_formatter_settings_form()
- ctools_entity_field_content_type_formatter_styles in plugins/
content_types/ entity_context/ entity_field.inc
File
- includes/
fields.inc, line 70 - Extend core fields with some helper functions to reduce code complexity within views and ctools plugins.
Code
function ctools_fields_get_field_formatter_settings_form($field, $formatter_type, &$form, $form_state, $view_mode = 'ctools') {
$conf = $form_state['conf'];
$formatter = field_info_formatter_types($formatter_type);
if (isset($formatter['settings'])) {
$conf['formatter_settings'] += $formatter['settings'];
}
$function = $formatter['module'] . '_field_formatter_settings_form';
$instance = ctools_fields_fake_field_instance($field['field_name'], $view_mode, $formatter_type, $conf['formatter_settings']);
if (function_exists($function)) {
$settings_form = $function($field, $instance, $view_mode, $form, $form_state);
}
if (empty($settings_form)) {
$settings_form = array();
}
// Allow other modules to alter the formatter settings form.
$context = array(
'module' => $formatter['module'],
'formatter' => $formatter,
'field' => $field,
'instance' => $instance,
'view_mode' => $view_mode,
'form' => $form,
'form_state' => $form_state,
);
drupal_alter('field_formatter_settings_form', $settings_form, $context);
$settings_form['#tree'] = TRUE;
$form['ctools_field_list']['#value'][] = $field;
$form += $settings_form;
if (isset($field['cardinality']) && $field['cardinality'] != 1) {
list($prefix, $suffix) = explode('@count', t('Skip the first @count item(s)'));
$form['delta_offset'] = array(
'#type' => 'textfield',
'#size' => 5,
'#field_prefix' => $prefix,
'#field_suffix' => $suffix,
'#default_value' => isset($conf['delta_offset']) ? $conf['delta_offset'] : 0,
);
list($prefix, $suffix) = explode('@count', t('Then display at most @count item(s)'));
$form['delta_limit'] = array(
'#type' => 'textfield',
'#size' => 5,
'#field_prefix' => $prefix,
'#field_suffix' => $suffix,
'#description' => t('Enter 0 to display all items.'),
'#default_value' => isset($conf['delta_limit']) ? $conf['delta_limit'] : 0,
);
$form['delta_reversed'] = array(
'#title' => t('Display in reverse order'),
'#type' => 'checkbox',
'#default_value' => !empty($conf['delta_reversed']),
'#description' => t('(start from last values)'),
);
}
}