Skip to content

Commit 06b9a55

Browse files
authored
Merge pull request #81 from localgovdrupal/1.x
1.0.0-beta7 release
2 parents 6df2c2f + c62b313 commit 06b9a55

File tree

7 files changed

+86
-211
lines changed

7 files changed

+86
-211
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -7,207 +7,11 @@ on:
77
pull_request:
88
branches:
99
- '1.x'
10-
11-
env:
12-
LOCALGOV_DRUPAL_PROJECT: localgovdrupal/localgov_forms
13-
LOCALGOV_DRUPAL_PROJECT_PATH: web/modules/contrib/localgov_forms
10+
workflow_dispatch:
1411

1512
jobs:
16-
17-
build:
18-
name: Install LocalGov Drupal
19-
runs-on: ubuntu-latest
20-
21-
strategy:
22-
fail-fast: false
23-
matrix:
24-
include:
25-
- localgov-version: '2.x'
26-
drupal-version: '~9.4'
27-
php-version: '8.1'
28-
- localgov-version: '3.x'
29-
drupal-version: '~10.0'
30-
php-version: '8.1'
31-
32-
steps:
33-
34-
- name: Save git branch and git repo names to env if this is not a pull request
35-
if: github.event_name != 'pull_request'
36-
run: |
37-
echo "GIT_BASE=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
38-
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
39-
echo "HEAD_USER=localgovdrupal" >> $GITHUB_ENV
40-
41-
- name: Save git branch and git repo names to env if this is a pull request
42-
if: github.event_name == 'pull_request'
43-
run: |
44-
echo "GIT_BASE=${GITHUB_BASE_REF}" >> $GITHUB_ENV
45-
echo "GIT_BRANCH=${GITHUB_HEAD_REF}" >> $GITHUB_ENV
46-
export HEAD="${{ github.event.pull_request.head.label }}"
47-
echo "HEAD_USER=${HEAD%%:*}" >> $GITHUB_ENV
48-
49-
- name: Set composer branch reference for version branches
50-
if: endsWith(github.ref, '.x')
51-
run: echo "COMPOSER_REF=${GIT_BRANCH}-dev" >> $GITHUB_ENV
52-
53-
- name: Set composer branch reference for non-version branches
54-
if: endsWith(github.ref, '.x') == false
55-
run: echo "COMPOSER_REF=dev-${GIT_BRANCH}" >> $GITHUB_ENV
56-
57-
- name: Get the latest tagged release for branch version
58-
run: |
59-
LATEST_RELEASE=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${GIT_BASE%'.x'} | grep -Po '(?<=refs/tags/)[^"]+' | tail -1)
60-
if [ -z $LATEST_RELEASE ]; then LATEST_RELEASE=1; fi
61-
echo "LATEST_RELEASE=${LATEST_RELEASE}" >> $GITHUB_ENV
62-
63-
- name: Cached workspace
64-
uses: actions/cache@v2
65-
with:
66-
path: ./html
67-
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
68-
69-
- name: Setup PHP
70-
uses: shivammathur/setup-php@v2
71-
with:
72-
php-version: ${{ matrix.php-version }}
73-
74-
- name: Clone drupal_container
75-
uses: actions/checkout@v2
76-
with:
77-
repository: localgovdrupal/drupal-container
78-
ref: php${{ matrix.php-version }}
79-
80-
- name: Create LocalGov Drupal project
81-
run: |
82-
composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "${{ matrix.localgov-version }}"
83-
composer --working-dir=./html require --no-install localgovdrupal/localgov:${{ matrix.localgov-version }}-dev
84-
composer --working-dir=./html require --no-install drupal/core-recommended:${{ matrix.drupal-version }} drupal/core-composer-scaffold:${{ matrix.drupal-version }} drupal/core-project-message:${{ matrix.drupal-version }} drupal/core-dev:${{ matrix.drupal-version }}
85-
composer --working-dir=./html install
86-
87-
- name: Obtain the test target using Composer
88-
if: env.HEAD_USER == 'localgovdrupal'
89-
run: |
90-
composer --working-dir=html config repositories.1 vcs [email protected]:${LOCALGOV_DRUPAL_PROJECT}.git
91-
composer global config github-oauth.github.com ${{ github.token }}
92-
composer --working-dir=./html require --with-all-dependencies ${LOCALGOV_DRUPAL_PROJECT}:"${COMPOSER_REF} as ${LATEST_RELEASE}"
93-
# Obtain test dependency.
94-
composer --working-dir=./html require --dev --with-all-dependencies geocoder-php/nominatim-provider
95-
96-
- name: Obtain the test target using Git
97-
if: env.HEAD_USER != 'localgovdrupal'
98-
uses: actions/checkout@v2
99-
with:
100-
path: ${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}
101-
102-
phpcs:
103-
name: Coding standards checks
104-
needs: build
105-
runs-on: ubuntu-latest
106-
107-
strategy:
108-
fail-fast: false
109-
matrix:
110-
include:
111-
- localgov-version: '2.x'
112-
drupal-version: '~9.4'
113-
php-version: '8.1'
114-
- localgov-version: '3.x'
115-
drupal-version: '~10.0'
116-
php-version: '8.1'
117-
118-
steps:
119-
120-
- name: Cached workspace
121-
uses: actions/cache@v2
122-
with:
123-
path: ./html
124-
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
125-
restore-keys: |
126-
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
127-
128-
- name: Setup PHP
129-
uses: shivammathur/setup-php@v2
130-
with:
131-
php-version: ${{ matrix.php-version }}
132-
133-
- name: Run coding standards checks
134-
run: |
135-
cd html
136-
./bin/phpcs -p ${LOCALGOV_DRUPAL_PROJECT_PATH}
137-
138-
phpstan:
139-
name: Deprecated code checks
140-
needs: build
141-
runs-on: ubuntu-latest
142-
143-
strategy:
144-
fail-fast: false
145-
matrix:
146-
include:
147-
- localgov-version: '2.x'
148-
drupal-version: '~9.4'
149-
php-version: '8.1'
150-
- localgov-version: '3.x'
151-
drupal-version: '~10.0'
152-
php-version: '8.1'
153-
154-
steps:
155-
156-
- name: Cached workspace
157-
uses: actions/cache@v2
158-
with:
159-
path: ./html
160-
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
161-
restore-keys: |
162-
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
163-
164-
- name: Setup PHP
165-
uses: shivammathur/setup-php@v2
166-
with:
167-
php-version: ${{ matrix.php-version }}
168-
169-
- name: Run deprecated code checks
170-
run: |
171-
cd html
172-
./bin/phpstan analyse -c ./phpstan.neon ${LOCALGOV_DRUPAL_PROJECT_PATH}
173-
phpunit:
174-
name: PHPUnit tests
175-
needs: build
176-
runs-on: ubuntu-latest
177-
178-
strategy:
179-
fail-fast: false
180-
matrix:
181-
include:
182-
- localgov-version: '2.x'
183-
drupal-version: '~9.4'
184-
php-version: '8.1'
185-
- localgov-version: '3.x'
186-
drupal-version: '~10.0'
187-
php-version: '8.1'
188-
189-
steps:
190-
191-
- name: Clone Drupal container
192-
uses: actions/checkout@v2
193-
with:
194-
repository: localgovdrupal/drupal-container
195-
ref: php${{ matrix.php-version }}
196-
197-
- name: Cached workspace
198-
uses: actions/cache@v2
199-
with:
200-
path: ./html
201-
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
202-
restore-keys: |
203-
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
204-
205-
- name: Start Docker environment
206-
run: docker-compose -f docker-compose.yml up -d
207-
208-
- name: Run PHPUnit tests
209-
run: |
210-
mkdir -p ./html/web/sites/simpletest && chmod 777 ./html/web/sites/simpletest
211-
sed -i "s#http://localgov.lndo.site#http://drupal#" ./html/phpunit.xml.dist
212-
docker exec -t drupal bash -c 'chown docker:docker -R /var/www/html'
213-
docker exec -u docker -t drupal bash -c "cd /var/www/html && ./bin/paratest --processes=4 /var/www/html/${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}"
13+
tests:
14+
uses: localgovdrupal/localgov_shared_workflows/.github/workflows/[email protected]
15+
with:
16+
project: 'localgovdrupal/localgov_forms'
17+
project_path: 'web/modules/contrib/localgov_forms'

localgov_forms.tokens.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
declare(strict_types=1);
99

10+
use Drupal\Core\Datetime\Entity\DateFormat;
1011
use Drupal\Core\Render\BubbleableMetadata;
1112
use Drupal\webform\Utility\WebformDateHelper;
1213

modules/localgov_forms_date/localgov_forms_date.install

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,45 @@ function localgov_forms_date_update_8002() {
2626
$uk_html_datetime_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
2727
\Drupal::configFactory()->getEditable($config_id)->setData($uk_html_datetime_config)->save();
2828
}
29+
30+
/**
31+
* Adds a UUID to LocalGov Forms Date formats.
32+
*/
33+
function localgov_forms_date_update_8003() {
34+
$localgov_date_formats = [
35+
'core.date_format.localgov_forms_date_short_date',
36+
'core.date_format.localgov_forms_date_datetime',
37+
];
38+
39+
foreach ($localgov_date_formats as $date_format_uuid) {
40+
// Date Format Name.
41+
$config_id = $date_format_uuid;
42+
43+
// Generate a new uuid.
44+
$uuid_service = \Drupal::service('uuid');
45+
$uuid = $uuid_service->generate();
46+
47+
$config_factory = \Drupal::configFactory();
48+
$date_format_uuid = $config_factory->getEditable($date_format_uuid);
49+
50+
// Get the date format's uuid.
51+
$has_date_format_uuid = $date_format_uuid->get('uuid');
52+
53+
// Add a new uuid if the date format doesn't have one.
54+
if (!$has_date_format_uuid) {
55+
56+
// Convert the date format config properties into an array.
57+
$date_format_config = (array) $date_format_uuid;
58+
59+
// Change the uuid into a key value pair.
60+
$new_uuid = ['uuid' => $uuid];
61+
62+
// Prepend the uuid to the date format config properties.
63+
$date_format_properties = $new_uuid + $date_format_config["\0*\0data"];
64+
65+
// Save the date format config properties.
66+
\Drupal::configFactory()->getEditable($config_id)->setData($date_format_properties)->save();
67+
68+
}
69+
}
70+
}

modules/localgov_forms_date/src/Element/LocalgovFormsDate.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\localgov_forms_date\Element;
44

55
use Drupal\Component\Datetime\DateTimePlus;
6+
use Drupal\Component\Utility\NestedArray;
67
use Drupal\Core\Datetime\Element\Datelist;
78
use Drupal\Core\Form\FormStateInterface;
89

@@ -123,4 +124,24 @@ private static function restoreUnprocessedDate(array &$element) :void {
123124
}
124125
}
125126

127+
/**
128+
* Validation callback - Has Required Message.
129+
*
130+
* When validating LocalGov Forms Date elements,
131+
* if the date is a required field, a required message can
132+
* be set in the UI which should take precedence over
133+
* the default error message.
134+
*/
135+
public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form) {
136+
$input_exists = FALSE;
137+
$input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);
138+
139+
// Show the required message if it has been set in the UI.
140+
if (empty($input['year']) && empty($input['month']) && empty($input['day']) && $element['#required'] && isset($element['#required_error'])) {
141+
$form_state->setError($element, t('%field', ['%field' => $element['#required_error']]));
142+
}
143+
144+
parent::validateDatelist($element, $form_state, $complete_form);
145+
}
146+
126147
}

modules/localgov_forms_example_liberty_create_integration/localgov_forms_example_liberty_create_integration.module

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Drupal\webform\WebformSubmissionInterface;
2222
*/
2323
function localgov_forms_example_liberty_create_integration_modules_installed($modules, $is_syncing) {
2424

25-
if (!$is_syncing && in_array('token_environment', $modules)) {
25+
if (!$is_syncing && in_array('token_environment', $modules, TRUE)) {
2626
$token_env_config = Drupal::service('config.factory')->getEditable('token_environment.settings');
2727
$allowed_env_vars = $token_env_config->get('allowed_env_variables') ?? [];
2828
$allowed_env_vars[] = 'DRUPAL_LIBERTY_CREATE_API_AUTH_KEY';
@@ -124,7 +124,7 @@ function localgov_forms_example_liberty_create_integration_webform_handler_invok
124124
function _localgov_forms_example_liberty_create_integration_manage_remote_post_custom_data(WebformHandlerInterface $handler) {
125125

126126
$webform_submission = $handler->getWebformSubmission();
127-
if (empty($webform_submission)) {
127+
if (!$webform_submission instanceof WebformSubmissionInterface) {
128128
return;
129129
}
130130

src/AddressLookup.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ public static function reformat(Location $addr) :array {
102102
}
103103

104104
$address = [
105-
'name' => $unique_id ?? '',
106-
'uprn' => $uprn ?? '',
107-
'display' => $display_name ?? '',
105+
'name' => $unique_id,
106+
'uprn' => $uprn,
107+
'display' => $display_name,
108108
'street' => implode(' ', array_filter([
109109
$street_number, $street_name,
110110
])),
111-
'flat' => $flat ?? '',
111+
'flat' => $flat,
112112
'house' => implode(', ', array_filter([$org, $house_name])),
113113
'town' => $locality ?? '',
114114
'postcode' => $postcode ?? '',
115-
'lat' => $latitude ?? '',
116-
'lng' => $longitude ?? '',
115+
'lat' => $latitude ?: '',
116+
'lng' => $longitude ?: '',
117117
'country' => $country_name ?? '',
118118
'country_code' => $country_code ?? '',
119119
'line1' => '',

src/Element/AddressLookupElement.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static function processAddressLookupElement(&$element, FormStateInterface
198198
$element['address_select']['address_select_list']['#disabled'] = FALSE;
199199
$options = array_keys($element['address_select']['address_select_list']['#options']);
200200
$selected = $parent_container_values['address_select']['address_select_list'] ?? 0;
201-
if (!in_array($selected, $options)) {
201+
if (!in_array($selected, $options, TRUE)) {
202202
$element['address_select']['address_select_list']['#value'] = NULL;
203203
}
204204
}
@@ -267,6 +267,13 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
267267
if (empty($input['address_search']['address_searchstring'])) {
268268
return NULL;
269269
}
270+
271+
// FIXME: Call to method valueCallback() of deprecated class
272+
// Drupal\Core\Render\Element\FormElement: in drupal:10.3.0 and
273+
// is removed from drupal:12.0.0.
274+
// use \Drupal\Core\Render\Element\FormElementBase instead.
275+
// @phpstan-ignore-next-line
276+
return parent::valueCallback($element, $input, $form_state);
270277
}
271278

272279
/**

0 commit comments

Comments
 (0)