DigiComp.AttachmentViewUtility/README.md

59 lines
1.6 KiB
Markdown
Raw Normal View History

2023-10-17 18:49:19 +02:00
# DigiComp.AttachmentViewUtility
This package helps with recurring tasks of creating views for `neos/flow` projects.
It delivers two traits:
1. `AttachmentViewTrait` creates views which returns downloadable resources
2. `EelFilenameTrait` allows to set the filename with an eel expression, which got the view variables as context
They can be used together or standalone - but the filename trait does not make sense, if your view is not delivered by attachment.
The `EelContext` contains the `String`, `Array` and `Translation` - Helpers. If you need more, you can connect to the `YourView::filenameEelExpressionContext` signal, which gets the context as argument. That way you can extend the context with whatever you need.
## Example
SimpleAttachmentView.php:
```php
class SimpleAttachmentView extends AbstractView
{
use AttachmentViewTrait;
use EelFilenameTrait;
public function __construct(array $options = [])
{
$this->addOptionFilenameEelExpression();
$this->addOptionsForAttachment();
parent::__construct($options);
}
protected function getAttachmentContent()
{
return 'Hello ' . $this->variables['name'];
}
protected function getAttachmentMimeType(): string
{
return 'text/plain';
}
}
```
Controller:
```php
class DefaultController extends ActionController {
public function downloadAction()
{
$this->view->assign('name', 'World');
}
}
```
Views.yaml:
```yaml
-
requestFilter: "isController('Default') && isAction('download')"
viewObjectName: "Acme\\Vendor\\SimpleAttachmentView"
options:
2023-11-09 16:32:28 +01:00
filenameEelExpression: "'hello-' + name + '.txt'"
2023-10-17 18:49:19 +02:00
```