Skip to content

Commit

Permalink
Merge pull request #142 from OS2Forms/develop
Browse files Browse the repository at this point in the history
Release 3.16.2
  • Loading branch information
jekuaitk authored Oct 31, 2024
2 parents bd2cdf0 + c2fe8c3 commit 21604bd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 286 deletions.
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

- [OS-119] Keeping value of CPR clean, not adding address protection text
## [3.16.2] 2024-10-31

- Applied coding standards
- [#192](https://github.com/OS2Forms/os2forms/pull/129)
Added audit logging module from os2web
- Remove dependency on webform migration module
- [#100](https://github.com/OS2Forms/os2forms/pull/100)
Removed unused `tecnickcom/tcpdf` package.

## [3.16.1] 2024-09-20

- [#133](https://github.com/OS2Forms/os2forms/pull/133)
[OS-119] Keeping value of CPR clean, not adding address protection text

## [3.16.0-beta1] 2024-08-27

Expand Down Expand Up @@ -281,7 +292,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa
- Security in case of vulnerabilities.
```

[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.16.0-beta1...HEAD
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.16.2...HEAD
[3.16.2]: https://github.com/OS2Forms/os2forms/compare/3.16.1...3.16.2
[3.16.1]: https://github.com/OS2Forms/os2forms/compare/3.16.0-beta1...3.16.1
[3.16.0-beta1]: https://github.com/OS2Forms/os2forms/compare/3.15.8...3.16.0-beta1
[3.15.8]: https://github.com/OS2Forms/os2forms/compare/3.15.7...3.15.8
[3.15.7]: https://github.com/OS2Forms/os2forms/compare/3.15.6...3.15.7
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"drupal/webform": "^6.1",
"drupal/webform_composite": "^1.0@RC",
"drupal/webform_encrypt": "^2.0@alpha",
"drupal/webform_migrate": "^2.0@alpha",
"drupal/webform_node_element": "^1.2",
"drupal/webform_remote_handlers": "^3.0",
"drupal/webform_remote_select": "^1.0.6",
Expand All @@ -69,12 +68,12 @@
"http-interop/http-factory-guzzle": "^1.0.0",
"itk-dev/beskedfordeler-drupal": "^1.0",
"itk-dev/serviceplatformen": "^1.5",
"os2web/os2web_audit": "^0.1",
"os2web/os2web_datalookup": "^1.5",
"os2web/os2web_nemlogin": "^1.0",
"php-http/guzzle7-adapter": "^1.0",
"phpoffice/phpword": "^0.18.2",
"symfony/options-resolver": "^5.4 || ^6.0",
"tecnickcom/tcpdf": "~6",
"webmozart/path-util": "^2.3",
"wsdltophp/packagebase": "^5.0",
"zaporylie/composer-drupal-optimizations": "^1.2",
Expand Down
1 change: 1 addition & 0 deletions modules/os2forms_forloeb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ before starting to add changes.

## [Unreleased]

- Remove dependency on webform_migrate module
- Implemented `hook_maestro_zero_user_notification` and added *Maestro
notification* handler for sending notifications via email or digital post.
- Cleaned up prefilling of forms in `MaestroWebformInheritTask`.
Expand Down
1 change: 0 additions & 1 deletion modules/os2forms_forloeb/os2forms_forloeb.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ dependencies:
- 'drupal:webform_composite'
- 'drupal:webform_entity_print'
- 'drupal:webform_entity_print_attachment'
- 'drupal:webform_migrate'
- 'drupal:webform_node_element'
- 'drupal:webform_remote_handlers'
- 'drupal:webform_rest'
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion os2forms.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies:
- 'drupal:webform_composite'
- 'drupal:webform_entity_print'
- 'drupal:webform_entity_print_attachment'
- 'drupal:webform_migrate'
- 'drupal:webform_scheduled_email'
- 'drupal:webform_submission_export_import'
- 'drupal:webform_submission_log'
Expand Down
266 changes: 0 additions & 266 deletions os2forms.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
*/

use Drupal\Core\Form\FormStateInterface;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;

/**
* Implements hook_entity_type_build().
Expand Down Expand Up @@ -65,269 +62,6 @@ function os2forms_theme() {
];
}

/**
* Implements hook_webform_migrate_d7_webform_element_ELEMENT_TYPE_alter().
*
* Adjusts migration from Drupal 7.
*
* @See https://www.drupal.org/project/webform_migrate/issues/3155073
*/
function os2forms_webform_migrate_d7_webform_element_date_popup_alter(&$markup, $indent, array $element) {
$markup .= "$indent '#type': date\n";
$markup .= "$indent '#datepicker': true\n";
$markup .= "$indent '#date_date_format': d/m/Y\n";

$extra = unserialize($element['extra'], ['allowed_classes' => FALSE]);
$options = [
'disabled',
'readonly',
'placehoder',
'description',
];
foreach ($options as $option) {
if (!empty($extra[$option])) {
$value = 'true';
switch ($option) {
case 'description':
case 'placeholder':
$value = "\"" . str_replace(['"', "\n", "\r"], ["'", '\n', ''], $extra[$option]) . "\"";
break;
}
$markup .= "$indent #$option: $value\n";
}
}
}

/**
* Implements hook_webform_migrate_d7_webform_element_ELEMENT_TYPE_alter().
*
* Adjusts migration from Drupal 7.
*
* @See https://www.drupal.org/project/webform_migrate/issues/3155073
*/
function os2forms_webform_migrate_d7_webform_element_bt_layout_row_alter(&$markup, $indent, array $element) {
$markup .= "$indent '#type': webform_flexbox\n";

$extra = unserialize($element['extra'], ['allowed_classes' => FALSE]);
if (!empty($extra['description'])) {
$value = "\"" . str_replace(['"', "\n", "\r"], ["'", '\n', ''], $extra['description']) . "\"";
$markup .= "$indent #description: $value\n";
}
}

/**
* Implements hook_webform_migrate_d7_webform_element_ELEMENT_TYPE_alter().
*
* Adjusts migration from Drupal 7.
*
* @See https://www.drupal.org/project/webform_migrate/issues/3155073
*/
function os2forms_webform_migrate_d7_webform_element_bt_layout_cols_alter(&$markup, $indent, array $element) {
$markup .= "$indent '#type': container\n";
$extra = unserialize($element['extra'], ['allowed_classes' => FALSE]);
if (!empty($extra['description'])) {
$value = "\"" . str_replace(['"', "\n", "\r"], ["'", '\n', ''], $extra['description']) . "\"";
$markup .= "$indent #description: $value\n";
}
}

/**
* Implements hook_migrate_prepare_row().
*/
function os2forms_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
_os2forms_migrate_prepare_row_pdf($row, $source, $migration);
_os2forms_migrate_prepare_row_doc($row, $source, $migration);
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$migrate_to_category = \Drupal::service('webform.third_party_settings_manager')->getThirdPartySetting('os2forms', 'migrate_to_category');
if (!empty($migrate_to_category)) {
$row->setDestinationProperty('category', $migrate_to_category);
}
}

/**
* Implements support of PDF attachment migration.
*/
function _os2forms_migrate_prepare_row_pdf(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
// Adding migration path for Webform PDF Entity print attachment.
$nid = $row->getSourceProperty('nid');
$default = $source->getDatabase()->select('webform2pdf', 'w2p')
->fields('w2p')
->condition('nid', $nid, '=')
->execute()
->fetchAssoc();

if (!empty($default['data'])) {
$data = unserialize($default['data'], ['allowed_classes' => FALSE]);
unset($default['data']);
$default = array_merge($default, $data);
}

if (empty($default['enabled'])) {
return;
}

$of_default = $source->getDatabase()->select('os2forms_frontend_webform_settings', 'of')
->fields('of')
->condition('nid', $nid, '=')
->condition('submodule', 'os2forms_webform2pdf', '=')
->execute()
->fetchAssoc();

if (!empty($of_default['data'])) {
$data = unserialize($of_default['data'], ['allowed_classes' => FALSE]);
unset($of_default['data']);
$default = array_merge($of_default, $data);
}

$markup = "webform_attachment_pdf:\n";
$markup .= " '#title': 'PDF Attachment'\n";
$markup .= " '#type': webform_entity_print_attachment:pdf\n";
$filename = 'webform_submission-[webform:id]-[webform_submission:sid].pdf';
if ($default['custom_pdf_name']) {
$filename = str_replace(
['@nid', '@sid'],
['[webform:id]', '[webform_submission:sid]'],
$data['custom_pdf_name']
);
}
$markup .= " '#filename': '$filename'\n";
$template = _os2forms_migrate_prepare_webform2pdf_get_template($nid, $source);
if ($template) {
$template_arr = explode("\n", $template);
$markup .= " '#view_mode': twig\n";
$markup .= " '#template': |\n " . implode("\n ", $template_arr) . "\n";
}

// Saving new form element.
$elements = $row->getSourceProperty('elements');
$elements .= $markup;
$row->setSourceProperty('elements', $elements);
$dependencies = $row->getDestinationProperty('dependencies');
if (empty($dependencies) || !array_search('os2forms', $dependencies)) {
$dependencies['module'][] = 'os2forms';
$row->setDestinationProperty('dependencies', $dependencies);
}
}

/**
* Implements support of DOC attachment migration.
*/
function _os2forms_migrate_prepare_row_doc(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
// Adding migration path for Webform DOC Entity print attachment.
$nid = $row->getSourceProperty('nid');
$default = $source->getDatabase()->select('os2forms_frontend_webform_settings', 'of')
->fields('of')
->condition('nid', $nid, '=')
->condition('submodule', 'os2forms_doc', '=')
->execute()
->fetchAssoc();

if (!empty($default['data'])) {
$data = unserialize($default['data'], ['allowed_classes' => FALSE]);
unset($default['data']);
$default = array_merge($default, $data);
}

if (empty($default['enabled'])) {
return;
}

$markup = "webform_attachment_docx:\n";
$markup .= " '#title': 'PDF Attachment'\n";
$markup .= " '#type': webform_entity_print_attachment:word_docx\n";
$markup .= " '#filename': 'webform_submission-[webform:id]-[webform_submission:sid].docx'\n";
$template = _os2forms_migrate_prepare_webform2pdf_get_template($nid, $source);
if ($template) {
$template_arr = explode("\n", $template);
$markup .= " '#view_mode': twig\n";
$markup .= " '#template': |\n " . implode("\n ", $template_arr) . "\n";
}

// Saving new form element.
$elements = $row->getSourceProperty('elements');
$elements .= $markup;
$row->setSourceProperty('elements', $elements);

$dependencies = $row->getDestinationProperty('dependencies');
if (empty($dependencies) || !array_search('os2forms', $dependencies)) {
$dependencies['module'][] = 'os2forms';
$row->setDestinationProperty('dependencies', $dependencies);
}
}

/**
* Preprocesses PDF template for webform.
*/
function _os2forms_migrate_prepare_webform2pdf_get_template($nid, $source) {
$template = &drupal_static(__FUNCTION__ . '_' . $nid, FALSE);
if ($template) {
return $template;
}
$settings = $source->getDatabase()->select('webform2pdf', 'w2p')
->fields('w2p')
->condition('nid', $nid, '=')
->execute()
->fetchAssoc();

if (!empty($settings['data'])) {
$data = unserialize($settings['data'], ['allowed_classes' => FALSE]);
unset($settings['data']);
$settings = array_merge($settings, $data);
}

if (empty($settings['p_body']['value'])) {
return FALSE;
}
$template = $settings['p_body']['value'];

// Due to changed form_keys we should replace old form_key to new one.
// Collecting mapping array for form_keys.
$query = $source->getDatabase()->select('webform_component', 'wc');
$query->fields('wc', [
'pid',
'form_key',
]);
$components = $query->condition('nid', $nid)->execute();
$keys = [];
foreach ($components as $component) {
$keys[$component->form_key] = $component->form_key . ($component->pid ? '_' . $component->pid : '');
}

// Replacing D7 webform tokens to D8.
$template = str_replace('[submission:', '[webform_submission:', $template);
foreach ($keys as $old_key => $new_key) {
$template = str_replace(':' . $old_key . ']', ':' . $new_key . ']', $template);
$template = str_replace(':' . $old_key . ':', ':' . $new_key . ':', $template);
}

// Check valid tokens.
preg_match_all('/\[(.*)\]/', $template, $matches);
$tokens = array_unique($matches[0]);
$valid_tokens = array_filter($tokens, function ($token) {
return empty(\Drupal::token()->getInvalidTokensByContext($token, [
0 => 'webform',
1 => 'webform_submission',
2 => 'webform_handler',
3 => 'site',
4 => 'date',
]));
});

// Making tokens available for twig template.
foreach ($valid_tokens as $token) {
$template = str_replace($token, "{{ webform_token('" . $token . "', webform_submission, [], options) }}", $template);
$unset_key = array_search($token, $tokens);
unset($tokens[$unset_key]);
}

// Removing invalid tokens.
foreach ($tokens as $invalid_token) {
$template = str_replace($invalid_token, '', $template);
}

return $template;
}

/**
* Implements hook_menu_local_tasks_alter().
*/
Expand Down

0 comments on commit 21604bd

Please sign in to comment.