diff --git a/CHANGELOG.md b/CHANGELOG.md index d15a292c..f85c82ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +## [3.15.1] 2024-05-14 + +- Added missing return type. +- Added new webform submission storage class to handle enable both encryption + and revision at the same time. + ## [3.15.0] 2024-05-03 - Added webform encryption modules @@ -218,7 +224,8 @@ 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.15.0...HEAD +[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.15.1...HEAD +[3.15.1]: https://github.com/OS2Forms/os2forms/compare/3.15.0...3.15.1 [3.15.0]: https://github.com/OS2Forms/os2forms/compare/3.14.1...3.15.0 [3.14.1]: https://github.com/OS2Forms/os2forms/compare/3.14.0...3.14.1 [3.14.0]: https://github.com/OS2Forms/os2forms/compare/3.13.3...3.14.0 diff --git a/modules/os2forms_encrypt/os2forms_encrypt.install b/modules/os2forms_encrypt/os2forms_encrypt.install new file mode 100644 index 00000000..0a42e4ee --- /dev/null +++ b/modules/os2forms_encrypt/os2forms_encrypt.install @@ -0,0 +1,19 @@ +setStorageClass('Drupal\os2forms_encrypt\WebformOs2FormsEncryptSubmissionStorage'); + } +} diff --git a/modules/os2forms_encrypt/src/WebformOs2FormsEncryptSubmissionStorage.php b/modules/os2forms_encrypt/src/WebformOs2FormsEncryptSubmissionStorage.php new file mode 100644 index 00000000..ac02e348 --- /dev/null +++ b/modules/os2forms_encrypt/src/WebformOs2FormsEncryptSubmissionStorage.php @@ -0,0 +1,175 @@ +moduleExists('webform_revisions')) { + return parent::getColumns($webform, $source_entity, $account, $include_elements); + } + else { + $view_any = $webform && $webform->access('submission_view_any'); + + $columns = []; + + // Serial number. + $columns['serial'] = [ + 'title' => $this->t('#'), + ]; + + // Submission ID. + $columns['sid'] = [ + 'title' => $this->t('SID'), + ]; + + // Submission label. + $columns['label'] = [ + 'title' => $this->t('Submission title'), + 'sort' => FALSE, + ]; + + // UUID. + $columns['uuid'] = [ + 'title' => $this->t('UUID'), + ]; + + // Draft. + $columns['in_draft'] = [ + 'title' => $this->t('In draft'), + ]; + + if (empty($account)) { + // Sticky (Starred/Unstarred). + $columns['sticky'] = [ + 'title' => $this->t('Starred'), + ]; + + // Locked. + $columns['locked'] = [ + 'title' => $this->t('Locked'), + ]; + + // Notes. + $columns['notes'] = [ + 'title' => $this->t('Notes'), + ]; + } + + // Created. + $columns['created'] = [ + 'title' => $this->t('Created'), + ]; + + // Completed. + $columns['completed'] = [ + 'title' => $this->t('Completed'), + ]; + + // Changed. + $columns['changed'] = [ + 'title' => $this->t('Changed'), + ]; + + // Source entity. + if ($view_any && empty($source_entity)) { + $columns['entity'] = [ + 'title' => $this->t('Submitted to'), + 'sort' => FALSE, + ]; + } + + // Submitted by. + if (empty($account)) { + $columns['uid'] = [ + 'title' => $this->t('User'), + ]; + } + + // Submission language. + if ($view_any && \Drupal::moduleHandler()->moduleExists('language')) { + $columns['langcode'] = [ + 'title' => $this->t('Language'), + ]; + } + + // Remote address. + $columns['remote_addr'] = [ + 'title' => $this->t('IP address'), + ]; + + // Webform and source entity for entity.webform_submission.collection. + // @see /admin/structure/webform/submissions/manage + if (empty($webform) && empty($source_entity)) { + $columns['webform_id'] = [ + 'title' => $this->t('Webform'), + ]; + $columns['entity'] = [ + 'title' => $this->t('Submitted to'), + 'sort' => FALSE, + ]; + } + + // Webform elements. + if ($webform && $include_elements) { + /** @var \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager */ + $element_manager = \Drupal::service('plugin.manager.webform.element'); + $content_entity_id = $webform->getContentEntityID(); + $revision_ids = $this->database->query( + 'SELECT revision FROM {config_entity_revisions_revision} WHERE id = :id', + [':id' => $content_entity_id] + )->fetchCol(); + if (!$revision_ids) { + return parent::getColumns($webform, $source_entity, $account, $include_elements); + } + + foreach ($revision_ids as $revision_id) { + $revisionController = WebformRevisionsController::create(\Drupal::getContainer()); + $webform = $revisionController->loadConfigEntityRevision($revision_id, $webform->id()); + $elements = $webform->getElementsInitializedFlattenedAndHasValue('view'); + foreach ($elements as $element) { + /** @var \Drupal\webform\Plugin\WebformElementInterface $element_plugin */ + $element_plugin = $element_manager->createInstance($element['#type']); + // Replace tokens which can be used in an element's #title. + $element_plugin->replaceTokens($element, $webform); + $columns += $element_plugin->getTableColumn($element); + } + } + } + + // Operations. + $columns['operations'] = [ + 'title' => $this->t('Operations'), + 'sort' => FALSE, + ]; + + // Add name and format to all columns. + foreach ($columns as $name => &$column) { + $column['name'] = $name; + $column['format'] = 'value'; + } + + return $columns; + } + } + +} diff --git a/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php b/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php index 94e64fbb..1eb27312 100644 --- a/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php +++ b/modules/os2forms_webform_list/src/CustomWebformEntityListBuilder.php @@ -2,6 +2,7 @@ namespace Drupal\os2forms_webform_list; +use Drupal\Core\Entity\Query\QueryInterface; use Drupal\webform\WebformEntityListBuilder; /** @@ -27,7 +28,7 @@ class CustomWebformEntityListBuilder extends WebformEntityListBuilder { * @return \Drupal\Core\Entity\Query\QueryInterface * An entity query. */ - protected function getQuery($keys = '', $category = '', $state = '') { + protected function getQuery($keys = '', $category = '', $state = ''): QueryInterface { $query = parent::getQuery($keys, $category, $state); // Setup a required condition for the list builder to respect webform update