Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
55b23f2
Added Travis-ci config
andriyun Nov 19, 2019
51da5bb
Added Twigcs check
andriyun Nov 19, 2019
279f4d9
Added README.md file
andriyun Nov 19, 2019
d88a29f
Added eslint check
andriyun Nov 19, 2019
64a7e27
Added stylelint check
andriyun Nov 19, 2019
262be11
Small text changes
franzskaaning Nov 19, 2019
ec5131d
Update README.md
franzskaaning Nov 19, 2019
3d13e52
Removed normal Drupal install, so its only OS2web way that is mentioned
franzskaaning Nov 19, 2019
13ed74b
Fixed typo
andriyun Nov 19, 2019
59a303e
Merge branch '8.x' of github.com:OS2Forms/os2forms into 8.x
andriyun Nov 19, 2019
6efdfdf
Fixed travis build
andriyun Nov 19, 2019
1fefa5b
Cleanup
andriyun Nov 20, 2019
d0dfb25
Optimized fetching drupal core
andriyun Nov 20, 2019
f8ed366
composer.json variables from travis-ce config file
andriyun Nov 20, 2019
41d16fa
Extended README
andriyun Nov 21, 2019
1393727
Added better markup for readme
andriyun Nov 21, 2019
c08e681
Enabled missed modules
andriyun Nov 21, 2019
12926f2
OS2FORMS-296 Added support for export webform submissions to PDF and …
andriyun Nov 22, 2019
475212e
OS2FORMS-294 Added entity print configuration check to status report …
andriyun Nov 25, 2019
69c54cb
Updated README. Change license to EUPL-1.2.
andriyun Nov 28, 2019
1a77f75
Remove URL to issue tracker from README to make snippet able to copy-…
andriyun Nov 28, 2019
2ce8a0b
Added Drupal 9 compatibility
andriyun Nov 29, 2019
5b15137
Adding os2forms_nemid module
stankut Nov 29, 2019
68dfe40
Changing os2forms drupal module package
stankut Nov 29, 2019
9b0b6d7
Adding dependency, fixing notices
stankut Nov 29, 2019
adb9914
Adding os2web_nemlogin as a composer dependency
stankut Nov 29, 2019
d4dd06d
Renaming CPR element
stankut Dec 2, 2019
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
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
language: php

sudo: false

php:
- 7.2

install:
- composer global require drush/drush:8.x-dev drupal/coder mglaman/drupal-check friendsoftwig/twigcs
- export PATH="$HOME/.config/composer/vendor/bin:$PATH"
- phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer
- phpenv rehash
- nvm install node
- nvm use node
- npm install --global yarn
- cd ../ && drush dl drupal-8 --drupal-project-rename=drupal
- cd drupal
- DRUPAL_ROOT=$(pwd)
- export REPOSITORIES='"repositories":\ \['
- export REPOSITORIES_REPLACE='"repositories":\[\{"type":"path","url":"..\/os2forms","options":\{"symlink":false\}\},'
- export REQUIRE='"require":\ {'
- export REQUIRE_REPLACE='"require":{"os2forms\/os2forms":"\*",'
- sed -i "s/$REPOSITORIES/$REPOSITORIES_REPLACE/g" composer.json
- sed -i "s/$REQUIRE/$REQUIRE_REPLACE/g" composer.json
- composer update
- PROJECT_PATH=$DRUPAL_ROOT/modules/contrib/os2forms
- cd $DRUPAL_ROOT/core
- yarn install
- npm install --global eslint-config-drupal-bundle stylelint

script:
- phpcs --standard=Drupal --ignore=*.md $PROJECT_PATH
- twigcs $PROJECT_PATH
- cd $DRUPAL_ROOT/core
- eslint $DRUPAL_ROOT/modules/contrib/os2forms
- stylelint --aei $DRUPAL_ROOT/modules/contrib/os2forms/**/*.css
- drupal-check $DRUPAL_ROOT/modules/contrib/os2forms
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# OS2Forms Drupal module [![Build Status](https://travis-ci.org/OS2Forms/os2forms.svg?branch=8.x)](https://travis-ci.org/OS2Forms/os2forms)

## Install

OS2Forms Drupal 8 module is available to download via composer.
```
composer require os2forms/os2forms
drush en os2forms
```

