Skip to content
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
208 changes: 6 additions & 202 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,207 +7,11 @@ on:
pull_request:
branches:
- '1.x'

env:
LOCALGOV_DRUPAL_PROJECT: localgovdrupal/localgov_forms
LOCALGOV_DRUPAL_PROJECT_PATH: web/modules/contrib/localgov_forms
workflow_dispatch:

jobs:

build:
name: Install LocalGov Drupal
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Save git branch and git repo names to env if this is not a pull request
if: github.event_name != 'pull_request'
run: |
echo "GIT_BASE=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "HEAD_USER=localgovdrupal" >> $GITHUB_ENV

- name: Save git branch and git repo names to env if this is a pull request
if: github.event_name == 'pull_request'
run: |
echo "GIT_BASE=${GITHUB_BASE_REF}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_HEAD_REF}" >> $GITHUB_ENV
export HEAD="${{ github.event.pull_request.head.label }}"
echo "HEAD_USER=${HEAD%%:*}" >> $GITHUB_ENV

- name: Set composer branch reference for version branches
if: endsWith(github.ref, '.x')
run: echo "COMPOSER_REF=${GIT_BRANCH}-dev" >> $GITHUB_ENV

- name: Set composer branch reference for non-version branches
if: endsWith(github.ref, '.x') == false
run: echo "COMPOSER_REF=dev-${GIT_BRANCH}" >> $GITHUB_ENV

- name: Get the latest tagged release for branch version
run: |
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)
if [ -z $LATEST_RELEASE ]; then LATEST_RELEASE=1; fi
echo "LATEST_RELEASE=${LATEST_RELEASE}" >> $GITHUB_ENV

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
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
with:
php-version: ${{ matrix.php-version }}

- name: Clone drupal_container
uses: actions/checkout@v2
with:
repository: localgovdrupal/drupal-container
ref: php${{ matrix.php-version }}

- name: Create LocalGov Drupal project
run: |
composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "${{ matrix.localgov-version }}"
composer --working-dir=./html require --no-install localgovdrupal/localgov:${{ matrix.localgov-version }}-dev
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 }}
composer --working-dir=./html install

- name: Obtain the test target using Composer
if: env.HEAD_USER == 'localgovdrupal'
run: |
composer --working-dir=html config repositories.1 vcs git@github.com:${LOCALGOV_DRUPAL_PROJECT}.git
composer global config github-oauth.github.com ${{ github.token }}
composer --working-dir=./html require --with-all-dependencies ${LOCALGOV_DRUPAL_PROJECT}:"${COMPOSER_REF} as ${LATEST_RELEASE}"
# Obtain test dependency.
composer --working-dir=./html require --dev --with-all-dependencies geocoder-php/nominatim-provider

- name: Obtain the test target using Git
if: env.HEAD_USER != 'localgovdrupal'
uses: actions/checkout@v2
with:
path: ${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}

phpcs:
name: Coding standards checks
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
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 }}-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Run coding standards checks
run: |
cd html
./bin/phpcs -p ${LOCALGOV_DRUPAL_PROJECT_PATH}

phpstan:
name: Deprecated code checks
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
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 }}-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Run deprecated code checks
run: |
cd html
./bin/phpstan analyse -c ./phpstan.neon ${LOCALGOV_DRUPAL_PROJECT_PATH}
phpunit:
name: PHPUnit tests
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Clone Drupal container
uses: actions/checkout@v2
with:
repository: localgovdrupal/drupal-container
ref: php${{ matrix.php-version }}

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
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 }}-

- name: Start Docker environment
run: docker-compose -f docker-compose.yml up -d

- name: Run PHPUnit tests
run: |
mkdir -p ./html/web/sites/simpletest && chmod 777 ./html/web/sites/simpletest
sed -i "s#http://localgov.lndo.site#http://drupal#" ./html/phpunit.xml.dist
docker exec -t drupal bash -c 'chown docker:docker -R /var/www/html'
docker exec -u docker -t drupal bash -c "cd /var/www/html && ./bin/paratest --processes=4 /var/www/html/${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}"
tests:
uses: localgovdrupal/localgov_shared_workflows/.github/workflows/test-module.yml@1.x
with:
project: 'localgovdrupal/localgov_forms'
project_path: 'web/modules/contrib/localgov_forms'
1 change: 1 addition & 0 deletions localgov_forms.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

declare(strict_types=1);

use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\webform\Utility\WebformDateHelper;

Expand Down
42 changes: 42 additions & 0 deletions modules/localgov_forms_date/localgov_forms_date.install
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,45 @@ function localgov_forms_date_update_8002() {
$uk_html_datetime_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
\Drupal::configFactory()->getEditable($config_id)->setData($uk_html_datetime_config)->save();
}

/**
* Adds a UUID to LocalGov Forms Date formats.
*/
function localgov_forms_date_update_8003() {
$localgov_date_formats = [
'core.date_format.localgov_forms_date_short_date',
'core.date_format.localgov_forms_date_datetime',
];

foreach ($localgov_date_formats as $date_format_uuid) {
// Date Format Name.
$config_id = $date_format_uuid;

// Generate a new uuid.
$uuid_service = \Drupal::service('uuid');
$uuid = $uuid_service->generate();

$config_factory = \Drupal::configFactory();
$date_format_uuid = $config_factory->getEditable($date_format_uuid);

// Get the date format's uuid.
$has_date_format_uuid = $date_format_uuid->get('uuid');

// Add a new uuid if the date format doesn't have one.
if (!$has_date_format_uuid) {

// Convert the date format config properties into an array.
$date_format_config = (array) $date_format_uuid;

// Change the uuid into a key value pair.
$new_uuid = ['uuid' => $uuid];

// Prepend the uuid to the date format config properties.
$date_format_properties = $new_uuid + $date_format_config["\0*\0data"];

// Save the date format config properties.
\Drupal::configFactory()->getEditable($config_id)->setData($date_format_properties)->save();

}
}
}
21 changes: 21 additions & 0 deletions modules/localgov_forms_date/src/Element/LocalgovFormsDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\localgov_forms_date\Element;

use Drupal\Component\Datetime\DateTimePlus;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Datetime\Element\Datelist;
use Drupal\Core\Form\FormStateInterface;

Expand Down Expand Up @@ -123,4 +124,24 @@ private static function restoreUnprocessedDate(array &$element) :void {
}
}

/**
* Validation callback - Has Required Message.
*
* When validating LocalGov Forms Date elements,
* if the date is a required field, a required message can
* be set in the UI which should take precedence over
* the default error message.
*/
public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form) {
$input_exists = FALSE;
$input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);

// Show the required message if it has been set in the UI.
if (empty($input['year']) && empty($input['month']) && empty($input['day']) && $element['#required'] && isset($element['#required_error'])) {
$form_state->setError($element, t('%field', ['%field' => $element['#required_error']]));
}

parent::validateDatelist($element, $form_state, $complete_form);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Drupal\webform\WebformSubmissionInterface;
*/
function localgov_forms_example_liberty_create_integration_modules_installed($modules, $is_syncing) {

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

$webform_submission = $handler->getWebformSubmission();
if (empty($webform_submission)) {
if (!$webform_submission instanceof WebformSubmissionInterface) {
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/AddressLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ public static function reformat(Location $addr) :array {
}

$address = [
'name' => $unique_id ?? '',
'uprn' => $uprn ?? '',
'display' => $display_name ?? '',
'name' => $unique_id,
'uprn' => $uprn,
'display' => $display_name,
'street' => implode(' ', array_filter([
$street_number, $street_name,
])),
'flat' => $flat ?? '',
'flat' => $flat,
'house' => implode(', ', array_filter([$org, $house_name])),
'town' => $locality ?? '',
'postcode' => $postcode ?? '',
'lat' => $latitude ?? '',
'lng' => $longitude ?? '',
'lat' => $latitude ?: '',
'lng' => $longitude ?: '',
'country' => $country_name ?? '',
'country_code' => $country_code ?? '',
'line1' => '',
Expand Down
9 changes: 8 additions & 1 deletion src/Element/AddressLookupElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static function processAddressLookupElement(&$element, FormStateInterface
$element['address_select']['address_select_list']['#disabled'] = FALSE;
$options = array_keys($element['address_select']['address_select_list']['#options']);
$selected = $parent_container_values['address_select']['address_select_list'] ?? 0;
if (!in_array($selected, $options)) {
if (!in_array($selected, $options, TRUE)) {
$element['address_select']['address_select_list']['#value'] = NULL;
}
}
Expand Down Expand Up @@ -267,6 +267,13 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
if (empty($input['address_search']['address_searchstring'])) {
return NULL;
}

// FIXME: Call to method valueCallback() of deprecated class
// Drupal\Core\Render\Element\FormElement: in drupal:10.3.0 and
// is removed from drupal:12.0.0.
// use \Drupal\Core\Render\Element\FormElementBase instead.
// @phpstan-ignore-next-line
return parent::valueCallback($element, $input, $form_state);
}

/**
Expand Down