diff --git a/config/install/localgov_base.settings.yml b/config/install/localgov_base.settings.yml index e2f5a1f4..5e4015f4 100644 --- a/config/install/localgov_base.settings.yml +++ b/config/install/localgov_base.settings.yml @@ -1,2 +1,4 @@ -localgov_base_remove_css: false -localgov_base_remove_js: false +localgov_base_remove_css: FALSE +localgov_base_remove_js: FALSE +localgov_base_add_unpublished_background_colour: TRUE +localgov_base_add_draft_note_to_unpublished_content: FALSE diff --git a/config/schema/localgov_base.schema.yml b/config/schema/localgov_base.schema.yml index 50391829..c6148cc3 100644 --- a/config/schema/localgov_base.schema.yml +++ b/config/schema/localgov_base.schema.yml @@ -8,3 +8,9 @@ localgov_base.settings: localgov_base_remove_js: type: boolean label: 'Remove JS libraries from base theme.' + localgov_base_add_unpublished_background_colour: + type: boolean + label: 'Add background colour to unpublished content.' + localgov_base_add_draft_note_to_unpublished_content: + type: boolean + label: 'Add "[Draft]" to title of unpublished content.' diff --git a/css/base/base.css b/css/base/base.css index 44e333f0..c30e6c3f 100644 --- a/css/base/base.css +++ b/css/base/base.css @@ -200,8 +200,3 @@ textarea, button { font-family: var(--font-primary); } - -.node--unpublished, -.paragraph--unpublished { - background-color: pink; -} \ No newline at end of file diff --git a/css/components/unpublished-bg.css b/css/components/unpublished-bg.css new file mode 100644 index 00000000..fe0c2706 --- /dev/null +++ b/css/components/unpublished-bg.css @@ -0,0 +1,4 @@ +.node--unpublished, +.paragraph--unpublished { + background-color: pink; +} \ No newline at end of file diff --git a/localgov_base.libraries.yml b/localgov_base.libraries.yml index 351c6387..51a0f493 100644 --- a/localgov_base.libraries.yml +++ b/localgov_base.libraries.yml @@ -33,6 +33,11 @@ region-tabs: theme: css/components/region-tabs.css: {} +unpublished-bg: + css: + theme: + css/components/unpublished-bg.css: {} + callout: css: theme: diff --git a/localgov_base.theme b/localgov_base.theme index af184482..cb1789d3 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -31,6 +31,20 @@ function localgov_base_form_system_theme_settings_alter(&$form, FormStateInterfa '#default_value' => theme_get_setting('localgov_base_remove_js'), '#description' => t("Check this box to disable the base theme's JavaScript"), ]; + + $form['localgov_base_add_unpublished_background_colour'] = [ + '#type' => 'checkbox', + '#title' => t('Add background colour to unpublished content.'), + '#default_value' => theme_get_setting('localgov_base_add_unpublished_background_colour'), + '#description' => t("If you remove the background colour, you should probably also check the box below to add '[Draft]' to the title of unpublished content."), + ]; + + $form['localgov_base_add_draft_note_to_unpublished_content'] = [ + '#type' => 'checkbox', + '#title' => t('Add "Draft" to title of unpublished content.'), + '#default_value' => theme_get_setting('localgov_base_add_draft_note_to_unpublished_content'), + '#description' => t('This adds the word "Draft" to the title of any unpublished content. This is useful if you have removed the pink background from unpublished content.'), + ]; } /** @@ -65,6 +79,45 @@ function localgov_base_preprocess_page(&$variables) { if (!isset($variables['localgov_base_remove_css'])) { $variables['#attached']['library'][] = 'localgov_base/global'; } + + // We have a theme setting boolean for removing the pink background from + // unpublished content. If that setting is false, + // we will add the 'unpublished' library to our page. + if (theme_get_setting('localgov_base_add_unpublished_background_colour') == TRUE) { + $variables['#attached']['library'][] = 'localgov_base/unpublished-bg'; + } +} + +/** + * Implements hook_preprocess_HOOK(). + */ +function localgov_base_preprocess_node(&$variables) { + $node_status = $variables['node']->isPublished(); + if ($node_status === FALSE) { + if (theme_get_setting('localgov_base_add_draft_note_to_unpublished_content') == TRUE) { + $variables['label'] = t('[Draft]') . " " . $variables['node']->label(); + } + } +} + +/** + * Implements hook_preprocess_HOOK(). + */ +function localgov_base_preprocess_block(&$variables) { + $route_match = Drupal::routeMatch(); + // Check if we are on a node page. + if ($route_match->getRouteName() == 'entity.node.canonical') { + $node = $route_match->getParameter('node'); + $node_status = $node->isPublished(); + if ($variables['plugin_id'] === 'localgov_page_header_block') { + if ($node_status === FALSE) { + if (theme_get_setting('localgov_base_add_draft_note_to_unpublished_content') == TRUE) { + $current_title = $variables['content'][0]['#title']; + $variables['content'][0]['#title'] = t('[Draft]') . " " . $current_title; + } + } + } + } } /**