No description
.woodpecker | ||
Classes | ||
Tests/Functional | ||
composer.json | ||
README.md |
DigiComp.AttachmentViewUtility
This package helps with recurring tasks of creating views for neos/flow
projects.
It delivers two traits:
AttachmentViewTrait
creates views which returns downloadable resourcesEelFilenameTrait
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:
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:
class DefaultController extends ActionController {
public function downloadAction()
{
$this->view->assign('name', 'World');
}
}
Views.yaml:
-
requestFilter: "isController('Default') && isAction('download')"
viewObjectName: "Acme\\Vendor\\SimpleAttachmentView"
options:
filenameEelExpression: "'hello-' + name + '.txt'"