Skip to content

Commit 384cb84

Browse files
committed
Cleaned up and improved XML helper
1 parent 9ee3b7a commit 384cb84

12 files changed

Lines changed: 905 additions & 191 deletions

File tree

.github/workflows/twig.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Do not edit this file! Make a pull request on changing
2+
# github/workflows/twig.yaml in
3+
# https://github.com/itk-dev/devops_itkdev-docker if need be.
4+
5+
### ### Twig
6+
###
7+
### Validates Twig files
8+
###
9+
### #### Assumptions
10+
###
11+
### 1. A docker compose service named `phpfpm` can be run and `composer` can be
12+
### run inside the `phpfpm` service.
13+
### 2. [vincentlanglet/twig-cs-fixer](https://github.com/VincentLanglet/Twig-CS-Fixer)
14+
### is a dev requirement in `composer.json`:
15+
###
16+
### ``` shell
17+
### docker compose run --rm phpfpm composer require --dev vincentlanglet/twig-cs-fixer
18+
### ```
19+
###
20+
### 3. A [Configuration
21+
### file](https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md#configuration-file)
22+
### in the root of the project defines which files to check and rules to use.
23+
24+
name: Twig
25+
26+
env:
27+
COMPOSE_USER: root
28+
29+
on:
30+
pull_request:
31+
push:
32+
branches:
33+
- main
34+
- develop
35+
36+
jobs:
37+
twig-lint:
38+
runs-on: ubuntu-latest
39+
strategy:
40+
fail-fast: false
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
45+
- run: |
46+
docker network create frontend
47+
docker compose run --rm phpfpm composer install
48+
docker compose run --rm phpfpm vendor/bin/twig-cs-fixer lint

.twig-cs-fixer.dist.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
// This file is copied from config/drupal/twig/.twig-cs-fixer.dist.php in https://github.com/itk-dev/devops_itkdev-docker.
3+
// Feel free to edit the file, but consider making a pull request if you find a general issue with the file.
4+
5+
// https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md#configuration-file
6+
7+
$finder = new TwigCsFixer\File\Finder();
8+
// Check all files …
9+
$finder->in(__DIR__);
10+
// … that are not ignored by VCS
11+
$finder->ignoreVCSIgnored(true);
12+
13+
$config = new TwigCsFixer\Config\Config();
14+
$config->setFinder($finder);
15+
16+
// @see https://github.com/VincentLanglet/Twig-CS-Fixer/pull/134#issuecomment-1756924889
17+
$config->addTokenParser(new Drupal\Core\Template\TwigTransTokenParser());
18+
19+
return $config;

Taskfile.yml

Lines changed: 101 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,112 @@ tasks:
1515
vars:
1616
TASK_ARGS: run --rm phpfpm composer {{.TASK_ARGS}}
1717

