Skip to content

1.8.10 release #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
66 changes: 66 additions & 0 deletions components/content/displays/display-full/display-full.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{#
@file Fallback content template to be used for full view mode when no other
more specific template is available.
#}

{% if not localgov_base_remove_css %}
{{ attach_library('localgov_base/full') }}
{% if content_type == 'localgov_directories_venue'
or content_type == 'localgov_directories_page'
or content_type == 'localgov_directory' %}
{{ attach_library('localgov_base/directories') }}
{% endif %}

{% if content_type == 'localgov_step_by_step_overview'
or content_type == 'localgov_step_by_step_page' %}
{{ attach_library('localgov_base/step-by-step') }}
{% endif %}
{% endif %}

{%
set classes = [
content_type|clean_class,
'node',
restricted_width_content_type ? 'node--with-restricted-width',
display_full_promoted ? 'node--promoted',
display_full_sticky ? 'node--sticky',
display_full_unpublished ? 'node--unpublished',
view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
]
%}

<article{{ attributes.addClass(classes).removeAttribute('role') }}>

<div class="lgd-container padding-horizontal">
{{ title_prefix }}
{{ title_suffix }}

{% if display_submitted %}
<footer class="node__meta">
{{ author_picture }}
<div{{ author_attributes.addClass('node__submitted') }}>
{% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}
{{ metadata }}
</div>
</footer>
{% endif %}

{% if content_type in restricted_width_content_types %}
<div class="node__restricted-width-section">
{% endif %}

<div{{ content_attributes.addClass(content_type|clean_class ~ '__content', 'node__content') }}>
{{ display_full_content }}
</div>
</div>

{% if localgov_subsites_content %}
{{ localgov_subsites_content }}
{% endif %}


{% if content_type in restricted_width_content_types %}
</div>
{% endif %}

</article>
1 change: 1 addition & 0 deletions config/install/localgov_base.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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
localgov_base_add_archived_note_to_archived_content: FALSE
localgov_base_header_behaviour: 'default'
localgov_base_localgov_guides_stacked_heading: FALSE
localgov_base_localgov_guides_vertical_navigation: TRUE
3 changes: 3 additions & 0 deletions config/schema/localgov_base.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ localgov_base.settings:
localgov_base_add_draft_note_to_unpublished_content:
type: boolean
label: 'Add "[Draft]" to title of unpublished content.'
localgov_base_add_archived_note_to_archived_content:
type: boolean
label: 'Add "[Archived]" to title of archived content.'
localgov_base_header_behaviour:
type: string
label: 'Header behaviour'
Expand Down
93 changes: 80 additions & 13 deletions localgov_base.theme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\views\ViewExecutable;

/**
Expand Down Expand Up @@ -42,9 +43,16 @@ function localgov_base_form_system_theme_settings_alter(&$form, FormStateInterfa

$form['localgov_base_add_draft_note_to_unpublished_content'] = [
'#type' => 'checkbox',
'#title' => t('Add "Draft" to title of unpublished content.'),
'#title' => t('Add "Draft" to title of draft 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.'),
'#description' => t('This adds the word "Draft" to the title of any draft unpublished content. This is useful if you have removed the pink background from unpublished content.'),
];

$form['localgov_base_add_archived_note_to_archived_content'] = [
'#type' => 'checkbox',
'#title' => t('Add "Archived" to title of archived content.'),
'#default_value' => theme_get_setting('localgov_base_add_archived_note_to_archived_content'),
'#description' => t('This adds the word "Archived" to the title of any content with the "archived" moderation state.'),
];

$form['localgov_base_show_back_to_top_link'] = [
Expand Down Expand Up @@ -190,14 +198,55 @@ function localgov_base_preprocess_page(&$variables): void {

}

/**
* Get the restricted width content types.
*
* @return array
* An array of restricted width content types.
*/
function _localgov_get_restricted_width_content_types() {
return [
'localgov_services_page',
'localgov_event',
'localgov_services_status',
'localgov_step_by_step_overview',
'localgov_publication_cover_page'
];
}

/**
* Implements hook_preprocess_HOOK().
*/
function localgov_base_preprocess_node(&$variables): void {
$node = $variables['node'];
$node_status = $variables['node']->isPublished();

if ($node instanceof NodeInterface && $variables['view_mode'] === 'full') {
// Restrict width of the content area to two-thirds of the screen for
// some content types. This is helpful to reduce the line-length for
// better readability.
$variables['restricted_width_content_types'] = [];
if (in_array($node->bundle(), _localgov_get_restricted_width_content_types(), TRUE)) {
$variables['restricted_width_content_types'][] = $node->bundle();
}

}

if ($node_status === FALSE) {
if (theme_get_setting('localgov_base_add_draft_note_to_unpublished_content') === TRUE) {
$variables['label'] = t('[Draft]') . " " . $variables['node']->label();
$state = $variables['node']->get('moderation_state')->getString();
if ($state == 'draft') {
$variables['label'] = t('[Draft]') . " " . $variables['node']->label();
}
}
}
// We have a theme setting to prepend 'archived' to the title of
// archived content, but we don't mind whether it is published or not.
// An archived state does not have to always be unpubilshed.
if (theme_get_setting('localgov_base_add_archived_note_to_archived_content') === TRUE) {
$state = $variables['node']->get('moderation_state')->getString();
if ($state == 'archived') {
$variables['label'] = t('[Archived]') . " " . $variables['node']->label();
}
}

Expand All @@ -224,7 +273,21 @@ function localgov_base_preprocess_block(&$variables): void {
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;
$state = $node->get('moderation_state')->getString();
if ($state == 'draft') {
$variables['content'][0]['#title'] = t('[Draft]') . " " . $current_title;
}
}
}

// We have a theme setting to prepend 'archived' to the title of
// archived content, but we don't mind whether it is published or not.
// An archived state does not have to always be unpubilshed.
if (theme_get_setting('localgov_base_add_archived_note_to_archived_content') === TRUE) {
$current_title = $variables['content'][0]['#title'];
$state = $node->get('moderation_state')->getString();
if ($state == 'archived') {
$variables['content'][0]['#title'] = t('[Archived]') . " " . $current_title;
}
}

Expand Down Expand Up @@ -302,18 +365,22 @@ function localgov_base_views_pre_render(ViewExecutable $view): void {
* Implements hook_preprocess_container().
*/
function localgov_base_preprocess_container(&$variables): void {

// Randomize form container IDs for accessibility.
// See https://www.drupal.org/project/drupal/issues/1852090
// Ensure the container has an ID.
if (isset($variables['element']['#id'])) {
$id = $variables['element']['#id'];
if ($id === 'edit-actions') {
$id .= '--' . Crypt::randomBytesBase64(8);
$original_id = $variables['element']['#id'];

// Check if the ID starts with 'edit-actions'.
if (strpos($original_id, 'edit-actions') === 0) {
$random_suffix = Crypt::randomBytesBase64(8);
$random_id = $original_id . '--' . $random_suffix;

// Keep a stable selector but allow ID randomization.
$variables['attributes']['id'] = $random_id;
$variables['attributes']['data-drupal-selector'] = $original_id;
$variables['element']['#attributes']['data-drupal-selector'] = $original_id;
$variables['element']['#id'] = $random_id;
}
$variables['attributes']['id'] = $id;
$variables['attributes']['data-drupal-selector'] = $id;
$variables['element']['#attributes']['data-drupal-selector'] = $id;
$variables['element']['#id'] = $id;
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 13 additions & 79 deletions templates/content/node--full.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,90 +71,24 @@
*/
#}

{#
Restrict width of the content area to two-thirds of the screen for
some content types. This is helpful to reduce the line-length for
better readability.
#}
{% set restricted_width_content_types = [
'localgov_services_page',
'localgov_event',
'localgov_step_by_step_overview',
'localgov_services_status',
'localgov_publication_cover_page'
]
%}

{% set content_type = node.bundle %}

{% if not localgov_base_remove_css %}
{{ attach_library('localgov_base/full') }}
{% if content_type == 'localgov_directories_venue'
or content_type == 'localgov_directories_page'
or content_type == 'localgov_directory' %}
{{ attach_library('localgov_base/directories') }}
{% endif %}

{% if content_type == 'localgov_event' %}
{{ attach_library('localgov_base/events') }}
{% endif %}

{% if content_type == 'localgov_step_by_step_overview'
or content_type == 'localgov_step_by_step_page' %}
{{ attach_library('localgov_base/step-by-step') }}
{% endif %}
{% if node.isPromoted() %}
{% set display_full_promoted = TRUE %}
{% endif %}

{%
set classes = [
content_type|clean_class,
'node',
'node--type-' ~ node.bundle|clean_class,
content_type in restricted_width_content_types ? 'node--with-restricted-width',
node.isPromoted() ? 'node--promoted',
node.isSticky() ? 'node--sticky',
not node.isPublished() ? 'node--unpublished',
view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
]
%}

<article{{ attributes.addClass(classes).removeAttribute('role') }}>

<div class="lgd-container padding-horizontal">
{{ title_prefix }}
{% if label and not page %}
<h2{{ title_attributes }}>
<a href="{{ url }}" rel="bookmark">{{ label }}</a>
</h2>
{% endif %}
{{ title_suffix }}

{% if display_submitted %}
<footer class="node__meta">
{{ author_picture }}
<div{{ author_attributes.addClass('node__submitted') }}>
{% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}
{{ metadata }}
</div>
</footer>
{% endif %}

{% if content_type in restricted_width_content_types %}
<div class="node__restricted-width-section">
{% endif %}
{% if node.isSticky() %}
{% set display_full_sticky = TRUE %}
{% endif %}

<div{{ content_attributes.addClass(content_type|clean_class ~ '__content', 'node__content') }}>
{{ content|without('localgov_subsites_content') }}
</div>
</div>
{% if not node.isPublished() %}
{% set display_full_unpublished = TRUE %}
{% endif %}

{% if node.localgov_subsites_content.value or content.localgov_subsites_content['#type'] == 'layout_paragraphs_builder' %}
{{ content.localgov_subsites_content }}
{% endif %}

{% set display_full_content = content|without('localgov_subsites_content') %}

{% if content_type in restricted_width_content_types %}
</div>
{% endif %}
{% if node.localgov_subsites_content.value or content.localgov_subsites_content['#type'] == 'layout_paragraphs_builder' %}
{% set localgov_subsites_content = content.localgov_subsites_content %}
{% endif %}

</article>
{% include "localgov_base:display-full" %}
Loading