Skip to content
Snippets Groups Projects
Commit 4c4598bf authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3149565 by Xiaohua Guan, yas: Setup JavaScript files in a local server environment (c3.js)

parent 7711d463
No related branches found
Tags 8.x-1.0-beta20
No related merge requests found
......@@ -719,3 +719,14 @@ function cloud_update_8136() {
function cloud_update_8137() {
drupal_flush_all_caches();
}
/**
* Add configuration items for C3 library.
*/
function cloud_update_8138() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('cloud.settings');
$config->set('cloud_custom_c3_js_url', 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.15/c3.min.js');
$config->set('cloud_custom_c3_css_url', 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.15/c3.min.css');
$config->save();
}
......@@ -223,11 +223,15 @@ function cloud_library_info_alter(&$libraries, $extension) {
if (empty($source)) {
$libraries['d3']['js'] = [];
$libraries['c3']['js'] = [];
$libraries['c3']['css']['theme'] = [];
$libraries['chartjs']['js'] = [];
$libraries['select2']['js'] = [];
$libraries['select2']['css']['theme'] = [];
$libraries['d3']['js'][trim($config->get('cloud_custom_d3_js_url'))] = [];
$libraries['c3']['js'][trim($config->get('cloud_custom_c3_js_url'))] = [];
$libraries['c3']['css']['theme'][trim($config->get('cloud_custom_c3_css_url'))] = [];
$libraries['chartjs']['js'][trim($config->get('cloud_custom_chart_js_url'))] = [];
$libraries['select2']['js'][trim($config->get('cloud_custom_select2_js_url'))] = [];
$libraries['select2']['css']['theme'][trim($config->get('cloud_custom_select2_css_url'))] = [];
......
......@@ -2,6 +2,8 @@ cloud_location_geocoder_plugin: 'openstreetmap'
cloud_default_location_map_json_url: 'http://enjalot.github.io/wwsd/data/world/ne_50m_admin_0_countries.geojson'
cloud_custom_location_map_json_url: 'http://enjalot.github.io/wwsd/data/world/ne_50m_admin_0_countries.geojson'
cloud_custom_d3_js_url: 'https://d3js.org/d3.v5.min.js'
cloud_custom_c3_js_url: 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.15/c3.min.js'
cloud_custom_c3_css_url: 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.15/c3.min.css'
cloud_custom_chart_js_url: 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js'
cloud_custom_select2_js_url: "https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.min.js"
cloud_custom_select2_css_url: "https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css"
......
......@@ -9,6 +9,10 @@ cloud.settings:
type: string
cloud_custom_d3_js_url:
type: string
cloud_custom_c3_js_url:
type: string
cloud_custom_c3_css_url:
type: string
cloud_custom_chart_js_url:
type: string
cloud_custom_select2_js_url:
......
......@@ -153,6 +153,30 @@ class CloudAdminSettings extends ConfigFormBase {
],
];
$form['custom_urls']['cloud_custom_c3_js_url'] = [
'#type' => 'url',
'#title' => $this->t('C3.js JavaScript URL'),
'#default_value' => $config->get('cloud_custom_c3_js_url'),
'#description' => $this->t('The default URL is <em>https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.15/c3.min.js</em>.'),
'#states' => [
'visible' => [
'input[name="cloud_use_default_urls"]' => ['checked' => FALSE],
],
],
];
$form['custom_urls']['cloud_custom_c3_css_url'] = [
'#type' => 'url',
'#title' => $this->t('C3.js CSS URL'),
'#default_value' => $config->get('cloud_custom_c3_css_url'),
'#description' => $this->t('The default URL is <em>https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.15/c3.min.css</em>.'),
'#states' => [
'visible' => [
'input[name="cloud_use_default_urls"]' => ['checked' => FALSE],
],
],
];
$form['custom_urls']['cloud_custom_chart_js_url'] = [
'#type' => 'url',
'#title' => $this->t('Chart.js JavaScript URL'),
......@@ -197,15 +221,21 @@ class CloudAdminSettings extends ConfigFormBase {
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$d3_url = $form_state->getValue('cloud_custom_d3_js_url');
$c3_js_url = $form_state->getValue('cloud_custom_c3_js_url');
$c3_css_url = $form_state->getValue('cloud_custom_c3_css_url');
$chartjs_url = $form_state->getValue('cloud_custom_chart_js_url');
$select2_css_url = $form_state->getValue('cloud_custom_select2_css_url');
$select2_js_url = $form_state->getValue('cloud_custom_select2_js_url');
if (empty($d3_url)
|| empty($c3_js_url)
|| empty($c3_css_url)
|| empty($chartjs_url)
|| empty($select2_css_url)
|| empty($select2_js_url)) {
$form_state->setErrorByName('cloud_custom_d3_js_url', $this->t('Please enter D3.js JavaScript URL.'));
$form_state->setErrorByName('cloud_custom_c3_js_url', $this->t('Please enter C3.js JavaScript URL.'));
$form_state->setErrorByName('cloud_custom_c3_css_url', $this->t('Please enter C3.js CSS URL.'));
$form_state->setErrorByName('cloud_custom_chart_js_url', $this->t('Please enter Chart.js JavaScript URL.'));
$form_state->setErrorByName('cloud_custom_select2_js_url', $this->t('Please enter Select2 JavaScript URL.'));
$form_state->setErrorByName('cloud_custom_select2_css_url', $this->t('Please enter Select2 CSS URL.'));
......@@ -222,6 +252,8 @@ class CloudAdminSettings extends ConfigFormBase {
$config->set('cloud_use_default_urls', $form_state->getValue('cloud_use_default_urls'));
$config->set('cloud_custom_location_map_json_url', $form_state->getValue('cloud_custom_location_map_json_url'));
$config->set('cloud_custom_d3_js_url', $form_state->getValue('cloud_custom_d3_js_url'));
$config->set('cloud_custom_c3_js_url', $form_state->getValue('cloud_custom_c3_js_url'));
$config->set('cloud_custom_c3_css_url', $form_state->getValue('cloud_custom_c3_css_url'));
$config->set('cloud_custom_chart_js_url', $form_state->getValue('cloud_custom_chart_js_url'));
$config->set('cloud_custom_select2_js_url', $form_state->getValue('cloud_custom_select2_js_url'));
$config->set('cloud_custom_select2_css_url', $form_state->getValue('cloud_custom_select2_css_url'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment