Issue Bug Needs Feedback Quiet

#98241Missing SaveToDatabase options in EmailFinisher

Stefan Froemken 09/01/22, 11:54 updated 10/16/26, 18:39

Description

Hello form-team,

I have configured following finishers:

finishers:
  1:
    identifier: SaveEventFinisher
    options:
      1:
        table: tx_events2_domain_model_link
        mode: insert
        elements:
          youtube-link:
            mapOnDatabaseColumn: link
        databaseColumnMappings:
          pid:
            value: 8
          crdate:
            value: '{__currentTimestamp}'
          tstamp:
            value: '{__currentTimestamp}'
          title:
            value: 'YouTube Link'
      2:
        table: tx_events2_domain_model_link
        mode: insert
        elements:
          download-link:
            mapOnDatabaseColumn: link
        databaseColumnMappings:
          pid:
            value: 8
          crdate:
            value: '{__currentTimestamp}'
          tstamp:
            value: '{__currentTimestamp}'
          title:
            value: 'Download Link'
      3:
        table: tx_events2_domain_model_link
        mode: insert
        elements:
          ticket-link:
            mapOnDatabaseColumn: link
        databaseColumnMappings:
          pid:
            value: 8
          crdate:
            value: '{__currentTimestamp}'
          tstamp:
            value: '{__currentTimestamp}'
          title:
            value: 'Ticket Link'
      4:
        table: tx_events2_domain_model_event
        mode: insert
        elements:
          choose-event-type:
            mapOnDatabaseColumn: event_type
          title:
            mapOnDatabaseColumn: title
        databaseColumnMappings:
          pid:
            value: 8
          crdate:
            value: '{__currentTimestamp}'
          tstamp:
            value: '{__currentTimestamp}'
      5:
        table: sys_category_record_mm
        mode: insert
        elements:
          categories:
            mapOnDatabaseColumn: categories
        databaseColumnMappings:
          uid_foreign:
            value: '{SaveEvent.insertedUids.4}'
          tablenames:
            value: tx_events2_domain_model_event
          fieldname:
            value: categories
      6:
        table: tx_events2_event_organizer_mm
        mode: insert
        databaseColumnMappings:
          uid_local:
            value: '{SaveEvent.insertedUids.4}'
          organizers:
            value: '{__currentOrganizer}'
    ...a lot more...
  2:
    identifier: EmailToReceiver
    options:
      subject: 'Overwrite me with TS or lang file'
      useFluidEmail: 1
      # Following values are prefilled with the values from Extension Settings automatically (HOOK)
      # Activating following settings will deactivate the automatism.
      #recipients:
      #  change-me@example.com: 'Change or overwrite me'
      #senderAddress:
      #senderName:
  3:
    identifier: Redirect
    options:
      pageUid: 1

In FluidTemplate (Default.html) of EmailToReceiverFinisher I try to access the inserted UID of the option for table tx_events2_domain_model_event of the SaveEventFinisher (This is a slightly copy of original SaveToDatabaseFinisher). In “finisherVariableProvider” I see the correct value at position 4:

$insertedUids = [
    1 => 324,
    2 => 325,
    3 => 326,
    4 => 54952,
    5 => 537,
    6 => 14264,
    7 => 25636,
    8 => 0,
    9 => 0,
    10 => 0,
    11 => 0,
    12 => 0,
    13 => 0,
    14 => 0,
    15 => 0,
    16 => 0   
];

How do I programmatically know that position 4 is correct? I tried the following:

Debug SaveEventFinisher which is at position 0:

...::debug($formRuntime->getFormDefinition()->getFinishers()[0]);

It results in:

form => JWeiland\Events2\Domain\Finisher\SaveEventFinisherprototypeobject
      defaultOptions => protectedarray(1 item)
      databaseConnection => protectedTYPO3\CMS\Core\Database\Connectionprototypeobject
      pathSegmentHelper => protectedJWeiland\Events2\Helper\PathSegmentHelperprototypeobject
      objectManager => protectedTYPO3\CMS\Extbase\Object\ObjectManagersingletonobjectfiltered
      finisherIdentifier => protected'SaveEventFinisher' (17 chars)
      shortFinisherIdentifier => protected'SaveEvent' (9 chars)
      options => protectedarray(4 items)
         table => 'tx_events2_domain_model_time' (28 chars)
         mode => 'insert' (6 chars)
         elements => array(1 item)
         databaseColumnMappings => array(6 items)

As you see, just the last processed options are available in this finisher. So, without access to all available options I don’t know which insertedUID value I have to take care of.

Stefan

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[BUGFIX] Missing SaveToDatabase options in EmailFinisher Resolves: #98241 Releases: main

History 3

  1. Georg Ringer commented <span data-processor="relativetime" data-value="2025-04-20T14:17:28+00:00" > 04/20/25, 14:17 </span>

    what about adding the inserted row with

    $this->finisherContext->getFinisherVariableProvider()->add(
                'safeToDatabase',
                $table . '-' . $id,
                $data
            );

    wanna add this?

  2. Stefan Froemken commented <span data-processor="relativetime" data-value="2025-06-05T19:39:18+00:00" > 06/05/25, 19:39 </span>

    Hi Georg,

    for my extension I have added that information already since 3 years:
    https://github.com/jweiland-net/events2/blob/53c5fd1e0d8819e6a3bbe24e528223a68a961c21/Classes/Domain/Finisher/SaveEventFinisher.php#L130-L134

    EXT:form is a framework, and I expected to have access to results of all options of a finisher instead of just the last available option. IMO a framework should provide this information.

    But yes, your solution works since years

  3. Georg Ringer commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2026-10-16T18:39:25+00:00" > 10/16/26, 18:39 </span>

    Hi Stefan,

    The core SaveToDatabaseFinisher already exposes the inserted uid of every entry of its options array, not only the last one. Each entry is stored in the finisher variable provider under the numeric key you gave it in the configuration:

    {SaveToDatabase.insertedUids.<keyWithinOptions>}

    So for your configuration the uid of the event is {SaveToDatabase.insertedUids.4}, because you defined that entry as key 4. The key is known to the integrator, as it is part of the finisher configuration, so there is no need to inspect the finisher object (which only holds the options of the last run, as you noticed).

    This works in every later finisher, including the EmailFinisher. I added a functional test which uses {SaveToDatabase.insertedUids.4} and {SaveToDatabase.insertedUids.1} in the subject of the EmailFinisher and verifies that each placeholder resolves to the uid of its own entry. In a Fluid template the same values are available via the assigned finisherVariableProvider. The behaviour is documented in the SaveToDatabaseFinisher chapter of the form documentation.

    As your own finisher already adds the inserted rows to the variable provider, there is nothing left to change in the core. Therefore I would like to close this issue as “works as designed”.

    is this ok for you?