Drupalwoo ☉

Building a Drupal Module to Turn Webform Submissions into Nodes

Forms do the unglamorous work on most Drupal sites. A grant application, a membership sign-up, a workshop booking — each arrives through a Webform submission and then sits in a results table, waiting for someone to copy the key details into a node and publish it. On a small site that is manageable. On a site taking a few hundred registrations a month, it becomes the bottleneck that editors complain about every Friday afternoon.

The fix is a small custom Drupal module that watches for Webform submissions and creates the corresponding node automatically, ready for an editor to review. This walkthrough covers the decisions to make before you write code, the field mapping that causes the most grief, the trigger strategies available in Drupal 10 and 11, the queue and cron work that keeps the thing reliable, and the privacy and permission settings that matter once real submissions start flowing in.

Planning the module and its dependencies

Start by deciding exactly what the node should be. A common pattern is a plain submission content type with fields for the applicant's name, email address, phone number, and a reference back to the originating Webform submission. If the site is for a community college or a council grant programme, you might instead create a distinct node type per webform, such as membership_application or event_registration, each with fields tuned to that form. Deciding this up front keeps the module generic: it reads a mapping definition and applies it, rather than hard-coding one form's field names into a service class.

The module itself lives in modules/custom/ and follows the usual Drupal conventions: a machine name, an .info.yml file declaring dependencies, a composer.json file if it bundles any third-party PHP libraries, and a src/ directory for classes. Webform is a contributed module, so add it with composer require drupal/webform and declare drupal:webform as a dependency. You will also want drupal:node, drupal:field, and drupal:user because the module creates nodes, reads field definitions, and often resolves an editor account as the author.

Rather than scattering configuration through hooks, store the mapping as YAML in the module's config/install/ directory — a config entity of type webform_node_mapping, for example. That keeps the mapping exportable with drush config:export, reviewable in a merge request, and easy to edit in the admin UI if you later expose it as a form. Site editors get a place to adjust a mapping without touching PHP, which is usually the difference between a module that survives its first year and one that gets abandoned.

Mapping Webform data onto Drupal fields

Webform stores each submission as its own entity, and the values are available through getData(). The returned array is keyed by the webform field key rather than the label the visitor sees, and composite fields such as an address or a name with first and last components come back as nested arrays with numeric or keyed sub-values. Getting this structure wrong is the single most common reason a mapped node ends up with an empty field or a PHP error, so log a sample payload during development and inspect it rather than guessing.

The mapping code therefore needs to handle conversions, not just copies. Checkbox groups arrive as arrays and often need to be flattened into a string list or a boolean. Select fields store the option value, which may be a machine-readable string such as membership_standard or the visible label, depending on how the webform was configured. Date fields arrive as strings in Y-m-d H:i:s format and need converting to a timestamp. Entity reference fields need the referenced entity's ID, which usually means looking it up by label. Decimal fields, such as the membership fee or an event ticket price, need the string cast to a float.

$data = $submission->getData();
$values = is_array($data) ? $data : [];

$email = $values['email_address'] ?? '';
$first_name = $values['first_name'] ?? '';
$last_name = $values['last_name'] ?? '';
$membership = $values['membership_type'] ?? '';

Attachments deserve their own handling. Files uploaded through a webform upload field end up in the managed file system, so copy the relevant ones into a media entity and attach them to the node if you want the editorial team to see them. Where a webform field has no sensible node equivalent — a marketing consent tick box, a referral code, a CAPTCHA response — skip it rather than forcing it into a field nobody will read.

Triggering node creation from submissions

There are three realistic ways to intercept a submission, and each trades off immediacy against reliability. The cheapest is a submit handler injected with hook_form_alter(), which lets you build and save the node while the visitor is still waiting on the confirmation page. The next is an entity hook that fires once the webform submission has been stored. The third is to enqueue the work and process it during cron, which costs a little more code but survives errors.

If you go the form-alter route, identify the webform from the form object rather than by matching a form ID string. Webform appends unique suffixes to the identifiers it generates, so hard-coding an ID breaks the moment the editor duplicates a form. The same caution applies if you use Webform's own submission hooks, such as hook_webform_submission_presave, which are available in recent Webform releases but have shifted across versions. Check the hooks provided by the version you have installed before relying on them.

