Created
February 18, 2019 16:13
-
-
Save ahebrank/18f952e41e8bea39f57d5dd000b0ef3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/config/install/frontback.settings.yml b/config/install/frontback.settings.yml | |
| index 05b9448..2b02576 100644 | |
| --- a/config/install/frontback.settings.yml | |
| +++ b/config/install/frontback.settings.yml | |
| @@ -3,3 +3,5 @@ frontback_endpoint: '' | |
| hide_button: false | |
| hide_reporter_options: false | |
| hide_assignee_options: false | |
| +show_on_nonadmin_routes: true | |
| +show_on_admin_routes: true | |
| diff --git a/config/schema/frontback.schema.yml b/config/schema/frontback.schema.yml | |
| index dbc39bc..d55f621 100644 | |
| --- a/config/schema/frontback.schema.yml | |
| +++ b/config/schema/frontback.schema.yml | |
| @@ -11,6 +11,12 @@ frontback.admin_settings: | |
| hide_button: | |
| type: boolean | |
| label: 'Hide Feedback button' | |
| + show_on_nonadmin_routes: | |
| + type: boolean | |
| + label: 'Use Frontback on non-admin routes' | |
| + show_on_admin_routes: | |
| + type: boolean | |
| + label: 'Use Frontback on admin routes' | |
| hide_reporter_options: | |
| type: boolean | |
| label: 'Disable reporter select box' | |
| diff --git a/frontback.module b/frontback.module | |
| index df2f37f..3f46d2e 100644 | |
| --- a/frontback.module | |
| +++ b/frontback.module | |
| @@ -24,10 +24,16 @@ function frontback_menu() { | |
| */ | |
| function frontback_page_attachments(array &$page) { | |
| if (\Drupal::currentUser()->hasPermission('access frontback')) { | |
| - $settings = frontback_get_settings(); | |
| - if ($settings['frontback']['repo_id'] && $settings['frontback']['endpoint']) { | |
| - $page['#attached']['drupalSettings']['frontback'] = $settings['frontback']; | |
| - $page['#attached']['library'][] = 'frontback/frontback'; | |
| + $settings = _frontback_get_settings(); | |
| + $is_admin_route = \Drupal::service('router.admin_context')->isAdminRoute(); | |
| + if ( | |
| + ($is_admin_route && $settings['show_on_admin_routes']) | |
| + || (!$is_admin_route && $settings['show_on_nonadmin_routes']) | |
| + ) { | |
| + if ($settings['frontback']['repo_id'] && $settings['frontback']['endpoint']) { | |
| + $page['#attached']['drupalSettings']['frontback'] = $settings['frontback']; | |
| + $page['#attached']['library'][] = 'frontback/frontback'; | |
| + } | |
| } | |
| } | |
| } | |
| @@ -35,7 +41,7 @@ function frontback_page_attachments(array &$page) { | |
| /** | |
| * Helper function to return frontback widget settings to the current page. | |
| */ | |
| -function frontback_get_settings() { | |
| +function _frontback_get_settings() { | |
| $config = \Drupal::config('frontback.admin_settings'); | |
| @@ -51,6 +57,8 @@ function frontback_get_settings() { | |
| // cache-bust every 10 min. | |
| 'version' => (time() - (time() % 600)), | |
| ], | |
| + 'show_on_admin_routes' => $config->get('show_on_admin_routes'), | |
| + 'show_on_nonadmin_routes' => $config->get('show_on_nonadmin_routes'), | |
| ]; | |
| return $settings_object; | |
| diff --git a/src/Form/FrontbackSettingsForm.php b/src/Form/FrontbackSettingsForm.php | |
| index dd7633f..11a67ea 100644 | |
| --- a/src/Form/FrontbackSettingsForm.php | |
| +++ b/src/Form/FrontbackSettingsForm.php | |
| @@ -55,6 +55,18 @@ class FrontbackSettingsForm extends ConfigFormBase { | |
| '#description' => t("Hide Feedback button but run script (useful for config split / local dev situations)"), | |
| '#default_value' => $admin_configurations->get('hide_button'), | |
| ]; | |
| + $form['show_on_nonadmin_routes'] = [ | |
| + '#type' => 'checkbox', | |
| + '#title' => t('Use Feedback on non-admin routes'), | |
| + '#description' => t("Show on the front end"), | |
| + '#default_value' => $admin_configurations->get('show_on_nonadmin_routes'), | |
| + ]; | |
| + $form['show_on_admin_routes'] = [ | |
| + '#type' => 'checkbox', | |
| + '#title' => t('Use Feedback on admin routes'), | |
| + '#description' => t("Show on the back end"), | |
| + '#default_value' => $admin_configurations->get('show_on_admin_routes'), | |
| + ]; | |
| $form['hide_assignee_options'] = [ | |
| '#type' => 'checkbox', | |
| '#title' => t('Hide assignee options'), | |
| @@ -81,6 +93,8 @@ class FrontbackSettingsForm extends ConfigFormBase { | |
| 'hide_button', | |
| 'hide_assignee_options', | |
| 'hide_reporter_options', | |
| + 'show_on_admin_routes', | |
| + 'show_on_nonadmin_routes', | |
| ]; | |
| $config = $this->config('frontback.admin_settings'); | |
| foreach ($config_fields as $config_field) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment