function _addthis_settings_form in AddThis 7.4
Create a addthis settings form.
1 call to _addthis_settings_form()
- addthis_form_block_admin_configure_alter in includes/
addthis.block.inc - Implements hook_form_FORM_ID_alter().
File
- ./
addthis.module, line 232
Code
function _addthis_settings_form($form = array(), &$form_state = array(), $display_type = NULL, $display_settings = array()) {
// Check display setting to be not empty or something else then an array.
if (empty($display_settings) || !is_array($display_settings)) {
$display_settings = array();
}
// Toggle variables.
$no_js = FALSE;
// Default display type if not set in the parameters.
$display_type = isset($display_type) ? $display_type : 'addthis_disabled';
// Load setting type from the form_state.
if (isset($form_state['values']['addthis_settings']['type'])) {
$display_type = $form_state['values']['addthis_settings']['type'];
}
// Container used as the replace for ajax.
$form['#type'] = 'container';
$form['#attributes'] = array();
$form['#id'] = 'addthis_settings';
// The list of formatters.
$formatter_options = AddThis::getInstance()
->getDisplayTypes();
$form['type'] = array(
'#type' => 'select',
'#title' => t('Formatter for @title', array(
'@title' => 'AddThis block',
)),
'#title_display' => 'invisible',
'#options' => $formatter_options,
'#default_value' => $display_type,
'#parents' => array(
'addthis_settings',
'type',
),
'#attributes' => array(
'class' => array(
'addthis-display-type',
),
),
'#ajax' => array(
'callback' => '_addthis_settings_form_submit_callback',
'wrapper' => 'addthis_settings',
'name' => 'switch_display',
'event' => 'change',
),
);
if ($no_js) {
$form['choose'] = array(
'#type' => 'submit',
'#name' => 'Switch display',
'#value' => 'Switch display',
'#op' => 'switch_display',
'#id' => 'switch-display',
'#submit' => array(
'_addthis_settings_form_submit',
),
);
}
// Formatter settings.
// Check the currently selected formatter, and merge persisted values for
// formatter settings.
$formatter_type = $display_type;
// Get the settings if set.
$settings = $display_settings;
$formatter_settings = field_info_formatter_settings($formatter_type);
$settings += $formatter_settings;
$field = array();
$instance = array();
$view_mode = 'block';
$instance['display'][$view_mode]['type'] = $formatter_type;
$formatter = field_info_formatter_types($formatter_type);
$instance['display'][$view_mode]['module'] = $formatter['module'];
$instance['display'][$view_mode]['settings'] = $settings;
$settings_form = array();
$function = $formatter['module'] . '_field_formatter_settings_form';
if (function_exists($function)) {
$settings_form = $function($field, $instance, $view_mode, $form, $form_state);
$settings_form['#tree'] = TRUE;
$settings_form['#parents'] = array(
'addthis_settings',
'settings',
);
}
$form['settings'] = $settings_form;
return $form;
}