No description
Find a file
Ferdinand Kuhl d2b5792001
Some checks failed
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/2 Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline failed
ci/woodpecker/push/functional-tests/3 Pipeline was successful
enabling installation in flow 6
2024-07-19 11:08:58 +02:00
.woodpecker enabling installation in flow 6 2024-07-19 11:08:58 +02:00
Classes fixing code style issue 2023-11-09 16:33:20 +01:00
Tests/Functional Initial version 2023-10-17 22:52:28 +02:00
composer.json enabling installation in flow 6 2024-07-19 11:08:58 +02:00
README.md fixing a syntax error in code example 2023-11-09 16:32:28 +01: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'"