Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
68efc61
Added HTML attributes and date validation constriant
MattOz-CDS Oct 19, 2021
f335acb
Fixed coding standard issues
MattOz-CDS Oct 19, 2021
c10c240
Fixed coding standard issues
MattOz-CDS Oct 19, 2021
0691a9f
Fixed coding standard issues
MattOz-CDS Oct 19, 2021
7644b9c
Fixed coding standard issues
MattOz-CDS Oct 19, 2021
ca3b0cc
Fixed coding standard issues
MattOz-CDS Oct 19, 2021
bd38d32
Merge remote-tracking branch 'remotes/origin/feature/os-places-geocod…
Adnan-cds Oct 20, 2021
274a9df
Added styling to localgov forms date element
MattOz-CDS Feb 9, 2022
ded7731
Merge branch 'feature/localgov-forms-date-styling' into wip/all-pr-20…
MattOz-CDS Feb 9, 2022
cc02aec
Merge branch '1.x' into wip/all-pr-2021-10-20
Adnan-cds Feb 10, 2022
5e78b4d
Add media query and selectors
cjstevens78 Feb 14, 2022
7ef75a7
Merge remote-tracking branch 'origin/fix/3-non-existent-php-interface…
Adnan-cds Feb 25, 2022
072b3c3
Merge pull request #16 from localgovdrupal/feature/date-validation
Adnan-cds Mar 11, 2022
c3726a3
Removed redundant function and applied coding standard
MattOz-CDS Mar 19, 2022
18275ce
Merge branch 'feature/localgov-forms-date-styling' into wip/all-pr-20…
MattOz-CDS Mar 21, 2022
7ebea9b
Added validation above input field
MattOz-CDS Apr 28, 2022
d21c8eb
Corrected comment typo
MattOz-CDS Apr 29, 2022
8e43465
Added the localgov date field required error class
MattOz-CDS May 20, 2022
8c6abfa
Added the localgov date field required error class
MattOz-CDS May 20, 2022
c94ebe9
Merge branch '1.x' into feature/date-styling-and-validation
MattOz-CDS May 23, 2022
a38a6b3
Removed redundant validation contraint
MattOz-CDS May 26, 2022
8585d6b
Added date time preprocess to achieve theme override
MattOz-CDS May 26, 2022
5fb1e99
Added amd amended if condition
MattOz-CDS May 26, 2022
4378a76
Coding standard fix - added comment
MattOz-CDS May 26, 2022
607bdfa
Removed unneeded function
MattOz-CDS May 27, 2022
38e1a08
Added a check to see thatform element is a localgov form date element
MattOz-CDS May 27, 2022
40988c4
Removed classes from classList contains function
MattOz-CDS May 27, 2022
246accc
Removed redundant twig templates
MattOz-CDS May 27, 2022
b2e6f30
Removed commented code
MattOz-CDS May 27, 2022
7048cd4
Removed classes from classList contains function
MattOz-CDS May 27, 2022
6c2c81e
Removed unneeded theme function
MattOz-CDS May 27, 2022
d28e7b4
Added theme wrapper declaration
MattOz-CDS May 27, 2022
e3d15ad
Amended if condition
MattOz-CDS May 27, 2022
29e4863
Added date styling fix
MattOz-CDS May 27, 2022
5dd5a81
Removed js that moved the error message above form inpuut
MattOz-CDS Jun 7, 2022
5204af2
Removed reference to js from localgov_forms.libraries.yml
MattOz-CDS Jun 7, 2022
04e9d7d
Updated workflow
MattOz-CDS Jun 23, 2022
a9eee6a
Coding Standards fix
MattOz-CDS Jun 23, 2022
f9bd92b
Coding standards: Resolved deprecation notice.
Adnan-cds Aug 1, 2022
a5926eb
Fix: Non-numeric date handling for PHP 8.x.
Adnan-cds Aug 1, 2022
5361b4c
Fix: Non-numeric date handling for PHP 8.x.
Adnan-cds Aug 1, 2022
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
88 changes: 60 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: Test LocalGov Drupal
##
# Managed by https://github.com/localgovdrupal/github_workflow_manager
---
name: Test localgovdrupal/localgov_forms drupal-module

on:
push:
Expand All @@ -8,33 +11,43 @@ on:
branches:
- '1.x'

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

jobs:

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

strategy:
fail-fast: false
matrix:
include:
- localgov-version: "2.x"
drupal-version: "~9.1"
php-version: "7.4"
localgov-version:
- '2.x'
drupal-version:
- '~9.3'
php-version:
- '7.4'
- '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 "GIT_REPO=${GITHUB_REPOSITORY}" >> $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
echo "GIT_REPO=${{ github.event.pull_request.head.repo.full_name }}" >> $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')
Expand Down Expand Up @@ -74,11 +87,18 @@ jobs:
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 from the repo that triggered this workflow
- name: Obtain the test target using Composer
if: env.HEAD_USER == 'localgovdrupal'
run: |
composer --working-dir=html config repositories.1 vcs git@github.com:${GIT_REPO}.git
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 localgovdrupal/${{ github.event.repository.name }}:"${COMPOSER_REF} as ${LATEST_RELEASE}"
composer --working-dir=./html require --with-all-dependencies ${LOCALGOV_DRUPAL_PROJECT}:"${COMPOSER_REF} as ${LATEST_RELEASE}"