Approach When the node is created Code effort Error handling Suits
Submit handler via hook_form_alter() During the visitor's request Low Weak, failures surface to the user One simple form, low volume
Entity hook on the submission entity Right after the submission is saved Medium Fair, can log and retry A handful of known webforms
Queue plus cron On the next cron run Medium Strong, retries and back-off Production sites with steady volume
Rules module in the admin UI Configured by a site builder Very low to write Fair Editors who will not touch code
Custom endpoint receiving a POST Whenever the caller posts High Depends on implementation Third-party systems pushing data

For most Australian organisations — a regional council, an advocacy NGO, a training provider — the queue approach is the safer default. The visitor gets their confirmation immediately, the node appears shortly afterwards, and a transient failure does not mean a lost registration.

Queuing, reliability and editorial workflow

Drupal's queue API is designed for exactly this kind of deferred work. Instead of saving the node inside the request, the submit handler adds a queue item containing the submission ID and the mapping key. A cron callback then loads the submission, rebuilds the node, and deletes the queue item on success. If the node creation throws an exception, the item stays in the queue, and you can log the failure to the watchdog table and retry on the next run. Elysia Cron, a contributed module, gives you finer control over the schedule than the default cron run, which is useful when your site runs on shared hosting with a restricted cron window.

Make the job idempotent before you make it clever. Store the originating submission ID in a dedicated integer or entity reference field on the node, then check for an existing node with that value before creating a new one. Without that check, a retried queue item or a double-clicked submit button produces duplicate nodes, and cleaning them up by hand is tedious. A second guard is to look at the queue length and alert if it climbs above a threshold, which tells you the cron callback has stopped running.

Set the node to unpublished and assign it to an editorial role that can review, tag, and publish. This mirrors how editors already work on the rest of the site, and it keeps auto-generated content out of the front end until a human has checked it. If the site has the Workflows module enabled, you can drop the node straight into a review state, or assign a moderated content type so changes are tracked. Notifications to editors can fire on node creation, but send them with a plain-text fallback so the email reads properly in Outlook and on the mobile devices that most Australian staff use to check submissions.

Permissions, privacy and Australian deployment realities

Access control matters here because a webform submission holds personal information. Restrict the webform results view to a dedicated role, and give the module its own permission for triggering node creation rather than borrowing an existing one. In the node itself, decide whether the submitted email address and phone number belong on the node at all, or whether only the essentials should be copied across. Every additional field you duplicate is another record to protect, delete, or explain to someone asking what you hold about them.

The Privacy Act 1988 and the Australian Privacy Principles apply to any organisation that handles personal information, which covers most of the sites this module would run on. The OAIC expects an organisation to limit collection to what it needs, keep the information secure, and dispose of it when it is no longer required. A module that copies webform data into nodes should therefore include a clean-up path: a cron task or a scheduled command that deletes old submission-linked nodes, and a policy for how long the original webform submission is retained. If the module also triggers email marketing, the Spam Act 2003 sets consent requirements that need to be honoured at the point of submission.

Deployment details are shaped by local conditions. Hosting in an Australian region — Amazon's ap-southeast-2 in Sydney or Azure's Australia East — keeps the round trip short for staff sitting in Melbourne, Brisbane, or Perth. Time zones are the classic trap: daylight saving shifts the clock in most Australian states, which quietly breaks cron jobs scheduled at a fixed hour. Schedule the queue callback at an awkward time such as 03:10, and check the logs after both the April and October clock changes to confirm the callback still runs. Note that Queensland, the Northern Territory, and Western Australia do not observe daylight saving, so a national site has to cope with more than one offset.

The local market favours this kind of automation. Small businesses, councils, and community colleges across Australia run lean Drupal sites, and the agencies that support them in Sydney, Melbourne, and Canberra are usually asked for fewer manual steps, not more. The .com.au market is crowded, so content that reaches the front end quickly still matters. That makes the queue-and-review pattern worth the extra effort: submissions land as structured nodes, editors spend their working hours on judgement rather than data entry, and the module keeps doing its job after the next Drupal core update, the next Webform release, and the next round of PHP upgrades.

Test the mapping with a PHPUnit test that builds a webform submission fixture and asserts the resulting node fields. Run it in CI, deploy with drush deploy, and re-check the queue length after release. A module of this size is roughly three hundred lines of code plus configuration, and it pays for itself the first time an editor realises nobody has to retype a registration form into a node ever again.