No description
Find a file
2023-11-09 16:32:15 +01:00
.woodpecker Initial version 2023-10-17 22:52:28 +02:00
Classes allow trait consumers to use the prepared eel evaluator 2023-11-09 16:32:15 +01:00
Tests/Functional Initial version 2023-10-17 22:52:28 +02:00
composer.json Initial version 2023-10-17 22:52:28 +02:00
README.md Initial version 2023-10-17 22:52:28 +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:

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"