Problem/Motivation

Specifying the host gives the following output in the DOM
<script src="////id.mktoweb.com/js/forms2/js/forms2.min.js"></script>

This is caused by the adding "//" prefix twice which is unnecessary. Although browsers seem to workaround this faulty syntax, this is not ideal and was actually picked by broken link checker.

Steps to reproduce

Add host to config, look at the actual generated DOM>

Remaining tasks

Will submit a patch later today.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

davisa created an issue. See original summary.

davisa’s picture

Issue summary: View changes

davisa’s picture

Removing the duplicate "//" lead to Drupal's domain being prefixed which is quite strange, and probably is the reason why quadruple //// is used instead as workaround.

davisa’s picture

I found the root cause.

MktoForms2.loadForm(host, munchkinId, formId);

The loadForm() expects a host with a "//" preffix as can be seen @ https://developers.marketo.com/rest-api/assets/forms/examples/
Since the backend strips out the "//", it's loaded without "//" preffix.

However, `marketo_forms.module` applies it twice and in some odd way makes the form load successfully. However, that is just a workaround that just works due to more broader browser support for invalid URL formatting. I've created a fix for this, merge request: https://git.drupalcode.org/project/marketo_forms/-/merge_requests/8

levmyshkin’s picture

Status: Active » Fixed

Thanks for the report and for chasing down the root cause, davisa — comment #5 is exactly right. MktoForms2.loadForm() wants the host with the "//" prefix, and the module was applying it twice.

Fixed on both branches:

3.0.x — commit 7efac19, released in 3.0.3
4.0.x — commit e191549, released in 4.1.0

The fix normalises at the opposite end from MR !8. $host keeps its "//" prefix, so drupalSettings.marketoForms.host stays in the shape loadForm() expects and js/marketo-forms.js needs no change; the duplicate prefix is dropped from the library's JS key instead:

-      "//{$host}/js/forms2/js/forms2.min.js" => [
+      "{$host}/js/forms2/js/forms2.min.js" => [

which gives src="//app-xxx.marketo.com/js/forms2/js/forms2.min.js". Same two slashes, just removed at the other end of the pipeline — both approaches are correct, and I picked this one because it leaves the JS untouched.

Two notes on MR !8, so it's clear why it wasn't merged as-is:

1. It patches marketo_forms.module, but since the Drupal 11 OOP hook conversion (fdb8a82) that file only contains #[LegacyHook] wrappers. The implementation that actually runs is Drupal\marketo_forms\Hook\MarketoFormsHooks::libraryInfoBuild(), so the MR's PHP hunk has no effect on D11.

2. Applied on top of the current code it would reintroduce the bug in mirror image: $host would lose its prefix while the JS adds one back, leaving drupalSettings.marketoForms.host and the script src disagreeing.

Fixed in the same commit: the library's license array was missing the "url" key, which raised an "Undefined array key" warning from JsCollectionOptimizerLazy on every page that embedded a form.

There is a regression test now, so this cannot come back silently — tests/src/Kernel/MarketoFormsLibraryTest.php asserts the script URL carries exactly two leading slashes, and MarketoFormsBlockTest::testForms2ScriptIsAttached() checks the rendered markup. Both run in GitLab CI.

Marking fixed. Credit to davisa for the report, the diagnosis and the MR.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

levmyshkin’s picture

Status: Fixed » Closed (fixed)