function addtocal_field_formatter_settings_form in Add to Cal 7
Implements hook_field_formatter_settings_form().
File
- ./
addtocal.module, line 182 - addtocal.module General functions and hook implementations.
Code
function addtocal_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$bundle_name = $field['bundles'][$instance['entity_type']][0];
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$field_list = field_info_instances($instance['entity_type'], $bundle_name);
$description_options = $location_options = array(
'-1' => 'None',
);
$location_field_types = array(
'text',
'text_long',
'text_with_summary',
'addressfield',
);
$description_field_types = array(
'text',
'text_long',
'text_with_summary',
);
foreach ($field_list as $field_i) {
// Get the full field array
$field_i_full = field_info_field($field_list[$field_i['field_name']]['field_name']);
// Get its type
$field_i_type = $field_i_full['type'];
// Check for location/description compatibility, add to appropriate arrays.
if (in_array($field_i_type, $location_field_types)) {
$location_options[$field_i['field_name']] = $field_i['label'];
}
if (in_array($field_i_type, $description_field_types)) {
$description_options[$field_i['field_name']] = $field_i['label'];
}
}
$tokens_enabled = module_exists('token');
if ($tokens_enabled) {
$location_options['tokenize output'] = 'Use Tokens';
$description_options['tokenize output'] = 'Use Tokens';
}
$element['location'] = array(
'#type' => 'fieldset',
'#title' => t('Location'),
'#collapsible' => TRUE,
'#weight' => 0,
);
$element['location']['field'] = array(
'#title' => t('Location Field:'),
'#type' => 'select',
'#options' => $location_options,
'#default_value' => $settings['location']['field'],
'#description' => 'A field to use as the location for calendar events.',
'#weight' => 0,
);
$element['location']['tokenized'] = array(
'#title' => t('Tokenized Location Contents:'),
'#type' => 'textarea',
'#default_value' => isset($settings['location']['tokenized']) ? $settings['location']['tokenized'] : '',
'#description' => 'You can insert static text or use tokens (see the token chart below).',
'#weight' => 1,
);
$element['description'] = array(
'#type' => 'fieldset',
'#title' => t('Description'),
'#collapsible' => TRUE,
'#weight' => 1,
);
$element['description']['field'] = array(
'#title' => t('Description Field:'),
'#type' => 'select',
'#options' => $description_options,
'#default_value' => $settings['description']['field'],
'#description' => 'A field to use as the description for calendar events.<br />The contents used from this field will be truncated to 1024 characters.',
'#weight' => 0,
);
$element['description']['tokenized'] = array(
'#title' => t('Tokenized Description Contents:'),
'#type' => 'textarea',
'#default_value' => isset($settings['description']['tokenized']) ? $settings['description']['tokenized'] : '',
'#description' => 'You can insert static text or use tokens (see the token chart below).',
'#weight' => 1,
);
$element['past_events'] = array(
'#title' => t('Show Add to Cal widget for Past Events'),
'#type' => 'checkbox',
'#default_value' => $settings['past_events'],
'#description' => 'Show the widget for past events.',
'#weight' => 2,
);
$element['view_mode'] = array(
'#title' => t('You Should Not Be Able To See This'),
'#type' => 'hidden',
'#default_value' => $view_mode,
'#tree' => TRUE,
);
$element += date_field_formatter_settings_form($field, $instance, $view_mode, $form, $form_state);
$element['format_type']['#weight'] = 3;
$element['fromto']['#weight'] = 4;
$element['multiple_number']['#weight'] = 5;
$element['multiple_from']['#weight'] = 6;
$element['multiple_to']['#weight'] = 7;
if (module_exists('date_repeat_field')) {
$element['show_repeat_rule'] = array(
'#title' => t('Repeat rule:'),
'#type' => 'select',
'#options' => array(
'show' => t('Show repeat rule'),
'hide' => t('Hide repeat rule'),
),
'#default_value' => isset($element['show_repeat_rule']) ? $element['show_repeat_rule'] : 'hide',
'#access' => $field['settings']['repeat'],
'#weight' => 8,
);
}
if ($tokens_enabled) {
$element['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array(
'node',
),
// The token types that have specific context. Can be multiple token types like 'term' and/or 'user'
'#global_types' => TRUE,
// A boolean TRUE or FALSE whether to include 'global' context tokens like [current-user:*] or [site:*]. Defaults to TRUE.
'#click_insert' => TRUE,
// A boolean whether to include the 'Click this token to insert in into the the focused textfield' JavaScript functionality. Defaults to TRUE.
'#weight' => 9,
);
}
return $element;
}