function jstimer_build_js_cache in Javascript Timer 8
Same name and namespace in other branches
- 6 jstimer.module \jstimer_build_js_cache()
- 7 jstimer.module \jstimer_build_js_cache()
create the timer.js file and put it in the files/jstimer directory.
Return value
string The full path of the file.
4 calls to jstimer_build_js_cache()
- JstimerAdminSettings::_submitForm in src/
Form/ JstimerAdminSettings.php - Save admin settings, write jstimer.js file, and clear js cache (for aggregation).
- jstimer_install in ./
jstimer.install - Implementation of hook_install().
- jst_clock_install in widgets/
jst_clock.module - Implementation of hook_install().
- jst_timer_install in widgets/
jst_timer.module - Implementation of hook_install().
File
- ./
jstimer.module, line 117
Code
function jstimer_build_js_cache() {
// Create the files/jstimer
$path = 'public://jstimer';
\Drupal::service('file_system')
->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
$data = jstimer_get_javascript(TRUE);
file_save_data($data, $path . '/timer.js', FileSystemInterface::EXISTS_REPLACE);
\Drupal::messenger()
->addStatus(t('Javascript timer javascript file saved to: ') . $path . '/timer.js');
if (!file_exists($path . '/timer.js')) {
\Drupal::messenger()
->addError(t('File Create Error: timer.js could not be created'));
}
else {
\Drupal::configFactory()
->getEditable('jstimer.settings')
->set('jstimer_timerjs_path', $path . '/timer.js')
->save();
}
return $path . '/timer.js';
}