Skip to content

Commit

Permalink
Merge pull request #29 from visol-forks/feature/fusion-form-action
Browse files Browse the repository at this point in the history
FEATURE: Add action for Neos Fusion Forms
  • Loading branch information
Benjamin-K authored Apr 12, 2022
2 parents 3a715f8 + 6fb6dae commit d4c7c6a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
50 changes: 50 additions & 0 deletions Classes/FusionForm/Runtime/Action/DatabaseStorageAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Wegmeister\DatabaseStorage\FusionForm\Runtime\Action;

/**
* The Fusion form action for the database storage.
*
* This file is part of the Flow Framework Package "Wegmeister.DatabaseStorage".
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Fusion\Form\Runtime\Action\AbstractAction;
use Neos\Fusion\Form\Runtime\Domain\Exception\ActionException;
use Wegmeister\DatabaseStorage\Domain\Model\DatabaseStorage;
use Wegmeister\DatabaseStorage\Domain\Repository\DatabaseStorageRepository;

class DatabaseStorageAction extends AbstractAction
{

/**
* @Flow\Inject
* @var DatabaseStorageRepository
*/
protected $databaseStorageRepository;

/**
* @return ActionResponse|null
* @throws ActionException
*/
public function perform(): ?ActionResponse
{
$identifier = $this->options['identifier'];
$formValues = $this->options['formValues'];

if (!$identifier) {
$identifier = '__undefined__';
}

$dbStorage = new DatabaseStorage();
$dbStorage->setStorageidentifier($identifier)->setProperties($formValues)->setDateTime(new \DateTime());

$this->databaseStorageRepository->add($dbStorage);

return null;
}

}
28 changes: 20 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Wegmeister.DatabaseStorage

This package adds the ability to store values of a form (or other input) into database and export the stored data as xlsx, xls, ods, csv or html.
This package adds the ability to store form submissions into a database and export the stored data as xlsx, xls, ods, csv or html.

## Installation

Expand All @@ -12,12 +12,12 @@ composer require wegmeister/databasestorage

## Usage

> :exclamation: The DatabaseStorage stores your data as JSON. Therefore only the Labels of the first entry can be used for the headline/export. Keep that in mind and try to avoid changing your forms later on. Whenever you add a now field **after** someone already entered some data, the new field would not exist in the headline row of the exported table :exclamation:
> :exclamation: The DatabaseStorage stores your data as JSON. Therefore only the labels of the first entry can be used for the headline/export. Keep that in mind and try to avoid changing your forms later on. Whenever you add a field **after** someone already entered some data, the new field would not exist in the headline row of the exported table :exclamation:
You can add the DatabaseStorage Finisher in two ways:
You can add the DatabaseStorage Finisher in the following ways:


### Add DatabaseStorage using yaml definitions
### Add DatabaseStorage using YAML definitions

Add the DatabaseStorage a finisher in your form definition/yaml file:

Expand All @@ -37,14 +37,26 @@ finishers:
identifier: 'my-form-data'
```
### Add DatabaseStorage using the Neos Form Builder
### Add DatabaseStorage using the new Neos Form-Builder
You can also use the DatabaseStorage with the [Neos.Form.Builder](https://github.com/neos/form-builder).
You should be able to simply add DatabaseStorage as a finisher to your form.
You can also use the DatabseStorage with the new [Neos.Form.Builder](https://github.com/neos/form-builder).
You should be able to simply add DatabaseStorage as a finisher to your formular.
Don't forget to set a (unique) `identifier`!

Don't forget to set an (unique) `identifier`!
### Add DatabaseStorage using a Fusion Form

You can also use the DatabaseStorage [Neos.Fusion.Form](https://github.com/neos/fusion-form) action.

Add the following configuration to your form action definition:

databaseStorage {
type = '\\Wegmeister\\DatabaseStorage\\FusionForm\\Runtime\\Action\\DatabaseStorageAction'
options {
identifier = 'identifier-in-backend'
formValues = ${data}
}
}

## Available settings

Expand Down

0 comments on commit d4c7c6a

Please sign in to comment.