Skip to main content

Submission data for add-ons

Overview​

Three services for an add-on that keeps data of its own on submissions:

  • a submission column keeps an array of yours on each submission, in a column your module adds;
  • submission presence tells whether a form has submissions with a value in that column;
  • an erasure step clears your copy of a customer's personal data when an admin erases it.

Short names are relative to MageMe\WebForms\. A complete class starts with <?php; any other code block is an excerpt.

Keep an array on each submission​

Your module can keep an array on each submission in a column of its own, added by its db_schema.xml. Implement MageMe\WebForms\Api\ResultSerializedColumnsInterface and register it, and WebForms stores the array in that column as JSON. Your code sets and reads the array under a data key and never touches the column.

The Cart Quote add-on keeps the quoted products this way. Its etc/db_schema.xml adds the column. Generate etc/db_schema_whitelist.json for it, as for any declarative schema change:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="mm_webforms_result" resource="default" engine="innodb">
<column xsi:type="text" name="cartquote_products_serialized" nullable="true" comment="CartQuote Products in JSON"/>
</table>
</schema>

The class is registered in the global etc/di.xml:

<type name="MageMe\WebForms\Model\ResourceModel\Result">
<arguments>
<argument name="serializedColumns" xsi:type="array">
<item name="webforms_cartquote" xsi:type="object">MageMe\WebFormsCartQuote\Model\CartColumn</item>
</argument>
</arguments>
</type>

The class, where CARTQUOTE_PRODUCTS is the data key cartquote_products and CARTQUOTE_PRODUCTS_SERIALIZED is the column cartquote_products_serialized:

<?php
declare(strict_types=1);

namespace MageMe\WebFormsCartQuote\Model;

use MageMe\WebForms\Api\ResultSerializedColumnsInterface;
use MageMe\WebFormsCartQuote\Api\Data\ResultInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Model\AbstractModel;

class CartColumn implements ResultSerializedColumnsInterface
{
public function getSerializedColumns(): array
{
return [ResultInterface::CARTQUOTE_PRODUCTS => ResultInterface::CARTQUOTE_PRODUCTS_SERIALIZED];
}

public function afterSerialize(DataObject $result): void
{
if (!empty($result->getData(ResultInterface::CARTQUOTE_PRODUCTS))) {
return;
}
if ($result instanceof AbstractModel && $this->hadCart($result)) {
$result->setData(ResultInterface::CARTQUOTE_PRODUCTS_SERIALIZED, null);
return;
}
$result->unsetData(ResultInterface::CARTQUOTE_PRODUCTS_SERIALIZED);
}

private function hadCart(AbstractModel $result): bool
{
return !empty($result->getOrigData(ResultInterface::CARTQUOTE_PRODUCTS))
|| !in_array(
$result->getOrigData(ResultInterface::CARTQUOTE_PRODUCTS_SERIALIZED),
[null, '', 'null', '[]'],
true
);
}
}
Method What it does
getSerializedColumns(): array Maps the data key that holds your array to the column that holds its JSON.
afterSerialize(DataObject $result): void Runs on save, after every column is encoded and before the row is written, inside the save's transaction. Use it to leave your column out of a save.

In the example, a submission without a cart leaves the column out of the save, so it stays NULL. A stored cart that was emptied on the model is saved as NULL.

How WebForms handles the column:

  • it encodes the array on save and decodes it on load, for one submission, a collection and the repository alike;
  • an empty column loads as [];
  • a data key that WebForms uses itself keeps WebForms' meaning.

Your other code works with the data key only: $result->setData('cartquote_products', $rows).

Check for submissions with your column set​

MageMe\WebForms\Api\SubmissionPresenceInterface::hasSubmissionWithColumnSet(int $formId, string $column): bool tells whether a form has at least one submission with a value in a column of the submission table. Usually that's a column your module added. It counts the submissions of that form only.

The Product Request add-on adds its product columns to a form's submission grid only when the form has product requests:

if (!$this->helper->getConfigIsEnabled()
|| !$this->submissionPresence->hasSubmissionWithColumnSet($formId, ResultInterface::PRODUCT_ID)) {
return;
}
$this->addProductId($columns); // … and the other product columns

What to keep in mind:

  • The column name must match ^[a-z][a-z0-9_]{0,63}$, or the call throws InvalidArgumentException.
  • An unknown column answers false and logs a warning.
  • It answers in cron, in the admin and in web API calls, limited to the forms the admin role may see. Anywhere else it answers false.
  • It's for PHP only: don't expose it through webapi.xml.

Erase your copy of personal data​

When an admin erases a customer's personal data, WebForms clears every copy of it that it knows. It does that one submission at a time, each in its own transaction. See Erase personal data.

If your module keeps its own copy of submission data, in a table with a result_id, add a step that clears it. Implement MageMe\WebForms\Model\Erasure\ErasureStepInterface and register the step in the global etc/di.xml.

The example comes from WebForms' own REST module, which is part of the WebForms platform, not an add-on. It clears staff replies queued through the API and expires unused download links:

<type name="MageMe\WebForms\Model\Erasure\PersonalDataErasure">
<arguments>
<argument name="steps" xsi:type="array">
<item name="api_copies" xsi:type="object">MageMe\WebFormsApi\Model\Erasure\ApiCopies</item>
</argument>
</arguments>
</type>
class ApiCopies implements ErasureStepInterface
{
public const TABLES = [OutboxResource::DB_TABLE, DownloadGrant::DB_TABLE];

public function erase(ErasureTarget $target): void
{
$target->count('api_replies_stopped', $this->outbox->moveStateByResult($target->resultId, ReplyOutbox::STATE_PENDING, ReplyOutbox::STATE_FAILED));
foreach ($this->outbox->fetchBodiesByResult($target->resultId) as $outboxId => $body) {
$this->outbox->updateById((int)$outboxId, [
OutboxResource::RECIPIENT_SNAPSHOT => ErasureTarget::LABEL,
OutboxResource::ATTACHMENTS_JSON => null,
OutboxResource::LAST_ERROR => null,
OutboxResource::BODY => $target->email !== '' ? str_ireplace($target->email, ErasureTarget::LABEL, $body) : $body,
]);
$target->count('api_replies');
}
$target->count('api_download_links', $this->downloadGrants->expireUnredeemedByResult($target->resultId, $this->clock->stamp()));
}
}
Part What it is
TABLES The tables the step clears.
erase(ErasureTarget $target): void Runs inside the submission's transaction, after the row is locked and marked erased.
$target Gives resultId, formId, email, personalFieldIds and names.
$target->scrub(string $text) Replaces the person's address and name in a text. Use it for free text: the example above replaces only the address.
ErasureTarget::LABEL The text [erased], which replaces the address and the name.
$target->count() Adds to the summary.
$target->afterCommit() Holds work that may run only after the commit, such as deleting files.

What's next​

Applies to WebForms 4Last reviewed December 2, 2026