- 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
Expand All @@ -88,12 +108,16 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- localgov-version: "2.x"
drupal-version: "~9.1"
php-version: "7.4"
localgov-version:
- '2.x'
drupal-version:
- '~9.3'
php-version:
- '7.4'
- '8.1'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
Expand All @@ -105,12 +129,12 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: ${{ matrix.php-version }}

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

phpstan:
name: Deprecated code checks
Expand All @@ -120,12 +144,16 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- localgov-version: "2.x"
drupal-version: "~9.1"
php-version: "7.4"
localgov-version:
- '2.x'
drupal-version:
- '~9.3'
php-version:
- '7.4'
- '8.1'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
Expand All @@ -137,13 +165,12 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: ${{ matrix.php-version }}

- name: Run deprecated code checks
run: |
cd html
./bin/phpstan analyse -c ./phpstan.neon ./web/modules/contrib/localgov_forms

./bin/phpstan analyse -c ./phpstan.neon ${LOCALGOV_DRUPAL_PROJECT_PATH}
phpunit:
name: PHPUnit tests
needs: build
Expand All @@ -152,12 +179,16 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- localgov-version: "2.x"
drupal-version: "~9.1"
php-version: "7.4"
localgov-version:
- '2.x'
drupal-version:
- '~9.3'
php-version:
- '7.4'
- '8.1'

steps:

- name: Clone Drupal container
uses: actions/checkout@v2
with:
Expand All @@ -178,5 +209,6 @@ jobs:
- 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"
docker exec -u docker -t drupal bash -c "cd /var/www/html && ./bin/paratest --processes=4 ${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}"
4 changes: 2 additions & 2 deletions localgov_forms.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Hook implementations.
*/

module_load_include('inc', 'webform', 'includes/webform.theme.template');

/**
* Implements hook_theme().
*/
Expand All @@ -29,6 +27,8 @@ function localgov_forms_theme() {
*/
function template_preprocess_localgov_forms_uk_address(array &$variables) {
// Here you can get the composite element and alter it.
Drupal::moduleHandler()->loadInclude('webform', 'inc', 'includes/webform.theme.template');

_template_preprocess_webform_composite($variables);
}

Expand Down
40 changes: 40 additions & 0 deletions modules/localgov_forms_date/css/date.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.localgov-forms-date {
display: flex;
flex-wrap: wrap;
}

.localgov-forms-date div[class*="-day"] {
margin-left: 0em;
flex: 1;
max-width: 100%;
margin-top: 0.5em;
margin-right: 0.5em;
}

.localgov-forms-date div[class*="-month"] {
flex: 2;
margin: 0.5em;
max-width: 100%;
}

.localgov-forms-date div[class*="-year"] {
flex: 3;
max-width: 100%;
margin: 0.5em;
}

.localgov-forms-date > .form-item--error-message {
flex: 0 0 100%;
}

@media screen and (min-width: 64rem) {
.localgov-forms-date div[class*="-day"] {
max-width: 6%;
}
.localgov-forms-date div[class*="-month"] {
max-width: 6%;
}
.localgov-forms-date div[class*="-year"] {
max-width: 9%;
}
}
5 changes: 5 additions & 0 deletions modules/localgov_forms_date/localgov_forms_date.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
localgov_forms_date:
version: VERSION
css:
theme:
css/date.css: {}
17 changes: 17 additions & 0 deletions modules/localgov_forms_date/localgov_forms_date.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @file
* LocalGov Forms Date module.
*/

/**
* Datetime Form preprocess function.
*/
function localgov_forms_date_preprocess_datetime_form(array &$variables) {
// Check that this is a localgov_forms_date form element.
if ($variables['element']['#type'] === 'localgov_forms_date') {
$variables['attributes']['class'][] = 'localgov-forms-date';
$variables['#attached']['library'][] = 'localgov_forms_date/localgov_forms_date';
}
}
26 changes: 26 additions & 0 deletions modules/localgov_forms_date/src/Element/LocalgovFormsDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\localgov_forms_date\Element;

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

Expand Down Expand Up @@ -37,6 +38,31 @@ public function getInfo() {
];
}

/**
* Wrapper over Datelist::valueCallback().
*
* Absorbs non-numeric day, month, or year values such as "1a", "dd", etc.
* Such values leads PHP 8.x's checkdate() to throw TypeError exceptions
* which core's Datelist class does not process gracefully yet.
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
try {
return parent::valueCallback($element, $input, $form_state);
}
catch (\TypeError $e) {
// This error msg will cancel any other error message added in
// ::areDatePartsNumeric().
// @see https://www.drupal.org/project/drupal/issues/2818437
$form_state->setError($element, t('Non-numeric date parts detected.'));

// Suppress PHP warning in Datelist::validateDatelist().
$placeholder_date = DateTimePlus::createFromArray([], $element['#date_timezone']);
$return = $input;
$return['object'] = $placeholder_date;
return $return;
}
}

/**
* Validation callback.
*
Expand Down