Skip to content

Commit

Permalink
Merge pull request #338 from localgovdrupal/1.8.x
Browse files Browse the repository at this point in the history
1.8.x Refactor
  • Loading branch information
finnlewis authored Oct 15, 2024
2 parents 4caf287 + 15d819f commit f927fce
Show file tree
Hide file tree
Showing 40 changed files with 535 additions and 2,865 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- '1.x'
- '1.8.x'
pull_request:
branches:
- '1.x'
- '1.8.x'
workflow_dispatch:

jobs:
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
LocalGovDrupal Alert banner module, adds a global alert banner block and entity.

## Order of alerts

In terms of order, it should be Notable Death -> Major -> Minor -> Announcement and then in date updated order.

## Scheduling alert banners

Scheduling the publishing and unpublishing of alert banners is done using the [Scheduled Transitions](https://www.drupal.org/project/scheduled_transitions) module. Scheduling is not enabled by default. To turn it on just enable the Scheduled Transitions module.

## Disable provided CSS.

This module will provide default CSS colours so it can be used out the box. If you wish to theme these yourself, you can disable the provided CSS with the following code in your themes `THEMENAME.info.yml` file:
```yaml
libraries-override:
localgov_alert_banner/alert_banner:
css:
component:
css/localgov-alert-banner.css: false
```
## Maintainers
Current maintainers:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"license": "GPL-2.0-or-later",
"require": {
"drupal/condition_field": "^2.0",
"drupal/core": "^9.4 || ^10.0"
"drupal/core": "^10.0 || ^11.0"
},
"require-dev": {
"drupal/group": "^3.2",
"drupal/scheduled_transitions": "^2.1"
},
"suggest": {
"drupal/scheduled_transitions": "Gives the ability to schedule the publishing and unpublishing of alert banners",
"localgovdrupal/localgov_core": "^1 || ^2",
"localgovdrupal/localgov_core": "Required by localgov_alert_banner_full_page sub module for localgov_media.",
"drupal/group": "For Group integration."
}
}
2 changes: 1 addition & 1 deletion config/install/user.role.emergency_publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ label: 'Emergency publisher'
weight: -2
is_admin: null
permissions:
- 'access administration pages'
- 'access localgov alert banner listing page'
- 'manage all localgov alert banner entities'
- 'use localgov_alert_banners transition publish'
- 'use localgov_alert_banners transition unpublish'
- 'view all localgov alert banner entities'
- 'view all localgov alert banner entity pages'
- 'view the administration theme'
25 changes: 17 additions & 8 deletions js/alert_banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,45 @@
* This is so if the alert changes, the banner is reshown.
*/

(function($, cookies) {
(function($) {

'use strict';

function setAlertBannerHideCookie(cookie_tokens, token) {
cookie_tokens.push(token);
var new_cookie = cookie_tokens.join('+')
cookies.set('hide-alert-banner-token', new_cookie, { path: '/', expires: 30, SameSite: 'Lax' });
const new_cookie = cookie_tokens.join('+');
// Set expiry 30 days.
const expiry = Date.now() + (30 * 24 * 60 * 60 * 1000);
document.cookie = 'hide-alert-banner-token=' + new_cookie + '; expires=' + new Date(expiry).toString() + '; SameSite=Lax;'
}

$(document).ready(function() {

var cookie = cookies.get('hide-alert-banner-token');
var cookie_tokens = typeof cookie !== 'undefined' ? cookie.split('+') : [];
const all_cookies = document.cookie.split('; ');
let cookie;
for (let i = 0; i < all_cookies.length; i++) {
const indv_cookie = all_cookies[i].split('=');
if (indv_cookie[0] == 'hide-alert-banner-token') {
cookie = indv_cookie[1];
}
}
const cookie_tokens = typeof cookie !== 'undefined' ? cookie.split('+') : [];

$('.js-localgov-alert-banner').each(function() {
$(this).removeClass('hidden');
var token = $(this).data('dismiss-alert-token');
const token = $(this).data('dismiss-alert-token');
if ($.inArray(token, cookie_tokens) > -1) {
$(this).hide();
}
});

$('.js-localgov-alert-banner__close').click(function(e) {
e.preventDefault();
var banner = $(this).closest('.js-localgov-alert-banner');
const banner = $(this).closest('.js-localgov-alert-banner');
banner.attr("aria-hidden", "true").slideUp('fast');
setAlertBannerHideCookie(cookie_tokens, banner.data('dismiss-alert-token'));
});

});

}) (jQuery, window.Cookies);
}) (jQuery);
2 changes: 1 addition & 1 deletion localgov_alert_banner.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'LocalGov Alert Banner'
type: module
description: 'Provides a sitewide alert banner for urgent alerts.'
core_version_requirement: ^9.4 || ^10
core_version_requirement: ^10 || ^11
package: LocalGov Drupal
dependencies:
- drupal:block
Expand Down
28 changes: 25 additions & 3 deletions localgov_alert_banner.install
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ use Symfony\Component\Yaml\Yaml;
*/
function localgov_alert_banner_install($is_syncing) {

// Don't run this if syncing.
if ($is_syncing) {
return;
}

// Configure scheduled transitions if enabled.
if (\Drupal::moduleHandler()->moduleExists('scheduled_transitions')) {
localgov_alert_banner_configure_scheduled_transitions();
}

// Default grant permissions to view all alert banners.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['view all localgov alert banner entities']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['view all localgov alert banner entities']);
localgov_alert_banner_set_default_permissions();
}

