Skip to content
Snippets Groups Projects
Commit 043106d6 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3296212: Support for SRI Integrity hash attribute

parent 961579cf
No related branches found
No related tags found
1 merge request!19Issue #3296212: Support for SRI Integrity hash attribute
TODO update README for branch 2.x
### Requirements
For the chart.js feature, follow either of the options:
1. Download chart.js library using composer or manually from https://github.com/chartjs/Chart.js/releases/tag/v2.5.0 placing inside libraries/chartjs/ (Downloading via composer is recommended.)
2. Use the CDN option.
**How to download chart.js library using composer:**
1. Add following code inside `repositories` section in your project's `composer.json`
```
"chart.js": {
"type": "package",
"package": {
"name": "nnnick/chartjs",
"version": "v2.5.0",
"type": "drupal-library",
"dist": {
"url": "https://github.com/chartjs/Chart.js/archive/refs/tags/v2.5.0.zip",
"type": "zip"
}
}
}
```
2. If not added already, please add following code under `installer-paths` in `composer.json` (Add `web` or `docroot` according to your structure)
```
"web/libraries/{$name}": [
"type:drupal-library",
]
```
3. Then run the command `composer require nnnick/chartjs`.
4. It should automatically download and place the `chartjs` library inside `web/libraries` or `docroot/libraries` folder.
For security, it's always safer to have a local copy vs external resource.
redirect_on_login: true
chart_js_cdn: false
......@@ -19,3 +19,6 @@ moderation_dashboard.settings:
redirect_on_login:
type: boolean
label: 'Redirect to moderation dashboard after login'
chart_js_cdn:
type: boolean
label: 'Pull chart.js from CDN'
......@@ -9,11 +9,14 @@ activity:
js:
js/moderation_dashboard_activity.js: {}
dependencies:
- moderation_dashboard/chart.js
- core/jquery
- core/jquery.once
chart.js:
chart.js.internal:
js:
/libraries/chartjs/dist/Chart.bundle.min.js: { minified: true }
chart.js.external:
remote: https://github.com/chartjs/Chart.js
version: 2.5.0
license:
......@@ -24,3 +27,6 @@ chart.js:
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js:
type: external
minified: true
attributes:
integrity: 'sha384-mVRLpSa1BOMjZqAeHjV/j7j2H5F+4uYD7NRPDeU7U3KznLYMxfpQfXv/FYBiC6i3'
crossorigin: anonymous
......@@ -108,3 +108,16 @@ function moderation_dashboard_plugin_filter_condition__block_ui_alter(array &$de
unset($definitions['has_moderated_content_type']);
unset($definitions['moderation_dashboard_access']);
}
function moderation_dashboard_page_attachments(array &$page) {
if (strpos(\Drupal::routeMatch()->getRouteName(), 'view.moderation_dashboard.page_1') === 0) {
$config = \Drupal::config('moderation_dashboard.settings');
$use_cdn = $config->get('chart_js_cdn');
if (!empty($use_cdn) && $use_cdn === 1) {
$page['#attached']['library'][] = 'moderation_dashboard/chart.js.external';
}
else {
$page['#attached']['library'][] = 'moderation_dashboard/chart.js.internal';
}
}
}
......@@ -29,6 +29,7 @@ class SettingsForm extends ConfigFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('moderation_dashboard.settings');
$form['redirect_on_login'] = [
'#type' => 'checkbox',
'#title' => $this->t('Redirect on login'),
......@@ -36,6 +37,14 @@ class SettingsForm extends ConfigFormBase {
'#description' => $this->t('Redirect to moderation dashboard after login.'),
];
$form['chart_js_cdn'] = [
'#type' => 'checkbox',
'#title' => $this->t('Pull chart.js from CDN'),
'#default_value' => $config->get('chart_js_cdn'),
'#description' => $this->t('Pull in chart.js from the CDN or leave uncheck to use local copy. For security it\'s best to use local copy'),
];
return parent::buildForm($form, $form_state);
}
......@@ -46,6 +55,7 @@ class SettingsForm extends ConfigFormBase {
$values = $form_state->getValues();
$this->config('moderation_dashboard.settings')
->set('redirect_on_login', $values['redirect_on_login'])
->set('chart_js_cdn', $values['chart_js_cdn'])
->save();
parent::submitForm($form, $form_state);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment