From 9ff985bc265dad87b6028cd2f2df03f8d9d4cad6 Mon Sep 17 00:00:00 2001 From: bighappyface Date: Tue, 12 May 2020 13:01:59 -0500 Subject: [PATCH] Issue #3135006: Webform Handler Token String Conversion Notice --- ...bform.webform.test_handler_remote_post.yml | 25 +++++++++++-------- .../WebformTestHandlerRemotePostClient.php | 4 +++ .../Handler/WebformHandlerRemotePostTest.php | 6 +++++ webform.tokens.inc | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/modules/webform_test_handler_remote_post/config/install/webform.webform.test_handler_remote_post.yml b/tests/modules/webform_test_handler_remote_post/config/install/webform.webform.test_handler_remote_post.yml index c7a8abc4e..00bd4b4a8 100644 --- a/tests/modules/webform_test_handler_remote_post/config/install/webform.webform.test_handler_remote_post.yml +++ b/tests/modules/webform_test_handler_remote_post/config/install/webform.webform.test_handler_remote_post.yml @@ -22,6 +22,7 @@ elements: | 200: '200 OK' 401: '401 Unauthorized' 404: '404 Not Found' + 405: '405 Method Not Allowed' 500: '500 Internal Server Error' '#default_value': 200 first_name: @@ -38,7 +39,7 @@ elements: | '#title': 'Confirmation number' '#type': value '#value': '[webform:handler:remote_post:completed:confirmation_number]' - + css: '' javascript: '' settings: @@ -129,7 +130,7 @@ settings: confirmation_title: '' confirmation_message: |

Your confirmation number is [webform_submission:values:confirmation_number].

- + confirmation_url: '' confirmation_attributes: { } confirmation_back: true @@ -238,43 +239,45 @@ handlers: confirmation_number: confirmation_number custom_data: | custom_data: true - + custom_options: | headers: 'Accept-Language': '[webform_submission:langcode]' custom_header: 'true' - + cast: false debug: true completed_url: 'http://webform-test-handler-remote-post/completed' completed_custom_data: | custom_completed: true - + updated_url: 'http://webform-test-handler-remote-post/updated' updated_custom_data: | custom_updated: true - + deleted_url: 'http://webform-test-handler-remote-post/deleted' deleted_custom_data: | custom_deleted: true - + draft_created_url: 'http://webform-test-handler-remote-post/draft_created' draft_created_custom_data: | custom_draft_created: true - + draft_updated_url: 'http://webform-test-handler-remote-post/draft_updated' draft_updated_custom_data: | custom_draft_updated: true - + converted_url: 'http://webform-test-handler-remote-post/converted' converted_custom_data: | custom_converted: true - + message: '' messages: - code: 401 - message: 'This is a message token [webform:handler:remote_post:message]' + message: 'This is a message token [webform:handler:remote_post:message][webform:handler:remote_post:options]' - code: 404 message: 'This is a custom 404 not found message.' + - code: 405 + message: 'This is a array token [webform:handler:remote_post:options][webform:handler:remote_post:options:clear]' error_url: '' variants: { } diff --git a/tests/modules/webform_test_handler_remote_post/src/WebformTestHandlerRemotePostClient.php b/tests/modules/webform_test_handler_remote_post/src/WebformTestHandlerRemotePostClient.php index ace37b4ec..d2e7179d9 100644 --- a/tests/modules/webform_test_handler_remote_post/src/WebformTestHandlerRemotePostClient.php +++ b/tests/modules/webform_test_handler_remote_post/src/WebformTestHandlerRemotePostClient.php @@ -37,6 +37,10 @@ class WebformTestHandlerRemotePostClient extends Client { case 404: return new Response(404, [], 'File not found'); + // 405 Method Not Allowed. + case 405: + return new Response(405, [], 'Method Not Allowed'); + // 401 Unauthorized. case 401: $status = 401; diff --git a/tests/src/Functional/Handler/WebformHandlerRemotePostTest.php b/tests/src/Functional/Handler/WebformHandlerRemotePostTest.php index a02cf4974..5d5286075 100644 --- a/tests/src/Functional/Handler/WebformHandlerRemotePostTest.php +++ b/tests/src/Functional/Handler/WebformHandlerRemotePostTest.php @@ -172,6 +172,12 @@ options: $this->assertNoRaw('Unable to process this submission. Please contact the site administrator.'); $this->assertRaw('This is a message token Unauthorized to process completed request.'); + // Check 405 Method Not Allowed with custom message and token. + $this->postSubmission($webform, ['response_type' => '405']); + $this->assertRaw('Method Not Allowed'); + $this->assertNoRaw('Unable to process this submission. Please contact the site administrator.'); + $this->assertRaw('This is a array token [webform:handler:remote_post:options]'); + // Disable saving of results. $webform->setSetting('results_disabled', TRUE); $webform->save(); diff --git a/webform.tokens.inc b/webform.tokens.inc index fcb3bc0d6..810a476a9 100644 --- a/webform.tokens.inc +++ b/webform.tokens.inc @@ -832,7 +832,7 @@ function webform_tokens($type, $tokens, array $data, array $options, BubbleableM $key_exists = NULL; $value = NestedArray::getValue($webform_handler, $parents, $key_exists); // A handler response is always considered safe markup. - $replacements[$original] = ($key_exists) ? Markup::create($value) : $original; + $replacements[$original] = ($key_exists && is_scalar($value)) ? Markup::create($value) : $original; } } -- 2.24.2 (Apple Git-127)