function jst_timer_form_jstimer_admin_settings_alter in Javascript Timer 8
Implementation of hook_form_alter(). Add the timer widget specific settings to admin screen.
File
- widgets/
jst_timer.module, line 322 - Default widget implementation for an up and down timer. This widget does not use hook_ctwidget as it is always included.
Code
function jst_timer_form_jstimer_admin_settings_alter(&$form, FormStateInterface $form_state, $form_id) {
$config = \Drupal::config('jstimer.settings');
// Get a list of formats.
$timer_formats = jst_timer_get_formats();
$form['jst_timer'] = array(
'#type' => 'fieldset',
'#title' => t('Timer widget'),
'#weight' => 1,
);
$form['jst_timer']['jst_timer_formats'] = array(
'#type' => 'fieldset',
'#title' => t('Timer formats'),
'#tree' => TRUE,
'#description' => t("Formats control how each timer will display and also allow you to add styles/classes.") . '<br/>' . t("Available replacement values are: %day%, %month%, %year%, %dow%, %moy%, %years%, %ydays%, %days%, %hours%, %mins%, and %secs%.") . '<br/>' . t("Refresh the page after saving to reload the examples."),
);
$i = 0;
foreach ($timer_formats as $i => $format) {
// 0 is the global default format.
if ($i == 0) {
$form['jst_timer']['jst_timer_formats'][] = array(
'#type' => 'textarea',
'#rows' => 1,
'#title' => t('Global format'),
'#default_value' => $format,
);
}
else {
$form['jst_timer']['jst_timer_formats'][] = array(
'#type' => 'textarea',
'#rows' => 1,
'#title' => t('Format preset %preset_num', array(
'%preset_num' => $i,
)),
'#default_value' => $format,
);
}
}
// Add a blank one.
$form['jst_timer']['jst_timer_formats'][] = array(
'#type' => 'textarea',
'#rows' => 1,
'#title' => t('Format preset %preset_num', array(
'%preset_num' => $i + 1,
)),
'#default_value' => '',
'#description' => t('Add a new preset. After you save, another blank one will be added.'),
);
$form['jst_timer']['actions'] = array(
'#type' => 'fieldset',
'#title' => t('Timer actions'),
'#weight' => 1,
'#description' => t('Javascript actions that execute when a countdown timer completes or nears completion.'),
);
// Proximity styling.
$form['jst_timer']['actions']['proximity'] = array(
'#type' => 'details',
'#title' => t('Proximity styling'),
'#description' => t('Dynamic styling of timer when countdown approaches completion.'),
'#tree' => FALSE,
);
$form['jst_timer']['actions']['proximity']['jstimer_highlight'] = array(
'#type' => 'textfield',
'#size' => 100,
'#title' => t('CSS statement'),
'#default_value' => $config
->get('jstimer_highlight'),
'#description' => t("Use a complete css attribute statement like style=\"\" or class=\"\"."),
);
$form['jst_timer']['actions']['proximity']['jstimer_highlight_threshold'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Threshold (minutes)'),
'#default_value' => $config
->get('jstimer_highlight_threshold'),
'#description' => t("Number of minutes before css statement is applied."),
);
$form['jst_timer']['actions']['proximity']['jstimer_highlight_down'] = array(
'#type' => 'checkbox',
'#title' => t('Apply to countdown timers'),
'#default_value' => $config
->get('jstimer_highlight_down'),
);
$form['jst_timer']['actions']['proximity']['jstimer_highlight_up'] = array(
'#type' => 'checkbox',
'#title' => t('Apply to down/up (NASA) timers'),
'#default_value' => $config
->get('jstimer_highlight_up'),
'#description' => t("Styling latches (ie stays on forever after the threshold has been reached)."),
);
$form['jst_timer']['actions']['proximity']['jstimer_highlight_threshold'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Threshold (minutes)'),
'#default_value' => $config
->get('jstimer_highlight_threshold'),
'#description' => t("Number of minutes before css statement is applied."),
);
// Redirect URL.
$form['jst_timer']['actions']['redirect'] = array(
'#type' => 'details',
'#title' => t('Timer complete redirect'),
'#description' => t('Javascript redirect/refresh that runs when a countdown completes.'),
'#tree' => FALSE,
);
$form['jst_timer']['actions']['redirect']['jst_timer_redirect_path'] = array(
'#type' => 'textfield',
'#size' => 100,
'#title' => t('Redirect path'),
'#default_value' => $config
->get('jst_timer_redirect_path'),
'#description' => t('An absolute URL or %reload for same page.', array(
'%reload' => '<reload>',
)),
);
$form['jst_timer']['actions']['redirect']['jst_timer_redirect_delay'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Delay (seconds)'),
'#default_value' => $config
->get('jst_timer_redirect_delay'),
'#description' => t("Number of seconds to wait after countdown completion before running redirect/refresh."),
);
// Timer complete message.
$form['jst_timer']['actions']['jst_timer_complete_message'] = array(
'#type' => 'details',
'#title' => t('Timer complete message'),
'#description' => t('Message that replaces timer when a countdown completes.'),
'#weight' => 1,
);
$form['jst_timer']['actions']['jst_timer_complete_message']['jst_timer_complete_message'] = array(
'#type' => 'textfield',
'#title' => t('Message'),
'#size' => 80,
'#default_value' => $config
->get('jst_timer_complete_message'),
);
// Timer complete alert.
$form['jst_timer']['actions']['jst_timer_complete_alert'] = array(
'#type' => 'details',
'#title' => t('Timer complete alert message'),
'#description' => t('Message that pops up in an alert box when when a countdown completes. Do NOT use HTML.'),
'#weight' => 1,
);
$form['jst_timer']['actions']['jst_timer_complete_alert']['jst_timer_complete_alert_message'] = array(
'#type' => 'textfield',
'#title' => t('Message'),
'#size' => 80,
'#default_value' => $config
->get('jst_timer_complete_alert_message'),
);
$form['buttons']['#weight'] = 10;
// Put this module's submit handler first so it can save before javascript file is built.
array_unshift($form['#submit'], 'jst_timer_admin_settings_submit');
}