Skip to content

Commit

Permalink
Merge pull request #500 from localgovdrupal/495/feature/unpublished-p…
Browse files Browse the repository at this point in the history
…ages

adds theme options for unpublished pages
  • Loading branch information
markconroy authored Nov 13, 2023
2 parents ce15df8 + 011e87f commit 6d9f42c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 7 deletions.
6 changes: 4 additions & 2 deletions config/install/localgov_base.settings.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions config/schema/localgov_base.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
5 changes: 0 additions & 5 deletions css/base/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,3 @@ textarea,
button {
font-family: var(--font-primary);
}

.node--unpublished,
.paragraph--unpublished {
background-color: pink;
}
4 changes: 4 additions & 0 deletions css/components/unpublished-bg.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.node--unpublished,
.paragraph--unpublished {
background-color: pink;
}
5 changes: 5 additions & 0 deletions localgov_base.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ region-tabs:
theme:
css/components/region-tabs.css: {}

unpublished-bg:
css:
theme:
css/components/unpublished-bg.css: {}

callout:
css:
theme:
Expand Down
53 changes: 53 additions & 0 deletions localgov_base.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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.'),
];
}

/**
Expand Down Expand Up @@ -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;
}
}
}
}
}

/**
Expand Down

0 comments on commit 6d9f42c

Please sign in to comment.