Skip to content

Commit

Permalink
Merge pull request #611 from localgovdrupal/feature/3.x/543-content-lock
Browse files Browse the repository at this point in the history
[3.x] Add but don't enable the Content Lock module
  • Loading branch information
finnlewis authored Sep 4, 2023
2 parents d66cfdc + 9363aa1 commit 1e9b949
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"require": {
"drupal/admin_toolbar": "^3.0",
"drupal/content_lock": "^2.3",
"drupal/core": "^10.0",
"drupal/gin": "^3.0@alpha",
"drupal/gin_login": "^1.0@RC",
Expand Down
11 changes: 11 additions & 0 deletions modules/localgov_content_lock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# LocalGov Drupal Content Lock

Customises the Content Lock module for use with LocalGov Drupal.

When enabled this module will:

* Enable the Content Lock and Content Lock Timeout modules.
* Enables content locking for all enabled content types.
* Adds a link to the content lock view to the content admin page and the admin menu.

The default content lock timeout is left at 30 minutes. This can be changed at /admin/config/content/content_lock/timeout.
8 changes: 8 additions & 0 deletions modules/localgov_content_lock/localgov_content_lock.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: LocalGov Content Lock
type: module
description: Customises the Content Lock module for use with LocalGov Drupal
package: LocalGov Drupal
core_version_requirement: ^9 || ^10
dependencies:
- content_lock:content_lock
- content_lock:content_lock_timeout
22 changes: 22 additions & 0 deletions modules/localgov_content_lock/localgov_content_lock.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @file
* Install, update and uninstall functions for the LocalGov Content Lock module.
*/

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

if ($is_syncing) {
return;
}

// Enable content locking on all content types.
$config_factory = \Drupal::configFactory();
$content_lock_config = $config_factory->getEditable('content_lock.settings');
$content_lock_config->set('types.node', ['*' => '*']);
$content_lock_config->save();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
localgov_content_lock.locked_content:
title: 'Locked content'
parent: system.admin_content
route_name: view.locked_content.page_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
localgov_content_lock.locked_content:
title: 'Locked'
parent_id: system.admin_content
route_name: view.locked_content.page_1
weight: 100
6 changes: 6 additions & 0 deletions modules/localgov_content_lock/localgov_content_lock.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

/**
* @file
* Primary module hooks for LocalGov Content Lock module.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Drupal\Tests\localgov_content_lock\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Functional tests for LocalGov Content Lock module.
*/
class ContentLockTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $profile = 'localgov';

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
public static $modules = [
'localgov_content_lock',
];

/**
* Test content lock configuration.
*/
public function testContentLockConfiguration() {

$user = $this->drupalCreateUser([], 'test_user', TRUE);
$this->drupalLogin($user);

// Create a node.
$this->drupalGet('/node/add/localgov_services_page');
$title = $this->randomMachineName();
$this->submitForm(
[
'title[0][value]' => $title,
'body[0][summary]' => 'Test content lock',
'body[0][value]' => 'Test content lock',
],
'Save'
);
$this->assertSession()->pageTextContains('Service page ' . $title . ' has been created.');
$nid = $this->drupalGetNodeByTitle($title)->id();

// Check that the node gets locked when editing.
$this->drupalGet('/node/' . $nid . '/edit');
$this->assertSession()->pageTextContains('This content is now locked against simultaneous editing.');
$this->drupalGet('/admin/content/locked-content');
$this->assertSession()->pageTextContains($title);
}

}

0 comments on commit 1e9b949

Please sign in to comment.