18-
coding-standards:coding-standards:check:
19-
desc: Apply and check coding-standards
18+
coding-standards:apply:
19+
desc: "Apply coding standards"
2020
cmds:
21-
- task: composer
22-
vars:
23-
TASK_ARGS: coding-standards-apply
24-
- task: composer
25-
vars:
26-
TASK_ARGS: coding-standards-check
21+
# - task: coding-standards:javascript:apply
22+
- task: coding-standards:markdown:apply
23+
- task: coding-standards:php:apply
24+
# - task: coding-standards:styles:apply
25+
- task: coding-standards:twig:apply
26+
- task: coding-standards:yaml:apply
27+
silent: true
28+
29+
coding-standards:check:
30+
desc: "Apply coding standards"
31+
cmds:
32+
# - task: coding-standards:javascript:check
33+
- task: coding-standards:markdown:check
34+
- task: coding-standards:php:check
35+
# - task: coding-standards:styles:check
36+
- task: coding-standards:twig:check
37+
- task: coding-standards:yaml:check
38+
silent: true
39+
40+
coding-standards:javascript:apply:
41+
desc: "Apply coding standards for javascript"
42+
cmds:
43+
# Cf. .github/workflows/javascript.yaml
44+
- docker compose run --rm prettier 'web/themes/custom/**/js/**/*.js' --write
45+
46+
coding-standards:javascript:check:
47+
desc: "Apply coding standards for javascript"
48+
cmds:
49+
- task: coding-standards:javascript:apply
50+
# Cf. .github/workflows/javascript.yaml
51+
- docker compose run --rm prettier 'web/themes/custom/**/js/**/*.js' --check
52+
53+
coding-standards:markdown:apply:
54+
desc: "Apply coding standards for Markdown"
55+
cmds:
56+
# Cf. .github/workflows/markdown.yaml
57+
- docker compose run --rm markdownlint markdownlint '**/*.md' --fix
58+
59+
coding-standards:markdown:check:
60+
desc: "Apply and check coding standards for Markdown"
61+
cmds:
62+
- task: coding-standards:markdown:apply
63+
# Cf. .github/workflows/markdown.yaml
64+
- docker compose run --rm markdownlint markdownlint '**/*.md'
65+
66+
coding-standards:php:apply:
67+
desc: "Apply coding standards for PHP"
68+
cmds:
69+
# Cf. .github/workflows/php.yaml
70+
- docker compose run --rm phpfpm vendor/bin/phpcbf
71+
silent: true
2772

28-
default:
73+
coding-standards:php:check:
74+
desc: "Apply and check coding standards for PHP"
2975
cmds:
30-
- task --list
76+
- task: coding-standards:php:apply
77+
# Cf. .github/workflows/php.yaml
78+
- docker compose run --rm phpfpm vendor/bin/phpcs
3179
silent: true
3280

