PHP code example of wwwision / neos-submissions

1. Go to this page and download the library: Download wwwision/neos-submissions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wwwision / neos-submissions example snippets




declare(strict_types=1);

namespace Some\Package\Submissions;

use Wwwision\Neos\Submissions\LabelGenerator\SubmissionLabelGenerator\SubmissionLabelGenerator;
use Wwwision\Neos\Submissions\LabelGenerator\SubmissionLabelGenerator\SubmissionLabelGeneratorFactory;
use Wwwision\Neos\Submissions\Model\Submission\SubmissionData;
use Wwwision\Neos\Submissions\Model\Submission\SubmissionId;
use Wwwision\Neos\Submissions\Model\Submission\SubmissionLabel;

final readonly class OrderNumberLabelGeneratorFactory implements SubmissionLabelGeneratorFactory
{
    public function create(array $options): SubmissionLabelGenerator
    {
        return new class ($options['prefix'] ?? 'ORDER-') implements SubmissionLabelGenerator {
            public function __construct(private readonly string $prefix) {}

            public function generate(SubmissionId $submissionId, SubmissionData $data): SubmissionLabel
            {
                return SubmissionLabel::fromString($this->prefix . substr($submissionId->value, 0, 8));
            }
        };
    }
}

use Wwwision\Neos\Submissions\Command\AddSubmission;
use Wwwision\Neos\Submissions\Factory\FormSubmissionServiceFactory;
use Wwwision\Neos\Submissions\Model\Preset\PresetId;
use Wwwision\Neos\Submissions\Model\Submission\SubmissionId;

// e.g. in a service or command controller with an injected $formSubmissionServiceFactory:
$service = $this->formSubmissionServiceFactory->create(PresetId::fromString('contact'));
$service->handleAddSubmission(AddSubmission::create(
    submissionId: SubmissionId::generate(),
    formId: 'legacy-contact-form',
    data: ['givenName' => 'John', 'familyName' => 'Doe', 'emailAddress' => '[email protected]'],
));