If you don't have Drupal installed on you server, you will to need install it first.
Read more about [how to install drupal core](https://www.drupal.org/docs/8/install).

We are recommending to install drupal via composer by using
[drupal-composer project](https://github.com/drupal-composer/drupal-project).

To get more benefits on your Drupal project we are offering you to use
[OS2web](https://packagist.org/packages/os2web/os2web) as installation
profile for Drupal.

You can easy download and install OS2web installation profile to your
composer based Drupal project with commands:
```
composer require os2web/os2web
drush si os2web --db-url=mysql://db_user:db_pass@mysql_host/db_name --account-pass=admin -y
```

## Update
Updating process for OS2forms module is similar to usual Drupal 8 module.
Use Composer's built-in command for listing packages that have updates available:

```
composer outdated os2forms/os2forms
```
## Automated testing and code quality
See [OS2Forms testing and CI information](https://github.com/OS2Forms/docs#testing-and-ci)

## Contribution

OS2Forms project is opened for new features and os course bugfixes.
If you have any suggestion or you found a bug in project, you are very welcome
to create an issue in github repository issue tracker.
For issue description there is expected that you will provide clear and
sufficient information about your feature request or bug report.

### Code review policy
See [OS2Forms code review policy](https://github.com/OS2Forms/docs#code-review)

### Git name convention
See [OS2Forms git name convention](https://github.com/OS2Forms/docs#git-guideline)

## Unstable features
### Export submissions to Word
This feature is still not part of Webform and Entity print modules stable versions
due to following issues:
* [[Webform] Unlock possibility of using Entity print module export to Word feature](https://www.drupal.org/project/webform/issues/3096552)
* [[Entity Print] Add Export to Word Support](https://www.drupal.org/project/entity_print/issues/2733781)

To get this functionality on drupal project there will be applied patches from issues above via Composer.

NOTE: If you are downloading os2forms module without using composer, be aware that you have apply those patches by yourself.
23 changes: 21 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Drupal 8 OS2Form module provides advanced webform functionality for Danish Municipalities",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "GPL-2.0-or-later",
"license": "EUPL-1.2",
"repositories": {
"drupal": {
"type": "composer",
Expand All @@ -28,6 +28,25 @@
"drupal/entity_print": "^2.1",
"drupal/webform_migrate": "^1.1",
"drupal/maillog": "1.x-dev",
"drupal/devel": "^2.1"
"drupal/devel": "^2.1",
"phpoffice/phpword": "^0.17.0",
"tecnickcom/tcpdf": "~6",
"vaimo/composer-patches": "^4.20",
"os2web/os2web_nemlogin": "8.x-dev"
},
"extra" : {
"composer-exit-on-patch-failure": true,
"patchLevel": {
"test": "-p2"
},
"enable-patching" : true,
"patches": {
"drupal/entity_print": {
"2733781 - Add Export to Word Support": "https://www.drupal.org/files/issues/2019-11-22/2733781-47.patch"
},
"drupal/webform" : {
"3096552 - Unlock possibility of using Entity print module export to Word feature": "https://www.drupal.org/files/issues/2019-11-25/3096552-unlock-export-to-word-1.patch"
}
}
}
}
19 changes: 19 additions & 0 deletions modules/os2forms_nemid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# OS2Forms Nemid Drupal module

# Module purpose

The aim of this module is to provide custom NemId field and integration with OS2Web Nemlogin module.

# How does it work

Module exposes dozen of new NemID components that are available in the webform build process.

Build page: admin/structure/webform/manage/[webform]

Besides this module adds a special settings to the Third Party Webform settings:

- Webform type
- Redirect to nemlogin automatically

Settings: admin/structure/webform/manage/[webform]/settings

10 changes: 10 additions & 0 deletions modules/os2forms_nemid/os2forms_nemid.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'OS2forms NemID'
type: module
description: 'Provides custom NemID fields and integration with NemID'
package: OS2Forms
core: 8.x
core_version_requirement: ^8 || ^9

dependencies:
- os2forms
- os2web_nemlogin
97 changes: 97 additions & 0 deletions modules/os2forms_nemid/os2forms_nemid.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* @file
* OS2Forms NemID functionality module.
*/

use Drupal\Core\Form\FormStateInterface;

/**
* Defines NemID webform type - Personal.
*/
define('OS2FORMS_NEMID_WEBFORM_TYPE_PERSONAL', 'personal');

/**
* Defines NemID webform type - Company.
*/
define('OS2FORMS_NEMID_WEBFORM_TYPE_COMPANY', 'company');

/**
* Implements hook_webform_third_party_settings_form_alter().
*/
function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $form_state->getFormObject()->getEntity();
$settings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid');

// OS2Forms NemID.
$form['third_party_settings']['os2forms']['os2forms_nemid'] = [
'#type' => 'details',
'#title' => t('OS2Forms NemID settings'),
'#open' => TRUE,
];

// Webform type.
$webform_types = [
OS2FORMS_NEMID_WEBFORM_TYPE_PERSONAL => t('Personal'),
OS2FORMS_NEMID_WEBFORM_TYPE_COMPANY => t('Company'),
];
$form['third_party_settings']['os2forms']['os2forms_nemid']['webform_type'] = [
'#type' => 'select',
'#title' => t('Webform type'),
'#default_value' => !(empty($settings)) ? $settings['webform_type'] : NULL,
'#empty_option' => t('Not specified'),
'#options' => $webform_types,
'#description' => t('Based on the selected type form irrelevant fields will not be shown to the end user'),
];

// Nemlogin auto redirect.
$form['third_party_settings']['os2forms']['os2forms_nemid']['nemlogin_auto_redirect'] = [
'#type' => 'checkbox',
'#title' => t('Redirect to nemlogin automatically'),
'#default_value' => !(empty($settings)) ? $settings['nemlogin_auto_redirect'] : FALSE,
'#description' => t('Redirection will happen right after user has is accessing the form, if user is already authenticated via NemID, redirection will not happen.'),
];
}

/**
* Implements hook_webform_submission_form_alter().
*/
function os2forms_nemid_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// Getting webform Nemid settings.
/** @var \Drupal\webform\WebformSubmissionInterface Interface $webformSubmission */
$webformSubmission = $form_state->getFormObject()->getEntity();
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $webformSubmission->getWebform();
$webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid');

// Getting webform_type setting.
$webform_type = NULL;
if (isset($webformNemidSettings['webform_type']) && !empty($webformNemidSettings['webform_type'])) {
$webform_type = $webformNemidSettings['webform_type'];
}

// Webform type is set and not empty.
if ($webform_type) {
// Initializing AuthProviderInterface plugin.
/** @var \Drupal\os2web_nemlogin\Service\AuthProviderService $authProviderService */
$authProviderService = \Drupal::service('os2web_nemlogin.auth_provider');
/** @var \Drupal\os2web_nemlogin\Plugin\AuthProviderInterface $authProviderPlugin */
$authProviderPlugin = $authProviderService->getActivePlugin();

// User is authenticated, check if the form type is corresponding to
// authentication type.
if ($authProviderPlugin->isAuthenticated()) {
if ($authProviderPlugin->isAuthenticatedPerson() && $webform_type !== OS2FORMS_NEMID_WEBFORM_TYPE_PERSONAL
|| $authProviderPlugin->isAuthenticatedCompany() && $webform_type !== OS2FORMS_NEMID_WEBFORM_TYPE_COMPANY) {
\Drupal::messenger()
->addWarning(t('Your login type does match the login type required by the webform. Please <a href="@logout">log out</a> and sign in with a different account', [
'@logout' => $authProviderService->getLogoutUrl()
->toString(),
]));
}
}
}

}
6 changes: 6 additions & 0 deletions modules/os2forms_nemid/os2forms_nemid.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
os2forms_nemid_nemlogin_redirect_subscriber:
class: Drupal\os2forms_nemid\EventSubscriber\NemloginRedirectSubscriber
arguments: ['@os2web_nemlogin.auth_provider', '@current_user']
tags:
- {name: event_subscriber}
64 changes: 64 additions & 0 deletions modules/os2forms_nemid/src/Element/NemidAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Drupal\os2forms_nemid\Element;

use Drupal\Core\Form\FormStateInterface;

/**
* Provides a 'os2forms_nemid_address'.
*
* @FormElement("os2forms_nemid_address")
*
* @see \Drupal\Core\Render\Element\FormElement
* @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21FormElement.php/class/FormElement
* @see \Drupal\Core\Render\Element\RenderElement
* @see https://api.drupal.org/api/drupal/namespace/Drupal%21Core%21Render%21Element
* @see \Drupal\os2forms_nemid\Element\NemidAddress
*/
class NemidAddress extends NemidElementBase {

/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return parent::getInfo() + [
'#process' => [
[$class, 'processNemidAddress'],
[$class, 'processAjaxForm'],
],
'#element_validate' => [
[$class, 'validateNemidAddress'],
],
'#pre_render' => [
[$class, 'preRenderNemidAddress'],
],
'#theme' => 'input__os2forms_nemid_address',
];
}

/**
* Processes a 'os2forms_nemid_address' element.
*/
public static function processNemidAddress(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add and manipulate your element's properties and callbacks.
return $element;
}

/**
* Webform element validation handler for #type 'os2forms_nemid_address'.
*/
public static function validateNemidAddress(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
}

/**
* {@inheritdoc}
*/
public static function preRenderNemidAddress(array $element) {
$element = parent::prerenderNemidElementBase($element);
static::setAttributes($element, ['form-text', 'os2forms-nemid-address']);
return $element;
}

}
Loading