Skip to content

Commit

Permalink
Added FormConfigStamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Oct 14, 2024
1 parent dce6aa4 commit 2113e27
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/listeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
->args([
service(NotificationCenter::class),
service(FileUploadNormalizer::class),
service(ConfigLoader::class),
])
;

Expand Down
5 changes: 5 additions & 0 deletions src/Config/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function loadModule(int $id): ModuleConfig|null
return $this->loadConfig($id, 'tl_module', ModuleConfig::class);
}

public function loadForm(int $id): FormConfig|null
{
return $this->loadConfig($id, 'tl_form', FormConfig::class);
}

/**
* @return array<MessageConfig>
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Config/FormConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Terminal42\NotificationCenterBundle\Config;

class FormConfig extends AbstractConfig
{
}
9 changes: 9 additions & 0 deletions src/EventListener/ProcessFormDataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
use Contao\Form;
use Contao\StringUtil;
use Terminal42\NotificationCenterBundle\BulkyItem\FileItem;
use Terminal42\NotificationCenterBundle\Config\ConfigLoader;
use Terminal42\NotificationCenterBundle\NotificationCenter;
use Terminal42\NotificationCenterBundle\Parcel\Stamp\BulkyItemsStamp;
use Terminal42\NotificationCenterBundle\Parcel\Stamp\FormConfigStamp;

#[AsHook('processFormData')]
class ProcessFormDataListener
{
public function __construct(
private readonly NotificationCenter $notificationCenter,
private readonly FileUploadNormalizer $fileUploadNormalizer,
private readonly ConfigLoader $configLoader,
) {
}

Expand Down Expand Up @@ -95,6 +98,12 @@ public function __invoke(array $submittedData, array $formData, array|null $file
$stamps = $stamps->with(new BulkyItemsStamp($bulkyItemVouchers));
}

$formConfig = $this->configLoader->loadForm((int) $form->id);

if (null !== $formConfig) {
$stamps = $stamps->with(new FormConfigStamp($formConfig));
}

$this->notificationCenter->sendNotificationWithStamps((int) $formData['nc_notification'], $stamps);
}
}
20 changes: 20 additions & 0 deletions src/Parcel/Stamp/FormConfigStamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Terminal42\NotificationCenterBundle\Parcel\Stamp;

use Terminal42\NotificationCenterBundle\Config\FormConfig;

class FormConfigStamp extends AbstractConfigStamp
{
public function __construct(public FormConfig $formConfig)
{
parent::__construct($this->formConfig);
}

public static function fromArray(array $data): self
{
return new self(FormConfig::fromArray($data));
}
}

0 comments on commit 2113e27

Please sign in to comment.