Loading config/install/simple_klaro.settings.yml +1 −0 Original line number Diff line number Diff line Loading @@ -2,3 +2,4 @@ config: "{\n \"elementID\":\"klaro\",\n \"storageMethod\":\"localStorage\",\ preferences: 'Cookie preferences' library: klaro enabled: true exclude_paths: '' No newline at end of file config/schema/simple_klaro.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,6 @@ simple_klaro: enabled: type: boolean label: 'Enable Simple Klaro' exclude_paths: type: string label: 'Exclude paths' simple_klaro.install +10 −0 Original line number Diff line number Diff line Loading @@ -36,3 +36,13 @@ function simple_klaro_update_8002() { $config->set('enabled', TRUE); $config->save(); } /** * Update simple klaro settings with new exclude_paths option. */ function simple_klaro_update_8101() { $config_factory = \Drupal::configFactory(); $config = $config_factory->getEditable('simple_klaro.settings'); $config->set('exclude_paths', ''); $config->save(); } simple_klaro.module +16 −2 Original line number Diff line number Diff line Loading @@ -14,13 +14,27 @@ function simple_klaro_page_attachments(array &$page) { if (\Drupal::currentUser()->hasPermission('bypass simple klaro')) { return FALSE; } /** @var \Drupal\Core\Config\ConfigFactoryInterface $config */ $config = \Drupal::config('simple_klaro.settings'); $klaro_enabled = $config->get('enabled'); $klaro_config = Json::decode($config->get('config')); $klaro_library = $config->get('library'); $excluded_paths = $config->get('exclude_paths'); $path_match = FALSE; if ($klaro_enabled && !empty($klaro_config) && !empty($klaro_library)) { if (!empty($excluded_paths)) { // Check both the URL path and the URL alias against the list to exclude. $path = \Drupal::service('path.current')->getPath(); $url_alias_path = \Drupal::service('path_alias.manager')->getAliasByPath($path); $path_match = \Drupal::service('path.matcher')->matchPath($path, $excluded_paths); $path_match_url_alias = \Drupal::service('path.matcher')->matchPath($url_alias_path, $excluded_paths); $path_match = $path_match || $path_match_url_alias; } if (!$path_match) { $page['#attached']['drupalSettings']['klaroConfig'] = $klaro_config; $page['#attached']['library'][] = "simple_klaro/$klaro_library"; } } } src/Form/SettingsForm.php +12 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,17 @@ class SettingsForm extends ConfigFormBase { '#required' => TRUE, ]; $form['exclude_paths'] = [ '#type' => 'textarea', '#title' => $this->t('Exclude paths'), '#default_value' => !empty($config->get('exclude_paths')) ? $config->get('exclude_paths') : '', '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", [ '%blog' => '/blog', '%blog-wildcard' => '/blog/*', '%front' => '<front>', ]), ]; $form['#attached']['library'][] = 'simple_klaro/klaro_editor'; return parent::buildForm($form, $form_state); Loading @@ -107,6 +118,7 @@ class SettingsForm extends ConfigFormBase { ->set('preferences', $form_state->getValue('preferences')) ->set('library', $form_state->getValue('library')) ->set('enabled', $form_state->getValue('enabled')) ->set('exclude_paths', $form_state->getValue('exclude_paths')) ->save(); parent::submitForm($form, $form_state); Loading Loading
config/install/simple_klaro.settings.yml +1 −0 Original line number Diff line number Diff line Loading @@ -2,3 +2,4 @@ config: "{\n \"elementID\":\"klaro\",\n \"storageMethod\":\"localStorage\",\ preferences: 'Cookie preferences' library: klaro enabled: true exclude_paths: '' No newline at end of file
config/schema/simple_klaro.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -14,3 +14,6 @@ simple_klaro: enabled: type: boolean label: 'Enable Simple Klaro' exclude_paths: type: string label: 'Exclude paths'
simple_klaro.install +10 −0 Original line number Diff line number Diff line Loading @@ -36,3 +36,13 @@ function simple_klaro_update_8002() { $config->set('enabled', TRUE); $config->save(); } /** * Update simple klaro settings with new exclude_paths option. */ function simple_klaro_update_8101() { $config_factory = \Drupal::configFactory(); $config = $config_factory->getEditable('simple_klaro.settings'); $config->set('exclude_paths', ''); $config->save(); }
simple_klaro.module +16 −2 Original line number Diff line number Diff line Loading @@ -14,13 +14,27 @@ function simple_klaro_page_attachments(array &$page) { if (\Drupal::currentUser()->hasPermission('bypass simple klaro')) { return FALSE; } /** @var \Drupal\Core\Config\ConfigFactoryInterface $config */ $config = \Drupal::config('simple_klaro.settings'); $klaro_enabled = $config->get('enabled'); $klaro_config = Json::decode($config->get('config')); $klaro_library = $config->get('library'); $excluded_paths = $config->get('exclude_paths'); $path_match = FALSE; if ($klaro_enabled && !empty($klaro_config) && !empty($klaro_library)) { if (!empty($excluded_paths)) { // Check both the URL path and the URL alias against the list to exclude. $path = \Drupal::service('path.current')->getPath(); $url_alias_path = \Drupal::service('path_alias.manager')->getAliasByPath($path); $path_match = \Drupal::service('path.matcher')->matchPath($path, $excluded_paths); $path_match_url_alias = \Drupal::service('path.matcher')->matchPath($url_alias_path, $excluded_paths); $path_match = $path_match || $path_match_url_alias; } if (!$path_match) { $page['#attached']['drupalSettings']['klaroConfig'] = $klaro_config; $page['#attached']['library'][] = "simple_klaro/$klaro_library"; } } }
src/Form/SettingsForm.php +12 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,17 @@ class SettingsForm extends ConfigFormBase { '#required' => TRUE, ]; $form['exclude_paths'] = [ '#type' => 'textarea', '#title' => $this->t('Exclude paths'), '#default_value' => !empty($config->get('exclude_paths')) ? $config->get('exclude_paths') : '', '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", [ '%blog' => '/blog', '%blog-wildcard' => '/blog/*', '%front' => '<front>', ]), ]; $form['#attached']['library'][] = 'simple_klaro/klaro_editor'; return parent::buildForm($form, $form_state); Loading @@ -107,6 +118,7 @@ class SettingsForm extends ConfigFormBase { ->set('preferences', $form_state->getValue('preferences')) ->set('library', $form_state->getValue('library')) ->set('enabled', $form_state->getValue('enabled')) ->set('exclude_paths', $form_state->getValue('exclude_paths')) ->save(); parent::submitForm($form, $form_state); Loading