This project is not covered by Drupal’s security advisory policy.

Links to webforms carry the entity of the page they are shown on, so every submission records where it came from. Editors link to /form/your-form; the module does the rest.

Sites often show one webform on many pages: a "Request a quote" button on every tour, "Ask about this product" on every product, "Apply" on every job offer. Webform can save the page the visitor came from as the submission's source entity, but only if the link carries source_entity_type and source_entity_id in its URL. Drupal core does not allow dynamic values in the URL of a link field, so this normally means a separate link for every page, or custom code.

This module adds those two parameters automatically, on the server, to every link that points to a webform. On the page of a node, a product or a term, a link to /form/quote becomes /form/quote?source_entity_type=node&source_entity_id=12, and Webform saves that node with the submission.

New to Drupal? Think of it this way: you have 80 tour pages and one "Request a quote" button that is shared by all of them. With this module, every quote you receive tells you which tour the visitor was looking at. You don't need a developer, and you don't need one form per tour.

Features

  • Automatic source entity. Links to a webform get the entity of the page as their source entity, with no parameters or tokens for editors to type. It works with any content entity type: nodes, taxonomy terms, users, Commerce products, custom entities…
  • Link fields and formatted text. It applies to any field whose type is, or extends, link, in entity view modes, Views fields and Layout Builder field blocks. For links written in CKEditor, enable the Pass the page entity to links to webforms filter in the text format.
  • Done on the server. The HTML already contains the final URL, so it works without JavaScript and for every link, not only special ones. If editors use Webform's ENTITY_TYPE and ENTITY_ID placeholders, they are resolved on the server too.
  • Same rules as Webform. The page entity is resolved with Webform's own route_parameters source entity plugin. Parameters are only added for webforms that accept them, and only for the entity type the webform allows.
  • Safe with Drupal's cache. A shared link (a content block, a view or a paragraph shown on many pages) is rendered once and cached. If its URL depended on the page but its cache entry did not, every page would serve the first page's URL. Every submission would be saved with the wrong source, and nothing on the site would show the error. The module adds its own route.page_entity cache context to every link it may rewrite, so each entity page gets its own cached variation. Automated kernel tests cover this.

When and why would someone use this module? Use cases include:

  • Travel and tours: A "Request a quote" button on every tour page, with the tour recorded in each request.
  • E-commerce and catalogs: "Ask about this product" or "Request a demo" forms that know which product the visitor was looking at.
  • Real estate, events, jobs: "Contact the agent", "Register" or "Apply" links that save the property, event or job offer with the submission.
  • CRM and marketing integrations: Webform handlers that send submissions to a CRM or by email receive the source entity too, and so do the [webform_submission:source-entity:*] tokens. Every lead arrives with its context.

Post-Installation

The module has no configuration page of its own. After enabling it:

  1. Edit the webform, go to Settings → Form → Form behaviors and enable Allow (only) the source entity to be populated using query string parameters. Optionally, restrict the source entity type there. Webforms without this setting do not get the parameters, because Webform would ignore them.
  2. In any link field (a block, a paragraph, a call to action…), link to the webform: /form/your-form.
  3. For links in formatted text, go to Administration → Configuration → Content authoring → Text formats and editors, edit the text format and enable the Pass the page entity to links to webforms filter. Only relative links (/form/your-form) are rewritten.
  4. To turn the feature off for the whole site, go to Structure → Webforms → Configuration → Forms → Third party settings → Links to webforms.

Clear caches (drush cr, or Administration → Configuration → Performance) after enabling the module, so that pages cached before it was enabled pick up the new links.

Additional Requirements

No external libraries or APIs. The requirements are:

  • Drupal core ^11.1 (the module uses object-oriented #[Hook] classes).
  • Core Link and Filter modules.
  • Webform ^6.3.
  • Current Page Entity Tokens: Provides tokens for the entity of the current page. It is a good fit for a webform embedded in the page. For a webform opened from a link, the form is loaded by its own request, where the "current page" is the form itself. That case is the one this module covers.

Similar projects

  • Webform's source entity placeholders: Webform can replace ENTITY_TYPE and ENTITY_ID placeholders in the browser, but only on links opened in its dialog. Editors have to type the placeholders in each URL, and without JavaScript they are removed. This module needs nothing from the editor, works on any link and builds the final URL on the server.
  • Current Page Entity Tokens: See above. It provides tokens rather than link behavior, and link fields do not support tokens in their URL (core issue #2903336).
  • Webform entity reference field ("Webform node"): Embeds a webform inside each entity and records that entity as the source. It is a good choice when every page carries its own form. This module is for the opposite case: one webform, linked from many pages.

I also maintain the following modules. They extend Drupal's native systems instead of replacing them, and they work alongside this one:

Commercial Support

This module is developed and maintained by Nelo.
The maintainer is available for professional consulting and architectural guidance on Webform integrations, lead capture and CRM workflows, caching, and production Drupal implementations.

Supporting this Module

- Check out our sponsor, Dom Host Seo, who made this module possible with their support!

Community Documentation

Currently no external videos or demo sites are available. The module's README.md explains the configuration and how caching is handled, and its CHANGELOG.md lists the changes between releases. The kernel test WebformLinkExtrasTest shows the expected behavior, including the shared-link cache case.

For questions, bug reports, or feature requests, please use the issue queue on Drupal.org.

Roadmap

Planned features, all about links to webforms:

  • Menu links that point to a webform.
  • Hide or disable the link while the webform is closed (scheduled open/close).
  • Prefill webform elements from the entity of the page.
  • Tell visitors when they have already submitted a webform that has a submission limit.
  • Send visitors back to the page they came from after submitting.

Project information

Releases