Skip to content

Commit

Permalink
Merge pull request #11 from OS2Forms/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
juuliabellcom authored Dec 4, 2020
2 parents 8a2d43d + df99d02 commit 0c618ce
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 16 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ before_install:
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

install:
- composer global require hirak/prestissimo
- 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
Expand Down
64 changes: 64 additions & 0 deletions modules/os2forms_nemid/src/Element/NemidKommunekode.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_kommunekode'.
*
* @FormElement("os2forms_nemid_kommunekode")
*
* @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\NemidKommunekode
*/
class NemidKommunekode extends NemidElementBase {

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

/**
* Processes a 'os2forms_nemid_kommunekode' element.
*/
public static function processNemidKommunekode(&$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_kommunekode'.
*/
public static function validateNemidKommunekode(&$element, FormStateInterface $form_state, &$complete_form) {
// Here you can add custom validation logic.
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Drupal\os2forms_nemid\Plugin\WebformElement;

/**
* Provides a 'os2forms_nemid_kommunekode' element.
*
* @WebformElement(
* id = "os2forms_nemid_kommunekode",
* label = @Translation("NemID Kommunekode"),
* description = @Translation("Provides a NemID Kommunekode element."),
* category = @Translation("NemID"),
* )
*
* @see \Drupal\os2forms_nemid\Plugin\NemidElementBase
* @see \Drupal\os2forms_nemid\Element\NemidKommunekode
*/
class NemidKommunekode extends ServiceplatformenCprElementBase implements NemidElementPersonalInterface {

/**
* {@inheritdoc}
*/
public function getPrepopulateFieldFieldKey() {
return 'kommunekode';
}

}
40 changes: 25 additions & 15 deletions modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$nemid_cpr = self::getFirstValueByType('os2forms_nemid_cpr', $webform_submission);
$nemid_com_cvr = self::getFirstValueByType('os2forms_nemid_company_cvr', $webform_submission);
$os2web_datalookup_plugins = \Drupal::service('plugin.manager.os2web_datalookup');
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cvr */
$sp_cvr = $os2web_datalookup_plugins->createInstance('serviceplatformen_cvr');
if (!empty($nemid_com_cvr) && $sp_cvr->isReady()) {
$company_info = $sp_cvr->getInfo($nemid_com_cvr);
if ($company_info['status']) {
$nemid_name = htmlspecialchars($company_info['company_name']);
$nemid_address = htmlspecialchars($company_info['company_street'] . ' ' . $company_info['company_house_nr'] . ' ' . $company_info['company_']);
$nemid_city = htmlspecialchars($company_info['company_city']);
$nemid_zipcode = htmlspecialchars($company_info['company_zipcode']);
}
}
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cpr */
$sp_cpr = $os2web_datalookup_plugins->createInstance('serviceplatformen_cpr');
if (!empty($nemid_cpr) && $sp_cpr->isReady()) {
Expand All @@ -51,6 +40,17 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$nemid_zipcode = htmlspecialchars($person_address['zipcode']);
}
}
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cvr */
$sp_cvr = $os2web_datalookup_plugins->createInstance('serviceplatformen_cvr');
if (!empty($nemid_com_cvr) && $sp_cvr->isReady()) {
$company_info = $sp_cvr->getInfo($nemid_com_cvr);
if ($company_info['status']) {
$nemid_name = htmlspecialchars($company_info['company_name']);
$nemid_address = htmlspecialchars($company_info['company_street'] . ' ' . $company_info['company_house_nr'] . ' ' . $company_info['company_']);
$nemid_city = htmlspecialchars($company_info['company_city']);
$nemid_zipcode = htmlspecialchars($company_info['company_zipcode']);
}
}

$config = self::getElementConfiguration($element);
$os2formsId = self::getConfigurationValue('os2formsId', $config, $webform_submission);
Expand Down Expand Up @@ -83,6 +83,7 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$webform = $webform_submission->getWebform();
$webform_title = htmlspecialchars($webform->label());
$fields = self::getWebformElementsAsList($webform_submission);

if (isset($fields['antal_rum_max'])) {
$maxRoom = htmlspecialchars($fields['antal_rum_max']);
}
Expand All @@ -101,14 +102,14 @@ public static function getFileContent(array $element, WebformSubmissionInterface
$xml_data = [
'OS2FormsId' => $os2formsId,
'SBSYSJournalisering' => [
'PrimaerPartCprNummer' => (!empty($nemid_cpr)) ? $nemid_cpr : '',
'PrimaerPartCprNummer' => (!empty($nemid_cpr) && empty($nemid_com_cvr)) ? $nemid_cpr : '',
'PrimaerPartCvrNummer' => (!empty($nemid_com_cvr)) ? $nemid_com_cvr : '',
'KLe' => $kle,
'SagSkabelonId' => $sagSkabelonId,
],
'DigitalForsendelse' => [
'Slutbruger' => [
'CprNummer' => (isset($nemid_cpr)) ? $nemid_cpr : '',
'CprNummer' => (!empty($nemid_cpr) && empty($nemid_com_cvr)) ? $nemid_cpr : '',
'CvrNummer' => (isset($nemid_com_cvr)) ? $nemid_com_cvr : '',
'Navn' => (isset($nemid_name)) ? $nemid_name : '',
'Adresse' => (isset($nemid_address)) ? $nemid_address : '',
Expand Down Expand Up @@ -199,19 +200,28 @@ protected static function getFirstValueByType($type, WebformSubmissionInterface
* Webform elements as simple array.
*/
protected static function getWebformElementsAsList(WebformSubmissionInterface $webform_submission) {
$nemid_cpr = self::getFirstValueByType('os2forms_nemid_cpr', $webform_submission);
$nemid_com_cvr = self::getFirstValueByType('os2forms_nemid_company_cvr', $webform_submission);
$webform = $webform_submission->getWebform();
$data = $webform_submission->getData();
$webform_elements = $webform->getElementsInitializedFlattenedAndHasValue();
$elements_list = [];

foreach ($webform_elements as $key => $webform_element) {
$field_name = $key;
$field_name = preg_replace('/\W/', '_', $field_name);
$webform_element['#type'];
if ($webform_element['#type'] == 'markup') {
$elements_list[$field_name] = $webform_element['value'];
}
elseif ($data && isset($data[$key])) {
$elements_list[$field_name] = $data[$key];
if ($webform_element['#type'] == 'os2forms_nemid_cpr') {
if (!empty($nemid_cpr) && empty($nemid_com_cvr)) {
$elements_list[$field_name] = $data[$key];
}
}
else {
$elements_list[$field_name] = $data[$key];
}
}
}
return $elements_list;
Expand Down

0 comments on commit 0c618ce

Please sign in to comment.