Skip to content

Commit

Permalink
Merge pull request #173 from localgovdrupal/1.x
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
Adnan-cds authored Sep 16, 2021
2 parents 45a823a + ad7efe8 commit f2d7124
Show file tree
Hide file tree
Showing 46 changed files with 3,513 additions and 47 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ 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.
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
"description": "LocalGovDrupal distribution: Alert banner.",
"homepage": "https://github.com/localgovdrupal/localgov_alert_banner",
"minimum-stability": "dev",
"license": "GPL-2.0-or-later",
"require": {
"drupal/condition_field": "^2.0",
"drupal/field_group": "~3.1"
},
"require-dev": {
"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"
},
"extra": {
"enable-patching": true,
"composer-exit-on-patch-failure": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- localgov_alert_banner
module:
- condition_field
- content_moderation
- link
- text
id: localgov_alert_banner.localgov_alert_banner.default
Expand Down Expand Up @@ -54,5 +55,6 @@ content:
link_to_entity: false
third_party_settings: { }
hidden:
content_moderation_control: true
type_of_alert: true
uid: true
2 changes: 2 additions & 0 deletions config/install/user.role.emergency_publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ 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'
56 changes: 56 additions & 0 deletions config/install/workflows.workflow.localgov_alert_banners.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
langcode: en
status: true
dependencies:
config:
- localgov_alert_banner.localgov_alert_banner_type.localgov_alert_banner
module:
- content_moderation
id: localgov_alert_banners
label: 'Alert banners'
type: content_moderation
type_settings:
states:
draft:
published: false
default_revision: false
label: Draft
weight: 0
published:
label: Published
published: true
default_revision: true
weight: 1
unpublished:
label: Unpublished
published: false
default_revision: true
weight: 2
transitions:
create_new_draft:
label: 'Create New Draft'
to: draft
weight: 0
from:
- draft
- published
- unpublished
publish:
label: Publish
to: published
weight: 1
from:
- draft
- published
- unpublished
unpublish:
label: Unpublish
to: unpublished
weight: 2
from:
- draft
- published
- unpublished
entity_types:
localgov_alert_banner:
- localgov_alert_banner
default_moderation_state: unpublished
4 changes: 4 additions & 0 deletions localgov_alert_banner.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ core_version_requirement: ^8.8 || ^9
package: LocalGov Drupal
dependencies:
- drupal:block
- drupal:content_moderation
- drupal:field
- drupal:field_group
- drupal:link
- drupal:node
- drupal:options
- drupal:user
- drupal:views
- drupal:workflows
- condition_field:condition_field
test_dependencies:
- scheduled_transitions:scheduled_transitions
133 changes: 133 additions & 0 deletions localgov_alert_banner.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@
* LocalGov Alert Banner install file.
*/

use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Symfony\Component\Yaml\Yaml;

/**
* Implements hook_install().
*/
function localgov_alert_banner_install($is_syncing) {

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

/**
* Update alert banner entity definition to include the token on the entity.
Expand Down Expand Up @@ -66,3 +80,122 @@ function localgov_alert_banner_update_8901() {
}
}
}

/**
* Add workflow and configure scheduled transitions if enabled.
*/
function localgov_alert_banner_update_9001() {

// Add localgov_alert_banner workflow config.
$workflows_workflow_localgov_alert_banner = <<<EOY
langcode: en
status: true
dependencies:
config:
- localgov_alert_banner.localgov_alert_banner_type.localgov_alert_banner
module:
- content_moderation
id: localgov_alert_banners
label: 'Alert banners'
type: content_moderation
type_settings:
states:
draft:
published: false
default_revision: false
label: Draft
weight: 0
published:
label: Published
published: true
default_revision: true
weight: 1
unpublished:
label: Unpublished
published: false
default_revision: true
weight: 2
transitions:
create_new_draft:
label: 'Create New Draft'
to: draft
weight: 0
from:
- draft
- published
- unpublished
publish:
label: Publish
to: published
weight: 1
from:
- draft
- published
- unpublished
unpublish:
label: Unpublish
to: unpublished
weight: 2
from:
- draft
- published
- unpublished
entity_types:
localgov_alert_banner:
- localgov_alert_banner
default_moderation_state: unpublished
EOY;
$workflow = \Drupal::service('config.factory')->getEditable('workflows.workflow.localgov_alert_banners');
assert($workflow instanceof Config);
if ($workflow->isNew()) {
$workflow->setData(Yaml::parse($workflows_workflow_localgov_alert_banner));
$workflow->save();
}

// Hide content moderation field on alert banner display.
$alert_banner_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('localgov_alert_banner');
foreach ($alert_banner_bundles as $bundle => $info) {
$form_display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('localgov_alert_banner.' . $bundle . '.default');
if ($form_display) {
$form_display->setComponent('content_moderation_control', [
'region' => 'hidden',
]);
$form_display->save();
}
}

// Check Scheduled Transitions module is enabled.
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('scheduled_transitions')) {

// Configure scheduled transitions for alert banners.
$scheduled_transitions_config = \Drupal::service('config.factory')->getEditable('scheduled_transitions.settings');
$bundles = [];
foreach ($alert_banner_bundles as $bundle => $info) {
$bundles[] = [
'entity_type' => 'localgov_alert_banner',
'bundle' => $bundle,
];
}
$scheduled_transitions_config->set('bundles', $bundles);
$scheduled_transitions_config->save();

Cache::invalidateTags([
'scheduled_transition_settings',
'config:scheduled_transitions.settings',
]);

// Add scheduling permissions to the emergency publisher user.
$permissions = [];
foreach ($alert_banner_bundles as $bundle => $info) {
$permissions = array_merge($permissions, [
'add scheduled transitions localgov_alert_banner ' . $bundle,
'reschedule scheduled transitions localgov_alert_banner ' . $bundle,
'view scheduled transitions localgov_alert_banner ' . $bundle,
]);
}
user_role_grant_permissions('emergency_publisher', $permissions);
}
}
46 changes: 46 additions & 0 deletions localgov_alert_banner.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Contains localgov_alert_banner.module.
*/

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

/**
Expand Down Expand Up @@ -75,3 +76,48 @@ function localgov_alert_banner_theme_suggestions_localgov_alert_banner(array $va
$suggestions[] = 'localgov_alert_banner__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;
}

/**
* Implements hook_modules_installed().
*/
function localgov_alert_banner_modules_installed($modules, $is_syncing) {

// Configure scheduled transitions if it's being installed.
if (in_array('scheduled_transitions', $modules)) {
localgov_alert_banner_configure_scheduled_transitions();
}
}

/**
* Configure scheduled transitions.
*/
function localgov_alert_banner_configure_scheduled_transitions() {

// Configure scheduled transitions for alert banners.
$scheduled_transitions_config = \Drupal::service('config.factory')->getEditable('scheduled_transitions.settings');
$alert_banner_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('localgov_alert_banner');
$bundles = [];
foreach ($alert_banner_bundles as $bundle => $info) {
$bundles[] = [
'entity_type' => 'localgov_alert_banner',
'bundle' => $bundle,
];
}
$scheduled_transitions_config->set('bundles', $bundles);
$scheduled_transitions_config->save();
Cache::invalidateTags([
'scheduled_transition_settings',
'config:scheduled_transitions.settings',
]);

// Add scheduling permissions to the emergency publisher user.
$permissions = [];
foreach ($alert_banner_bundles as $bundle => $info) {
$permissions = array_merge($permissions, [
'add scheduled transitions localgov_alert_banner ' . $bundle,
'reschedule scheduled transitions localgov_alert_banner ' . $bundle,
'view scheduled transitions localgov_alert_banner ' . $bundle,
]);
}
user_role_grant_permissions('emergency_publisher', $permissions);
}
Loading

0 comments on commit f2d7124

Please sign in to comment.