Skip to content

Commit

Permalink
add deeplink option to file upload field (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat authored Sep 16, 2024
1 parent 738fef3 commit 3ac08df
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- pimcore: ~11.2.0
template_tag: v11.0.0
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
path: lib/test-bundle

Expand Down Expand Up @@ -108,10 +108,10 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer Downloads
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -136,7 +136,7 @@ jobs:
vendor/bin/codecept run --env github -c ${{ github.workspace }}/lib/test-bundle
- name: Log Output
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: "Logs (PHP ${{ matrix.php }}, Pimcore ${{ matrix.pimcore }}, Symfony ${{ matrix.symfony }})"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- pimcore: ~11.2.0
template_tag: v11.0.0
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
path: lib/test-bundle

Expand Down Expand Up @@ -88,10 +88,10 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer Downloads
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/php-stan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- pimcore: ~11.2.0
template_tag: v11.0.0
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
path: lib/test-bundle

Expand Down Expand Up @@ -88,10 +88,10 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer Downloads
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Upgrade Notes

## 5.1.1
- **[IMPROVEMENT]** [File Upload] Add Deeplink Option to file upload field [#475](https://github.com/dachcom-digital/pimcore-formbuilder/issues/475)

## 5.1.1
- **[BUGFIX]** Fix Migration and Installer

Expand Down
2 changes: 2 additions & 0 deletions config/install/translations/admin.csv
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
"form_builder_type_field.max_file_size_desc","Max file size will be calculated in MB. Empty or Zero means no Limit!","Maximale Dateigröße wird in MB verarbeitet. Leer oder 0 bedeutet kein Limit!"
"form_builder_type_field.submit_as_attachment","Send Files as Attachment","Daten als Anhang versenden"
"form_builder_type_field.submit_as_attachment_desc","All Files will be stored in your pimcore asset structure (/formdata) by default. If you check this option, the files will be attached to the mail instead of adding a download link.","Daten werden stets im Asset-Verzeichnis (/formdata) abgelegt und via Link im Mail versendet. Ist diese Option aktiviert, werden die Daten als Anhang versendet."
"form_builder_type_field.submit_as_admin_deep_link","Send Links as Admin Deeplink","Links als Admin-Deeplink versenden"
"form_builder_type_field.submit_as_admin_deep_link_desc","Generate admin deeplink to attachment asset instead of frontend asset links.","Admin-Deeplink zum Asset anstelle eines Frontend-Asset-Links erstellen."
"form_builder_type_field.date_seconds","Seconds","Sekunden"
"form_builder_type_field.date_minutes","Minutes","Minuten"
"form_builder_type_field.date_hours","Hours","Stunden"
Expand Down
11 changes: 10 additions & 1 deletion config/types/type/dynamic_multi_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ form_builder:
options.submit_as_attachment_label:
display_group_id: attributes
type: label
label: 'form_builder_type_field.submit_as_attachment_desc'
label: 'form_builder_type_field.submit_as_attachment_desc'
options.submit_as_admin_deep_link:
display_group_id: attributes
type: checkbox
label: 'form_builder_type_field.submit_as_admin_deep_link'
config: ~
options.submit_as_admin_deep_link_label:
display_group_id: attributes
type: label
label: 'form_builder_type_field.submit_as_admin_deep_link_desc'
9 changes: 5 additions & 4 deletions docs/DynamicMultiFile/99_CustomAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ class MyUploaderType extends AbstractType
// these options are required to support!

$resolver->setDefaults([
'max_file_size' => null,
'allowed_extensions' => [],
'item_limit' => null,
'submit_as_attachment' => false
'max_file_size' => null,
'allowed_extensions' => [],
'item_limit' => null,
'submit_as_attachment' => false,
'submit_as_admin_deep_link' => false
]);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Form/Type/DynamicMultiFile/DropZoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public function buildView(FormView $view, FormInterface $form, array $options):
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'max_file_size' => null,
'allowed_extensions' => [],
'item_limit' => null,
'submit_as_attachment' => false
'max_file_size' => null,
'allowed_extensions' => [],
'item_limit' => null,
'submit_as_attachment' => false,
'submit_as_admin_deep_link' => false,
]);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Form/Type/DynamicMultiFile/FineUploaderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public function buildView(FormView $view, FormInterface $form, array $options):
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'max_file_size' => 0,
'allowed_extensions' => [],
'item_limit' => 0,
'submit_as_attachment' => false
'max_file_size' => 0,
'allowed_extensions' => [],
'item_limit' => 0,
'submit_as_attachment' => false,
'submit_as_admin_deep_link' => false,
]);
}

Expand Down
11 changes: 6 additions & 5 deletions src/Form/Type/DynamicMultiFileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public function __construct(
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'compound' => true,
'max_file_size' => 0,
'allowed_extensions' => [],
'item_limit' => 0,
'submit_as_attachment' => false
'compound' => true,
'max_file_size' => 0,
'allowed_extensions' => [],
'item_limit' => 0,
'submit_as_attachment' => false,
'submit_as_admin_deep_link' => false,
]);
}

Expand Down
31 changes: 31 additions & 0 deletions src/Migrations/Version20240916132702.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace FormBuilderBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use FormBuilderBundle\Tool\Install;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

final class Version20240916132702 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;

public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$installer = $this->container->get(Install::class);
$installer->updateTranslations();
}

public function down(Schema $schema): void
{
}
}
4 changes: 2 additions & 2 deletions src/OutputWorkflow/Channel/Email/Parser/MailParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function parseSubject(Email $mailTemplate, array $fieldValues = []): v

preg_match_all('/\%(.+?)\%/', $realSubject, $matches);

if (!isset($matches[1]) || count($matches[1]) === 0) {
if (count($matches[1]) === 0) {
return;
}

Expand Down Expand Up @@ -164,7 +164,7 @@ protected function extractPlaceHolder(string $str, array $fieldValues): mixed

preg_match_all('/\%(.+?)\%/', $str, $matches);

if (!isset($matches[1]) || count($matches[1]) === 0) {
if (count($matches[1]) === 0) {
return $str;
}

Expand Down
12 changes: 10 additions & 2 deletions src/Transformer/Output/DynamicMultiFileTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
use Pimcore\Model\Asset;
use FormBuilderBundle\Model\FormFieldDefinitionInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class DynamicMultiFileTransformer implements OutputTransformerInterface
{
public function __construct(
protected RouterInterface $router,
protected TranslatorInterface $translator,
protected AttachmentStreamInterface $attachmentStream
) {
Expand Down Expand Up @@ -44,13 +46,19 @@ public function getValue(FieldDefinitionInterface $fieldDefinition, FormInterfac
$asset = $this->attachmentStream->createAttachmentAsset($attachmentData, $fieldDefinition->getName(), $rootFormData->getFormDefinition()->getName());

if ($asset instanceof Asset) {
$path = $asset->getFrontendFullPath();

$hostUrl = \Pimcore\Tool::getHostUrl();

if (isset($options['submit_as_admin_deep_link']) && $options['submit_as_admin_deep_link'] === true) {
return sprintf('%s%s?%s_%d_%s', $hostUrl, $this->router->generate('pimcore_admin_login_deeplink'), 'asset', $asset->getId(), $asset->getType());
}

$path = $asset->getFrontendFullPath();
if (str_starts_with($path, 'http')) {
return $path;
}

return sprintf('%s%s', \Pimcore\Tool::getHostUrl(), $asset->getRealFullPath());
return sprintf('%s%s', $hostUrl, $asset->getRealFullPath());
}

return null;
Expand Down

0 comments on commit 3ac08df

Please sign in to comment.