Skip to content

Commit b826836

Browse files
authored
Merge pull request #16 from moreonion/webform4
Cut webform 3 support & support optional elements
2 parents 754ab8d + 3f29768 commit b826836

File tree

4 files changed

+61
-46
lines changed

4 files changed

+61
-46
lines changed

.github/workflows/test.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
on:
2+
push:
3+
branches: [ 7.x-1.x, 7.x-2.x ]
4+
pull_request:
5+
branches: [ 7.x-1.x, 7.x-2.x ]
6+
7+
jobs:
8+
phpunit:
9+
runs-on: ubuntu-18.04
10+
env:
11+
DB_DATABASE: drupal
12+
DB_USER: root
13+
DB_PASSWORD: root
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: "Setup PHP 7.3"
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: "7.3"
20+
- name: Start MySQL
21+
run: |
22+
sudo systemctl start mysql
23+
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
24+
- name: Set env
25+
run: |
26+
echo "REPO=`pwd`" >> $GITHUB_ENV
27+
echo "COMPOSER_HOME=${HOME}/.config/composer" >> $GITHUB_ENV
28+
echo "ROOT=${HOME}/drupal-root" >> $GITHUB_ENV
29+
- name: Get Composer Cache Directory
30+
id: composer-cache
31+
run: |
32+
echo "::set-output name=dir::$(composer config cache-files-dir)"
33+
- uses: actions/cache@v2
34+
with:
35+
path: ${{ steps.composer-cache.outputs.dir }}
36+
key: ${{ runner.os }}-composer-
37+
restore-keys: |
38+
${{ runner.os }}-composer-
39+
- name: Install composer packages
40+
run: |
41+
mkdir -p $COMPOSER_HOME
42+
cd $COMPOSER_HOME
43+
composer require drush/drush:8.1.* phpunit/phpunit:^8 torotil/upal:2.0.0-RC1 stripe/stripe-php:7.27.2
44+
- name: Bootstrap drupal
45+
run: |
46+
php -d sendmail_path=`which true` $COMPOSER_HOME/vendor/bin/drush.php --yes core-quick-drupal --core=drupal-7.69 --profile=testing --no-server --db-url=mysql://${{ env.DB_USER }}:${{ env.DB_PASSWORD }}@127.0.0.1:3306/${{ env.DB_DATABASE }} --root=$ROOT
47+
ln -s $REPO $ROOT/sites/all/modules/module_under_test
48+
cd $ROOT
49+
curl https://www.drupal.org/files/issues/1891356-drupal_static_reset-on-module-changes-30-D7.patch | patch -p1
50+
drush dl ctools form_builder-7.x-2.0-alpha2 jquery_update little_helpers psr0 select2 variable webform
51+
drush --yes pm-enable autocomplete_api form_builder_webform
52+
- name: Run phpunit tests
53+
run: UPAL_ROOT=$ROOT UPAL_WEB_URL=http://127.0.0.1 XDEBUG_MODE=coverage phpunit --bootstrap=$COMPOSER_HOME/vendor/torotil/upal/bootstrap.php --coverage-clover=coverage.xml .
54+
- uses: codecov/codecov-action@v1

.travis.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

autocomplete_api.component.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function _webform_defaults_autocomplete() {
1919
'pid' => 0,
2020
'weight' => 0,
2121
'value' => '',
22-
'mandatory' => 1,
22+
'required' => 1,
2323
'extra' => array(
2424
'width' => '',
2525
'unique' => 0,
@@ -75,7 +75,7 @@ function _webform_render_autocomplete($component, $value = NULL, $filter = TRUE)
7575
ArrayConfig::mergeDefaults($component, _webform_defaults_autocomplete());
7676
$element = [
7777
'#type' => 'autocomplete_api_select',
78-
'#required' => !empty($component['mandatory']) || !empty($component['required']),
78+
'#required' => !empty($component['required']),
7979
'#weight' => $component['weight'],
8080
'#theme_wrappers' => ['webform_element'],
8181
'#pre_render' => [],

autocomplete_api.module

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ function autocomplete_api_element_process($element, &$form_state) {
9999
* Callback for _form_validate().
100100
*/
101101
function _autocomplete_api_element_validate($element, &$form_state, $form) {
102+
// Allow empty values if the element is not required.
103+
if (empty($element['#required']) && empty($element['#value'])) {
104+
return;
105+
}
106+
// Make sure a valid value was submitted.
102107
$client = Client::fromConfig($element['#dataset_key']);
103108
$value = drupal_json_decode($element['#value']);
104109
if (!$client->verifySignature($value)) {

0 commit comments

Comments
 (0)