/**
Expand Down Expand Up @@ -219,3 +222,22 @@ function localgov_alert_banner_update_9002() {
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['view localgov alert banner ' . $bundle . ' entities']);
}
}

/**
* Assign additional permissions to Emergency publisher role.
*
* Give emergency publisher permissions to access the alert banner manage screen
* from the toolbar.
*/
function localgov_alert_banner_update_10002() {
$module_handler = \Drupal::service('module_handler');
$perms[] = 'view the administration theme';
if ($module_handler->moduleExists('node')) {
$perms[] = 'access content overview';
}
if ($module_handler->moduleExists('toolbar')) {
$perms[] = 'access toolbar';
}
user_role_grant_permissions('emergency_publisher', $perms);
user_role_revoke_permissions('emergency_publisher', ['access administration pages']);
}
1 change: 0 additions & 1 deletion localgov_alert_banner.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ alert_banner:
js/alert_banner.js: {}
dependencies:
- core/jquery
- core/js-cookie
5 changes: 5 additions & 0 deletions localgov_alert_banner.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ entity.localgov_alert_banner.collection:
base_route: system.admin_content
title: 'Alert banners'
weight: 30

entity.localgov_alert_banner_type.edit_form:
title: Edit
route_name: entity.localgov_alert_banner_type.edit_form
base_route: entity.localgov_alert_banner_type.edit_form
37 changes: 37 additions & 0 deletions localgov_alert_banner.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Cache\Cache;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\user\RoleInterface;

/**
* Implements hook_help().
Expand Down Expand Up @@ -137,6 +138,29 @@ function localgov_alert_banner_configure_scheduled_transitions() {
user_role_grant_permissions('emergency_publisher', $permissions);
}

/**
* Setup deafault permissions.
*
* @todo consider using hook_localgov_roles().
*/
function localgov_alert_banner_set_default_permissions() {

// Default grant permissions to view all alert banners.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['view all localgov alert banner entities']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['view all localgov alert banner entities']);

// Set up emergency publisher access to toolbar if certian modules exist.
$perms = [];
$module_handler = \Drupal::service('module_handler');
if ($module_handler->moduleExists('node')) {
$perms[] = 'access content overview';
}
if ($module_handler->moduleExists('toolbar')) {
$perms[] = 'access toolbar';
}
user_role_grant_permissions('emergency_publisher', $perms);
}

/**
* Implements hook_preprocess_field().
*/
Expand All @@ -150,3 +174,16 @@ function localgov_alert_banner_preprocess_field(&$variables) {
}
}
}

/**
* Implements hook_gin_content_form_routes().
*/
function localgov_alert_banner_gin_content_form_routes() {
return [
// Alert banner add form.
'entity.localgov_alert_banner.add_form',

// Alert banner add form edit form.
'entity.localgov_alert_banner.edit_form',
];
}
44 changes: 0 additions & 44 deletions localgov_alert_banner.routing.yml

This file was deleted.

4 changes: 4 additions & 0 deletions localgov_alert_banner.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ services:
arguments: ['@current_user', '@current_route_match']
tags:
- { name: access_check }

localgov_alert_banner.manager:
class: Drupal\localgov_alert_banner\AlertBannerManager
arguments: ['@entity_type.manager', '@current_user', '@entity.repository']
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ display:
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
Expand Down
2 changes: 1 addition & 1 deletion modules/group_alert_banner/group_alert_banner.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Group Alert banner'
type: module
description: 'Enables Group functionality for Alert banners.'
package: 'LocalGov Drupal'
core_version_requirement: ^8.8 || ^9 || ^10
core_version_requirement: ^10 || ^11
dependencies:
- group:group
- localgov_alert_banner:localgov_alert_banner
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ dialog + .backdrop {
background: rgba(0, 0, 0, 1) !important;
}

.localgov-alert-banner-full h1,
.localgov-alert-banner-full p,
.localgov-alert-banner-full a {
color: #FFFFFF;
.localgov-alert-banner-full h1 {
color: inherit;
}

.localgov-alert-banner-full > .localgov-alert-banner-full--centered {
Expand Down
Loading

0 comments on commit f927fce

Please sign in to comment.