81+
coding-standards:styles:apply:
82+
desc: "Apply coding standards for styles"
83+
cmds:
84+
# Cf. .github/workflows/styles.yaml
85+
- docker compose run --rm prettier 'web/themes/custom/**/css/**/*.{css,scss}' --write
86+
87+
coding-standards:styles:check:
88+
desc: "Apply coding standards for styles"
89+
cmds:
90+
- task: coding-standards:styles:apply
91+
# Cf. .github/workflows/styles.yaml
92+
- docker compose run --rm prettier 'web/themes/custom/**/css/**/*.{css,scss}' --check
93+
94+
coding-standards:twig:apply:
95+
desc: "Apply coding standards for Twig"
96+
cmds:
97+
- docker compose run --rm phpfpm vendor/bin/twig-cs-fixer fix
98+
silent: true
99+
100+
coding-standards:twig:check:
101+
desc: "Apply and check coding standards for Twig"
102+
cmds:
103+
- task: coding-standards:twig:apply
104+
- docker compose run --rm phpfpm vendor/bin/twig-cs-fixer lint
105+
silent: true
106+
107+
coding-standards:yaml:apply:
108+
desc: "Apply coding standards for YAML"
109+
cmds:
110+
# Cf. .github/workflows/yaml.yaml
111+
- docker compose run --rm prettier '**/*.{yml,yaml}' --write
112+
113+
coding-standards:yaml:check:
114+
desc: "Apply coding standards for YAML"
115+
cmds:
116+
- task: coding-standards:yaml:apply
117+
# Cf. .github/workflows/yaml.yaml
118+
- docker compose run --rm prettier '**/*.{yml,yaml}' --check
119+
120+
test:
121+
cmds:
122+
- docker compose run --env PHP_XDEBUG_MODE --env PHP_XDEBUG_WITH_REQUEST --env PHP_IDE_CONFIG --rm phpfpm vendor/bin/phpunit {{.CLI_ARGS}}
123+
33124
xdebug:test:
34125
cmds:
35126
- PHP_XDEBUG_MODE=debug PHP_XDEBUG_WITH_REQUEST=yes PHP_IDE_CONFIG=serverName=localhost docker compose run --env PHP_XDEBUG_MODE --env PHP_XDEBUG_WITH_REQUEST --env PHP_IDE_CONFIG --rm phpfpm vendor/bin/phpunit {{.CLI_ARGS}}

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
"drush/drush": "^12 || ^13",
1616
"itk-dev/serviceplatformen": "dev-feature/SF2900-Fordelingskomponenten",
1717
"os2web/os2web_audit": "^1.2",
18-
"os2web/os2web_key": "^1.0"
18+
"os2web/os2web_key": "^1.0",
19+
"drupal/system_stream_wrapper": "^2.1"
1920
},
2021
"require-dev": {
2122
"drupal/coder": "^8.3",
2223
"ergebnis/composer-normalize": "^2.49",
2324
"mglaman/phpstan-drupal": "^2.0",
2425
"phpstan/extension-installer": "^1.4",
25-
"phpunit/phpunit": "^9.6"
26+
"phpunit/phpunit": "^9.6",
27+
"vincentlanglet/twig-cs-fixer": "^3.13"
2628
},
2729
"repositories": [
2830
{

modules/os2forms_fordelingskomponent_examples/config/install/webform.webform.os2_fdk_kp_anmoding.yml

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -282,44 +282,20 @@ handlers:
282282
Anmodning:
283283
Header:
284284
# Static values
285-
Myndighed: 'urn:oio:cvr-nr:00000000'
286-
ModtagetDato: '2006-05-04'
285+
Myndighed: "urn:oio:cvr-nr:00000000"
286+
ModtagetDato: "2006-05-04"
287287
KLE: KLE
288288
AnsoegerOplysninger:
289289
Ansoeger:
290290
# Submission values
291-
Fornavn: '[webform_submission:values:fornavn]'
292-
Efternavn: '[webform_submission:values:efternavn]'
293-
Personnummer: '[webform_submission:values:personnummer]'
291+
Fornavn: "[webform_submission:values:fornavn]"
292+
Efternavn: "[webform_submission:values:efternavn]"
293+
Personnummer: "[webform_submission:values:personnummer]"
294294
Sagstype:
295-
AlmindeligtHelbredstillaeg: '[webform_submission:values:almindeligthelbredstillaeg]'
295+
AlmindeligtHelbredstillaeg: "[webform_submission:values:almindeligthelbredstillaeg]"
296296
Underskriftsoplysninger:
297-
Underskrift: '[webform_submission:values:underskrift]'
298-
Underskriftsdato: '[webform_submission:completed:custom:Y-m-d]'
299-
300-
xml_template: |
301-
<?xml version="1.0" encoding="UTF-8"?>
302-
<Anmodning xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
303-
<Header>
304-
<Myndighed>urn:oio:cvr-nr:00000000</Myndighed>
305-
<ModtagetDato>[webform_submission:completed:custom:Y-m-d]</ModtagetDato>
306-
<KLE>KLE0</KLE>
307-
</Header>
308-
<AnsoegerOplysninger>
309-
<Ansoeger>
310-
<Fornavn>Fornavn0</Fornavn>
311-
<Efternavn>Efternavn0</Efternavn>
312-
<Personnummer>urn:oio:cpr:0000000000</Personnummer>
313-
</Ansoeger>
314-
</AnsoegerOplysninger>
315-
<Sagstype>
316-
<AlmindeligtHelbredstillaeg>Medicin</AlmindeligtHelbredstillaeg>
317-
</Sagstype>
318-
<Underskriftsoplysninger>
319-
<Underskrift>Underskrift0</Underskrift>
320-
<Underskriftsdato>2006-05-04</Underskriftsdato>
321-
</Underskriftsoplysninger>
322-
</Anmodning>
297+
Underskrift: "[webform_submission:values:underskrift]"
298+
Underskriftsdato: "[webform_submission:completed:custom:Y-m-d]"
323299

324300
xml_template: |
325301
<?xml version="1.0" encoding="UTF-8"?>

0 commit comments

Comments
 (0)