From ef0bee2404632bad705908c63f91803d8afb97a1 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Thu, 27 Apr 2023 14:44:36 +1000 Subject: [PATCH 01/16] [SDPAP-7716] Added managed file element type and related settings. --- config/optional/webform.settings.yml | 6 ++--- tide_webform.install | 24 ++++++++++++++++++++ tide_webform.module | 34 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/config/optional/webform.settings.yml b/config/optional/webform.settings.yml index f4b5aef..5c1f33b 100644 --- a/config/optional/webform.settings.yml +++ b/config/optional/webform.settings.yml @@ -123,7 +123,6 @@ element: fieldset: fieldset item: item language_select: language_select - managed_file: managed_file range: range search: search tableselect: tableselect @@ -140,7 +139,6 @@ element: webform_contact: webform_contact webform_custom_composite: webform_custom_composite webform_document_file: webform_document_file - webform_element: webform_element webform_email_confirm: webform_email_confirm webform_email_multiple: webform_email_multiple webform_entity_checkboxes: webform_entity_checkboxes @@ -181,8 +179,8 @@ file: file_public: false file_private_redirect: true file_private_redirect_message: 'Please login to access the uploaded file.' - default_max_filesize: '' - default_managed_file_extensions: 'gif jpg png bmp eps tif pict psd txt rtf html odf pdf doc docx ppt pptx xls xlsx xml avi mov mp3 ogg wav bz2 dmg gz jar rar sit svg tar zip' + default_max_filesize: '10 MB' + default_managed_file_extensions: 'docx jpg png pdf csv zip xls' default_audio_file_extensions: 'mp3 ogg wav' default_document_file_extensions: 'txt rtf pdf doc docx odt ppt pptx odp xls xlsx ods' default_image_file_extensions: 'gif jpg png svg' diff --git a/tide_webform.install b/tide_webform.install index 908aacb..194ff45 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -325,3 +325,27 @@ function tide_webform_update_8013() { $config->save(); } } + +/** + * Updating webform settings for managed_file types. + */ +function tide_webform_update_8014() { + if (\Drupal::moduleHandler()->moduleExists('webform')) { + $webform_elements = [ + 'managed_file', + 'webform_element', + ]; + $config_factory = \Drupal::configFactory(); + $config = $config_factory->getEditable('webform.settings'); + $excluded_elements_values = $config->get('element.excluded_elements'); + foreach ($webform_elements as $webform_element) { + if (array_key_exists($webform_element, $excluded_elements_values)) { + unset($excluded_elements_values[$webform_element]); + } + } + $config->set('element.excluded_elements', $excluded_elements_values); + $config->set('file.default_max_filesize', '10 MB'); + $config->set('default_managed_file_extensions', 'docx jpg png pdf csv zip xls'); + $config->save(); + } +} diff --git a/tide_webform.module b/tide_webform.module index e1560f1..a469dac 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -39,6 +39,8 @@ function tide_webform_form_alter(&$form, FormStateInterface $form_state, $form_i if ($form_id == 'webform_ui_element_form') { $form['#after_build'][] = 'tide_webform_webform_ui_element_form_after_build'; + // Custom validation for the managed_file elemt type. + $form['#validate'][] = 'tide_webform_managed_file_type_element_validation'; } if ($form_id == 'webform_submission_filter_form') { @@ -365,3 +367,35 @@ function tide_webform_form_webform_results_export_form_submit(array $form, FormS $options = ['query' => $query]; $form_state->setRedirect('entity.webform.results_export', $route_parameters, $options); } + +/** + * Custom validation callback for managed file type element. + * + * @param array $form + * The form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. + * + */ +function tide_webform_managed_file_type_element_validation(array $element, FormStateInterface $form_state) { + $allowed_file_formats = ['docx', 'jpg', 'png', 'pdf', 'csv', 'zip', 'xls']; + $element_settings = $form_state->getValues(); + if ($element_settings["properties"]["type"] !== "managed_file") { + return; + } + $given_file_formats = explode(" ", $element_settings["properties"]["file_extensions"]); + if ($element_settings["properties"]["multiple"] > 3) { + $form_state->setError($element, t('Maximum allowed number of values are 3.')); + } + $matched_values = array_intersect($allowed_file_formats, $given_file_formats); + if (count($matched_values) > 0) { + $unmatched_values = array_diff($given_file_formats, $matched_values); + if (count($unmatched_values) > 0) { + $form_state->setError($element, t('Invalid file formats found:' . implode(", ", $unmatched_values))); + } + } + $unmatched_values = array_diff($allowed_file_formats, $matched_values); + if (count($matched_values) == 0 && count($unmatched_values) > 0) { + $form_state->setError($element, t('Invalid file formats found::' . implode(", ", $given_file_formats))); + } +} From 85f546198f97fd3975991ce762986d7bedd145bb Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Thu, 27 Apr 2023 14:56:45 +1000 Subject: [PATCH 02/16] [SDPAP-7716] Updated lint fix. --- tide_webform.install | 2 +- tide_webform.module | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tide_webform.install b/tide_webform.install index 194ff45..92d15c7 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -341,7 +341,7 @@ function tide_webform_update_8014() { foreach ($webform_elements as $webform_element) { if (array_key_exists($webform_element, $excluded_elements_values)) { unset($excluded_elements_values[$webform_element]); - } + } } $config->set('element.excluded_elements', $excluded_elements_values); $config->set('file.default_max_filesize', '10 MB'); diff --git a/tide_webform.module b/tide_webform.module index a469dac..16c1b6d 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -371,11 +371,10 @@ function tide_webform_form_webform_results_export_form_submit(array $form, FormS /** * Custom validation callback for managed file type element. * - * @param array $form + * @param array $element * The form. * @param \Drupal\Core\Form\FormStateInterface $form_state * Form state. - * */ function tide_webform_managed_file_type_element_validation(array $element, FormStateInterface $form_state) { $allowed_file_formats = ['docx', 'jpg', 'png', 'pdf', 'csv', 'zip', 'xls']; @@ -391,11 +390,11 @@ function tide_webform_managed_file_type_element_validation(array $element, FormS if (count($matched_values) > 0) { $unmatched_values = array_diff($given_file_formats, $matched_values); if (count($unmatched_values) > 0) { - $form_state->setError($element, t('Invalid file formats found:' . implode(", ", $unmatched_values))); + $form_state->setError($element, t('Invalid file formats found: @format', ['@format' => implode(", ", $unmatched_values)])); } } $unmatched_values = array_diff($allowed_file_formats, $matched_values); if (count($matched_values) == 0 && count($unmatched_values) > 0) { - $form_state->setError($element, t('Invalid file formats found::' . implode(", ", $given_file_formats))); + $form_state->setError($element, t('Invalid file formats found: @format', ['@format' => implode(", ", $given_file_formats)])); } } From 2fcdda570c3000acb27d0d5c4bf48ee764c1b9d7 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Thu, 27 Apr 2023 16:14:32 +1000 Subject: [PATCH 03/16] Updated hook. --- tide_webform.install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide_webform.install b/tide_webform.install index 92d15c7..bb82a93 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -345,7 +345,7 @@ function tide_webform_update_8014() { } $config->set('element.excluded_elements', $excluded_elements_values); $config->set('file.default_max_filesize', '10 MB'); - $config->set('default_managed_file_extensions', 'docx jpg png pdf csv zip xls'); + $config->set('file.default_managed_file_extensions', 'docx jpg png pdf csv zip xls'); $config->save(); } } From e495a8a448b56547662a0b869c4b6a9c13312f72 Mon Sep 17 00:00:00 2001 From: edyuenyw <67810118+edyuenyw@users.noreply.github.com> Date: Tue, 23 May 2023 11:00:46 +1000 Subject: [PATCH 04/16] [SDPAP-7717] Form submission with attachments (#85) * [SDPAP-7717] Form submission with attachments. --- src/TideWebformSubmissionListBuilder.php | 18 ++++++++++++++++++ tide_webform.module | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/TideWebformSubmissionListBuilder.php b/src/TideWebformSubmissionListBuilder.php index 86bec6e..22ce9e2 100644 --- a/src/TideWebformSubmissionListBuilder.php +++ b/src/TideWebformSubmissionListBuilder.php @@ -2,6 +2,7 @@ namespace Drupal\tide_webform; +use Drupal\Core\Database\Database; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\webform\WebformSubmissionListBuilder; @@ -24,6 +25,11 @@ class TideWebformSubmissionListBuilder extends WebformSubmissionListBuilder { */ const STATE_UNPROCESSED = 'unprocessed'; + /** + * Submission state with_attachments. + */ + const STATE_WITH_ATTACHMENTS = 'with_attachments'; + /** * {@inheritdoc} */ @@ -48,6 +54,18 @@ protected function getQuery($keys = '', $state = '', $source_entity = '') { $query->condition('processed', 0); break; + case static::STATE_WITH_ATTACHMENTS: + $sub_query = Database::getConnection()->select('webform_submission_data', 'sd'); + $sub_query->join('file_usage', 'fu', 'fu.fid = CAST(sd.value as UNSIGNED)'); + $sub_query + ->fields('sd', ['sid']) + ->condition('sd.value', '', '<>') + ->groupBy('sd.sid'); + $query->condition( + $query->orConditionGroup() + ->condition('sid', $sub_query, 'IN') + ); + break; } return $query; } diff --git a/tide_webform.module b/tide_webform.module index 16c1b6d..3bada4e 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -47,6 +47,7 @@ function tide_webform_form_alter(&$form, FormStateInterface $form_state, $form_i $options = $form['filter']['state']['#options']; $options['processed'] = 'Exported [' . tide_webform_submission_filter_query(1) . ']'; $options['unprocessed'] = 'New [' . tide_webform_submission_filter_query(0) . ']'; + $options['with_attachments'] = 'With attachments [' . tide_webform_submission_data_filter() . ']'; $form['filter']['state']['#options'] = $options; } @@ -398,3 +399,21 @@ function tide_webform_managed_file_type_element_validation(array $element, FormS $form_state->setError($element, t('Invalid file formats found: @format', ['@format' => implode(", ", $given_file_formats)])); } } + +/** + * Function to build query for filter on webform submissions data pages. + * + * @return total + * Returns total from the webform submission data count. + */ +function tide_webform_submission_data_filter() { + $database = \Drupal::service('database'); + $select = $database->select('webform_submission_data', 'sd'); + $select->join('file_usage', 'fu', 'fu.fid = sd.value'); + $select + ->fields('sd', ['sid']) + ->condition('sd.value', '', '<>'); + $select->groupBy('sid'); + $total = $select->countQuery()->execute()->fetchField(); + return $total; +} From a1d9b22d9213dd93754358f84c4b77832fa29c3c Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 11:19:42 +1000 Subject: [PATCH 05/16] Merged develop changes. --- composer.json | 4 ++++ config/optional/webform.settings.yml | 2 +- tide_webform.install | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6b800ba..ff79ca5 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "dpc-sdp/tide_core": "3.2.5", "drupal/token_conditions": "dev-compatible-with-drupal-9", "drupal/webform": "^6.1@beta", + "drupal/webform_rest": "^4.0", "choices/choices": "9.0.1", "codemirror/codemirror": "5.53.2", "jquery/inputmask": "5.0.5", @@ -18,6 +19,9 @@ "drupal/webform": { "Filtering by category doesn't work - https://www.drupal.org/project/webform/issues/3313766": "https://www.drupal.org/files/issues/2022-10-07/3313766-8.patch", "Exporting webform submission as batch does not allowed for extended field due to static method - https://www.drupal.org/project/webform/issues/3348336#comment-14969352": "https://www.drupal.org/files/issues/2023-03-16/exporting-webform-submission-static-batch-process-3348336-3.patch" + }, + "drupal/webform_rest": { + "Send/Upload files - https://www.drupal.org/project/webform_rest/issues/2899902": "https://www.drupal.org/files/issues/2023-05-10/webform_rest-add_file_upload_resource-2899902-56-v4.0.2.patch" } } }, diff --git a/config/optional/webform.settings.yml b/config/optional/webform.settings.yml index 5c1f33b..dffac73 100644 --- a/config/optional/webform.settings.yml +++ b/config/optional/webform.settings.yml @@ -176,7 +176,7 @@ html_editor: format: '' tidy: true file: - file_public: false + file_public: true file_private_redirect: true file_private_redirect_message: 'Please login to access the uploaded file.' default_max_filesize: '10 MB' diff --git a/tide_webform.install b/tide_webform.install index bb82a93..55d0aa6 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -345,6 +345,7 @@ function tide_webform_update_8014() { } $config->set('element.excluded_elements', $excluded_elements_values); $config->set('file.default_max_filesize', '10 MB'); + $config->set('file.file_public', true); $config->set('file.default_managed_file_extensions', 'docx jpg png pdf csv zip xls'); $config->save(); } From 9b30400903e8899e1156cad8c8fe7f24b56c100f Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 12:04:59 +1000 Subject: [PATCH 06/16] [SDPAP-7716] Added more changes. --- .../rest.resource.webform_rest_file_upload.yml | 17 +++++++++++++++++ config/optional/webform.settings.yml | 2 +- tide_webform.install | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 config/optional/rest.resource.webform_rest_file_upload.yml diff --git a/config/optional/rest.resource.webform_rest_file_upload.yml b/config/optional/rest.resource.webform_rest_file_upload.yml new file mode 100644 index 0000000..4fdc00e --- /dev/null +++ b/config/optional/rest.resource.webform_rest_file_upload.yml @@ -0,0 +1,17 @@ +langcode: en +status: true +dependencies: + module: + - serialization + - user + - webform_rest +id: webform_rest_file_upload +plugin_id: webform_rest_file_upload +granularity: resource +configuration: + methods: + - POST + formats: + - json + authentication: + - cookie diff --git a/config/optional/webform.settings.yml b/config/optional/webform.settings.yml index dffac73..7d4f5eb 100644 --- a/config/optional/webform.settings.yml +++ b/config/optional/webform.settings.yml @@ -180,7 +180,7 @@ file: file_private_redirect: true file_private_redirect_message: 'Please login to access the uploaded file.' default_max_filesize: '10 MB' - default_managed_file_extensions: 'docx jpg png pdf csv zip xls' + default_managed_file_extensions: 'docx jpg png pdf csv zip xls mp3 mp4 wav avi' default_audio_file_extensions: 'mp3 ogg wav' default_document_file_extensions: 'txt rtf pdf doc docx odt ppt pptx odp xls xlsx ods' default_image_file_extensions: 'gif jpg png svg' diff --git a/tide_webform.install b/tide_webform.install index 55d0aa6..2c4e272 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -330,6 +330,13 @@ function tide_webform_update_8013() { * Updating webform settings for managed_file types. */ function tide_webform_update_8014() { + /** @var \Drupal\Core\Extension\ModuleHandler $moduleHandler */ + $moduleExists = \Drupal::service('module_handler')->moduleExists('webform_rest'); + // Check if module is both installed and enabled. + if (!$moduleExists) { + // If not, install the queue_mail module. + \Drupal::service('module_installer')->install(['webform_rest']); + } if (\Drupal::moduleHandler()->moduleExists('webform')) { $webform_elements = [ 'managed_file', @@ -346,7 +353,13 @@ function tide_webform_update_8014() { $config->set('element.excluded_elements', $excluded_elements_values); $config->set('file.default_max_filesize', '10 MB'); $config->set('file.file_public', true); - $config->set('file.default_managed_file_extensions', 'docx jpg png pdf csv zip xls'); + $config->set('file.default_managed_file_extensions', 'docx jpg png pdf csv zip xls mp3 mp4 wav avi'); $config->save(); } + module_load_include('inc', 'tide_core', 'includes/helpers'); + $config_storage = \Drupal::service('config.storage'); + $rest_resource_webform_file_upload = 'rest.resource.webform_rest_file_upload'; + $config_location = [drupal_get_path('module', 'tide_webform') . '/config/optional']; + $config_read = _tide_read_config($rest_resource_webform_file_upload, $config_location, TRUE); + $config_storage->write($rest_resource_webform_file_upload, $config_read); } From 9e4c3fece75041255d6ab97741dfae9acd0a2888 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 13:33:17 +1000 Subject: [PATCH 07/16] Updated the patch. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ff79ca5..47db00a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "Exporting webform submission as batch does not allowed for extended field due to static method - https://www.drupal.org/project/webform/issues/3348336#comment-14969352": "https://www.drupal.org/files/issues/2023-03-16/exporting-webform-submission-static-batch-process-3348336-3.patch" }, "drupal/webform_rest": { - "Send/Upload files - https://www.drupal.org/project/webform_rest/issues/2899902": "https://www.drupal.org/files/issues/2023-05-10/webform_rest-add_file_upload_resource-2899902-56-v4.0.2.patch" + "Send/Upload files - https://www.drupal.org/project/webform_rest/issues/2899902": "https://www.drupal.org/files/issues/2023-05-10/webform_rest-add_file_upload_resource-2899902-56-v4.x.patch" } } }, From 986d1c49823114814458dfe0ff843c56927c9630 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 13:41:44 +1000 Subject: [PATCH 08/16] Added lint fix. --- tide_webform.install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide_webform.install b/tide_webform.install index 2c4e272..21ac9ec 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -352,7 +352,7 @@ function tide_webform_update_8014() { } $config->set('element.excluded_elements', $excluded_elements_values); $config->set('file.default_max_filesize', '10 MB'); - $config->set('file.file_public', true); + $config->set('file.file_public', TRUE); $config->set('file.default_managed_file_extensions', 'docx jpg png pdf csv zip xls mp3 mp4 wav avi'); $config->save(); } From 6e320174f5819ca25f4e629d4e69859110bc92a2 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 15:15:31 +1000 Subject: [PATCH 09/16] [SDPAP-7716] Added file delete restrictions trhough json api. --- composer.json | 1 + .../JsonapiLimitingRouteSubscriber.php | 47 +++++++++++++++++++ tide_webform.info.yml | 2 + tide_webform.install | 2 +- tide_webform.services.yml | 6 ++- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/Routing/JsonapiLimitingRouteSubscriber.php diff --git a/composer.json b/composer.json index 47db00a..8c9006c 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "drupal/token_conditions": "dev-compatible-with-drupal-9", "drupal/webform": "^6.1@beta", "drupal/webform_rest": "^4.0", + "drupal/restui": "^1.21", "choices/choices": "9.0.1", "codemirror/codemirror": "5.53.2", "jquery/inputmask": "5.0.5", diff --git a/src/Routing/JsonapiLimitingRouteSubscriber.php b/src/Routing/JsonapiLimitingRouteSubscriber.php new file mode 100644 index 0000000..5ac6256 --- /dev/null +++ b/src/Routing/JsonapiLimitingRouteSubscriber.php @@ -0,0 +1,47 @@ +mutableResourceTypes(); + foreach ($collection as $name => $route) { + $defaults = $route->getDefaults(); + if (!empty($defaults['_is_jsonapi']) && !empty($defaults['resource_type'])) { + $methods = $route->getMethods(); + if (in_array('DELETE', $methods)) { + // We never want to delete data, only unpublish. + $collection->remove($name); + } + } + } + } + + /** + * Get mutable resource types, exposed to user changes via API. + * + * @return array + * List of mutable jsonapi resource types as keys. + */ + public function mutableResourceTypes(): array { + return [ + 'file--file' => TRUE, + ]; + } + +} diff --git a/tide_webform.info.yml b/tide_webform.info.yml index 3919934..bfb611f 100644 --- a/tide_webform.info.yml +++ b/tide_webform.info.yml @@ -9,6 +9,8 @@ dependencies: - token_conditions:token_conditions - webform:webform - webform:webform_ui + - webform_rest:webform_rest + - restui:restui - dpc-sdp:tide_core config_devel: install: diff --git a/tide_webform.install b/tide_webform.install index 21ac9ec..c2b9a9b 100644 --- a/tide_webform.install +++ b/tide_webform.install @@ -335,7 +335,7 @@ function tide_webform_update_8014() { // Check if module is both installed and enabled. if (!$moduleExists) { // If not, install the queue_mail module. - \Drupal::service('module_installer')->install(['webform_rest']); + \Drupal::service('module_installer')->install(['webform_rest', 'restui']); } if (\Drupal::moduleHandler()->moduleExists('webform')) { $webform_elements = [ diff --git a/tide_webform.services.yml b/tide_webform.services.yml index f639a16..95fdc9d 100644 --- a/tide_webform.services.yml +++ b/tide_webform.services.yml @@ -4,4 +4,8 @@ services: public: false decorates: webform_submission.exporter decoration_priority: 4 - arguments: ['@tide_webform.exporter.inner', '@config.factory', '@file_system', '@entity_type.manager', '@stream_wrapper_manager', '@plugin.manager.archiver', '@plugin.manager.webform.element', '@plugin.manager.webform.exporter'] \ No newline at end of file + arguments: ['@tide_webform.exporter.inner', '@config.factory', '@file_system', '@entity_type.manager', '@stream_wrapper_manager', '@plugin.manager.archiver', '@plugin.manager.webform.element', '@plugin.manager.webform.exporter'] + tide_webform.route_subscriber: + class: Drupal\tide_webform\Routing\JsonapiLimitingRouteSubscriber + tags: + - { name: event_subscriber } From ea1423b9ee97c63be7c6efe96317691b90d2918a Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 16:42:45 +1000 Subject: [PATCH 10/16] [SDPAP-7716] Updated the custom validation. --- tide_webform.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide_webform.module b/tide_webform.module index 3bada4e..c9d72f4 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -384,7 +384,7 @@ function tide_webform_managed_file_type_element_validation(array $element, FormS return; } $given_file_formats = explode(" ", $element_settings["properties"]["file_extensions"]); - if ($element_settings["properties"]["multiple"] > 3) { + if ($element_settings["properties"]["multiple"] > 3 || $element_settings["properties"]["multiple"] === true) { $form_state->setError($element, t('Maximum allowed number of values are 3.')); } $matched_values = array_intersect($allowed_file_formats, $given_file_formats); From 45b9a6c0042e3a190403e1415a434991512718f5 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 16:43:26 +1000 Subject: [PATCH 11/16] [SDPAP-7716] Updated the custom validation. --- tide_webform.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide_webform.module b/tide_webform.module index c9d72f4..01ca539 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -378,7 +378,7 @@ function tide_webform_form_webform_results_export_form_submit(array $form, FormS * Form state. */ function tide_webform_managed_file_type_element_validation(array $element, FormStateInterface $form_state) { - $allowed_file_formats = ['docx', 'jpg', 'png', 'pdf', 'csv', 'zip', 'xls']; + $allowed_file_formats = ['docx', 'jpg', 'png', 'pdf', 'csv', 'zip', 'xls', 'mp3', 'mp4', 'wav', 'avi']; $element_settings = $form_state->getValues(); if ($element_settings["properties"]["type"] !== "managed_file") { return; From 41123c9306a4d189ef8853e90d4903b988ca6d88 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 16:54:16 +1000 Subject: [PATCH 12/16] [SDPAP-7716] lint issues fixed. --- tide_webform.module | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tide_webform.module b/tide_webform.module index 01ca539..b2d55fc 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -378,13 +378,25 @@ function tide_webform_form_webform_results_export_form_submit(array $form, FormS * Form state. */ function tide_webform_managed_file_type_element_validation(array $element, FormStateInterface $form_state) { - $allowed_file_formats = ['docx', 'jpg', 'png', 'pdf', 'csv', 'zip', 'xls', 'mp3', 'mp4', 'wav', 'avi']; + $allowed_file_formats = [ + 'docx', + 'jpg', + 'png', + 'pdf', + 'csv', + 'zip', + 'xls', + 'mp3', + 'mp4', + 'wav', + 'avi', + ]; $element_settings = $form_state->getValues(); if ($element_settings["properties"]["type"] !== "managed_file") { return; } $given_file_formats = explode(" ", $element_settings["properties"]["file_extensions"]); - if ($element_settings["properties"]["multiple"] > 3 || $element_settings["properties"]["multiple"] === true) { + if ($element_settings["properties"]["multiple"] > 3 || $element_settings["properties"]["multiple"] === TRUE) { $form_state->setError($element, t('Maximum allowed number of values are 3.')); } $matched_values = array_intersect($allowed_file_formats, $given_file_formats); From 96c2e2cd890acc4b0ead77e635b9dc4e4dd012a5 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Tue, 23 May 2023 17:04:48 +1000 Subject: [PATCH 13/16] [SDPAP-7716] lint issues fixed. --- tide_webform.module | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tide_webform.module b/tide_webform.module index b2d55fc..a23fd21 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -379,16 +379,16 @@ function tide_webform_form_webform_results_export_form_submit(array $form, FormS */ function tide_webform_managed_file_type_element_validation(array $element, FormStateInterface $form_state) { $allowed_file_formats = [ - 'docx', - 'jpg', - 'png', - 'pdf', - 'csv', - 'zip', - 'xls', - 'mp3', - 'mp4', - 'wav', + 'docx', + 'jpg', + 'png', + 'pdf', + 'csv', + 'zip', + 'xls', + 'mp3', + 'mp4', + 'wav', 'avi', ]; $element_settings = $form_state->getValues(); From f82dee0d5ded4a879022ffa3a14b1c5624c4a314 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Wed, 24 May 2023 10:23:35 +1000 Subject: [PATCH 14/16] [SDPAP-7716] Reverting routing event subscribing changes. --- .../JsonapiLimitingRouteSubscriber.php | 47 ------------------- tide_webform.services.yml | 4 -- 2 files changed, 51 deletions(-) delete mode 100644 src/Routing/JsonapiLimitingRouteSubscriber.php diff --git a/src/Routing/JsonapiLimitingRouteSubscriber.php b/src/Routing/JsonapiLimitingRouteSubscriber.php deleted file mode 100644 index 5ac6256..0000000 --- a/src/Routing/JsonapiLimitingRouteSubscriber.php +++ /dev/null @@ -1,47 +0,0 @@ -mutableResourceTypes(); - foreach ($collection as $name => $route) { - $defaults = $route->getDefaults(); - if (!empty($defaults['_is_jsonapi']) && !empty($defaults['resource_type'])) { - $methods = $route->getMethods(); - if (in_array('DELETE', $methods)) { - // We never want to delete data, only unpublish. - $collection->remove($name); - } - } - } - } - - /** - * Get mutable resource types, exposed to user changes via API. - * - * @return array - * List of mutable jsonapi resource types as keys. - */ - public function mutableResourceTypes(): array { - return [ - 'file--file' => TRUE, - ]; - } - -} diff --git a/tide_webform.services.yml b/tide_webform.services.yml index 95fdc9d..993c7a5 100644 --- a/tide_webform.services.yml +++ b/tide_webform.services.yml @@ -5,7 +5,3 @@ services: decorates: webform_submission.exporter decoration_priority: 4 arguments: ['@tide_webform.exporter.inner', '@config.factory', '@file_system', '@entity_type.manager', '@stream_wrapper_manager', '@plugin.manager.archiver', '@plugin.manager.webform.element', '@plugin.manager.webform.exporter'] - tide_webform.route_subscriber: - class: Drupal\tide_webform\Routing\JsonapiLimitingRouteSubscriber - tags: - - { name: event_subscriber } From ccddacf35a772532cbd9c2cd9099e8275b94f7cf Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Thu, 25 May 2023 14:54:46 +1000 Subject: [PATCH 15/16] [SDPAP-7716] Updated the cusom validation to allow upto 10 attachments. --- tide_webform.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide_webform.module b/tide_webform.module index a23fd21..b6fdc77 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -396,7 +396,7 @@ function tide_webform_managed_file_type_element_validation(array $element, FormS return; } $given_file_formats = explode(" ", $element_settings["properties"]["file_extensions"]); - if ($element_settings["properties"]["multiple"] > 3 || $element_settings["properties"]["multiple"] === TRUE) { + if ($element_settings["properties"]["multiple"] > 10 || $element_settings["properties"]["multiple"] === TRUE) { $form_state->setError($element, t('Maximum allowed number of values are 3.')); } $matched_values = array_intersect($allowed_file_formats, $given_file_formats); From 39d348152220e89f31001ef8536b392c7a10c697 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Fri, 26 May 2023 10:18:45 +1000 Subject: [PATCH 16/16] [SDPAP-7716] Updated the cusom validation message. --- tide_webform.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide_webform.module b/tide_webform.module index b6fdc77..6df3ace 100644 --- a/tide_webform.module +++ b/tide_webform.module @@ -397,7 +397,7 @@ function tide_webform_managed_file_type_element_validation(array $element, FormS } $given_file_formats = explode(" ", $element_settings["properties"]["file_extensions"]); if ($element_settings["properties"]["multiple"] > 10 || $element_settings["properties"]["multiple"] === TRUE) { - $form_state->setError($element, t('Maximum allowed number of values are 3.')); + $form_state->setError($element, t('Maximum allowed number of values are 10.')); } $matched_values = array_intersect($allowed_file_formats, $given_file_formats); if (count($matched_values) > 0) {