terminal42 / contao-notification_center

The most popular notification configuration extension for the Contao Open Source CMS!
63 stars 38 forks source link

Multiple conditional attachments via tokens #259

Closed Shoekrates closed 1 year ago

Shoekrates commented 2 years ago

It seems that it is not possible to add multiple attachments if they are conditional.

Our client has two locations where customers are being served. I have a form that asks via radio button for the preferred location. After submitting the form the customer should get an email with four pdf file attachments dependant to the chosen location e.g. for location A: location_a_1.pdf, location_a_2.pdf, location_a_3.pdf, location_a_4.pdf for location B: location_b_1.pdf, location_b_2.pdf, location_b_3.pdf, location_b_4.pdf

With an if else condition I can only add one file at a time. This works: {if form_standort=='location_a'} {{file::f1d87570-b9ab-11ec-97d3-6a9b680e1f17}} {elseif form_standort=='location_b'} {{file::071f9da1-b9ac-11ec-97d3-6a9b680e1f17}} {endif}

If I add this condition with multiple files separated with a comma, I run into „Error parsing simple tokens“ (/var/log). That does not work: {if form_standort=='location_a'} {{file::f1d87570-b9ab-11ec-97d3-6a9b680eXXXX}},{{file::071f9da1-b9ac-11ec-97d3-6a9b680eXXXX}},{{file::f1d87570-b9ab-11ec-97d3-6a9b680XXXX}},{{file::071f9da1-b9ac-11ec-97d3-6a9b680eXXXX}} {elseif form_standort=='location_b'} {{file::f1d87570-b9ab-11ec-97d3-6a9b680eXXXX}},{{file::071f9da1-b9ac-11ec-97d3-6a9b680eXXXX}},{{file::f1d87570-b9ab-11ec-97d3-6a9b680XXXX}},{{file::071f9da1-b9ac-11ec-97d3-6a9b680eXXXX}} {endif}

If I add multiple files without condition it works again: {{file::f1d87570-b9ab-11ec-97d3-6a9b680eXXXX}},{{file::071f9da1-b9ac-11ec-97d3-6a9b680eXXXX}},{{file::f1d87570-b9ab-11ec-97d3-6a9b680XXXX}},{{file::071f9da1-b9ac-11ec-97d3-6a9b680eXXXX}}

I even added hidden fields to the form with the file-insert tags as values to add the fields like this: This works: ##form_gm_1##,##form_gm_2##,##form_gm_3##,##form_gm_4

But with condition it doesn't work: {if form_standort=='location_a'}##form_gm_1##,##form_gm_2##,##form_gm_3##,##form_gm_4##{elseif form_standort=='location_b'}##form_si_1##,##form_si_2##,##form_si_3##,##form_si_4##{endif}

Another problem that I ran into: the database field for file attachements is VARCHAR(255). The conditional string was too long for the field, so I changed the field to VARCHAR(1000) via DCA: $GLOBALS['TL_DCA']['tl_nc_language']['fields']['attachment_tokens']['sql'] = "varchar(1028) NOT NULL default ''"; Maybe this is something general to change in future releases?

Any ideas if this could work and how? And no, a single ZIP-File as attachement is no option ;)

aschempp commented 2 years ago

what does does not work mean to you? Also, increasing the field can easily and update-safely be done through a local DCA adjustment, so I would think that should be a local optimization.

Shoekrates commented 2 years ago

Hi Andreas, sorry, I somehow forgot to add the exact error message from var/log: [2022-04-11 19:36:19] request.CRITICAL: Uncaught PHP Exception Exception: "Error parsing simple tokens" at /var/www/vhosts/xxxxxxxxxxx/xxxxxxxx/vendor/contao/core-bundle/src/Resources/contao/library/Contao/StringUtil.php line 732 {"exception":"[object] (Exception(code: 0): Error parsing simple tokens at /var/www/vhosts/xxxxxxxxxxxxx/xxxxxxxx/vendor/contao/core-bundle/src/Resources/contao/library/Contao/StringUtil.php:732)"} [] This error appears if I add the if-condition to the attachment-field in combination with multiple files as mentioned above.

Contao 4.9.28 PHP 7.4.28 NC 1.6.8 (I just found that there is a new version 1.6.9 from last week)

I already added the DCA adjustment as I ran into the field limit, so local optimization is okay for me. I thought it would be something valuable to mention here.