From bce28d5c3ea361a6904718a02f2d2cc0203105d9 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 16 Sep 2024 15:29:48 +0200 Subject: [PATCH 1/6] add deeplink option to file upload field --- UPGRADE.md | 3 ++ config/install/translations/admin.csv | 2 ++ config/types/type/dynamic_multi_file.yaml | 11 ++++++- docs/DynamicMultiFile/99_CustomAdapter.md | 9 +++--- .../Type/DynamicMultiFile/DropZoneType.php | 9 +++--- .../DynamicMultiFile/FineUploaderType.php | 9 +++--- src/Form/Type/DynamicMultiFileType.php | 11 ++++--- src/Migrations/Version20240916132702.php | 31 +++++++++++++++++++ .../Output/DynamicMultiFileTransformer.php | 12 +++++-- 9 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 src/Migrations/Version20240916132702.php diff --git a/UPGRADE.md b/UPGRADE.md index 30525bf0..868535e8 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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 diff --git a/config/install/translations/admin.csv b/config/install/translations/admin.csv index b7809188..37465472 100644 --- a/config/install/translations/admin.csv +++ b/config/install/translations/admin.csv @@ -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" diff --git a/config/types/type/dynamic_multi_file.yaml b/config/types/type/dynamic_multi_file.yaml index ea10ae52..eb7a6e82 100644 --- a/config/types/type/dynamic_multi_file.yaml +++ b/config/types/type/dynamic_multi_file.yaml @@ -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' \ No newline at end of file + 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' \ No newline at end of file diff --git a/docs/DynamicMultiFile/99_CustomAdapter.md b/docs/DynamicMultiFile/99_CustomAdapter.md index 41a7bf21..834413ba 100644 --- a/docs/DynamicMultiFile/99_CustomAdapter.md +++ b/docs/DynamicMultiFile/99_CustomAdapter.md @@ -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 ]); } diff --git a/src/Form/Type/DynamicMultiFile/DropZoneType.php b/src/Form/Type/DynamicMultiFile/DropZoneType.php index 76b3af67..f941e9cd 100644 --- a/src/Form/Type/DynamicMultiFile/DropZoneType.php +++ b/src/Form/Type/DynamicMultiFile/DropZoneType.php @@ -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, ]); } diff --git a/src/Form/Type/DynamicMultiFile/FineUploaderType.php b/src/Form/Type/DynamicMultiFile/FineUploaderType.php index 5f733c99..e433633c 100644 --- a/src/Form/Type/DynamicMultiFile/FineUploaderType.php +++ b/src/Form/Type/DynamicMultiFile/FineUploaderType.php @@ -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, ]); } diff --git a/src/Form/Type/DynamicMultiFileType.php b/src/Form/Type/DynamicMultiFileType.php index 1c3bfcb8..57affa7e 100644 --- a/src/Form/Type/DynamicMultiFileType.php +++ b/src/Form/Type/DynamicMultiFileType.php @@ -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, ]); } diff --git a/src/Migrations/Version20240916132702.php b/src/Migrations/Version20240916132702.php new file mode 100644 index 00000000..1c14d395 --- /dev/null +++ b/src/Migrations/Version20240916132702.php @@ -0,0 +1,31 @@ +container->get(Install::class); + $installer->updateTranslations(); + } + + public function down(Schema $schema): void + { + } +} diff --git a/src/Transformer/Output/DynamicMultiFileTransformer.php b/src/Transformer/Output/DynamicMultiFileTransformer.php index cf9d5f3b..5e7cc197 100644 --- a/src/Transformer/Output/DynamicMultiFileTransformer.php +++ b/src/Transformer/Output/DynamicMultiFileTransformer.php @@ -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 ) { @@ -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; From 21c43bd24c2db398682d3109dc645150a958ab94 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 16 Sep 2024 15:31:29 +0200 Subject: [PATCH 2/6] upgrade actions/upload-artifact@v4 --- .github/workflows/codeception.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index 64e2ac7b..5cad47d9 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -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 }})" From 2625d0674cbd259becaf0f28c3e1c8aff98691f7 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 16 Sep 2024 15:44:51 +0200 Subject: [PATCH 3/6] remove non nullable check --- src/OutputWorkflow/Channel/Email/Parser/MailParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OutputWorkflow/Channel/Email/Parser/MailParser.php b/src/OutputWorkflow/Channel/Email/Parser/MailParser.php index 219f6ad4..a554587e 100644 --- a/src/OutputWorkflow/Channel/Email/Parser/MailParser.php +++ b/src/OutputWorkflow/Channel/Email/Parser/MailParser.php @@ -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; } @@ -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; } From 7fc85bf1a66bc66a4c09a493a72a99a790ea9162 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 16 Sep 2024 16:02:40 +0200 Subject: [PATCH 4/6] update test steps --- .github/workflows/codeception.yml | 4 ++-- .github/workflows/ecs.yml | 4 ++-- .github/workflows/php-stan.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index 5cad47d9..cd254738 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -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 @@ -111,7 +111,7 @@ jobs: echo "::set-output name=dir::$(composer config cache-files-dir)" - 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') }} diff --git a/.github/workflows/ecs.yml b/.github/workflows/ecs.yml index 5403b5f7..da562b5f 100644 --- a/.github/workflows/ecs.yml +++ b/.github/workflows/ecs.yml @@ -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 @@ -91,7 +91,7 @@ jobs: echo "::set-output name=dir::$(composer config cache-files-dir)" - 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') }} diff --git a/.github/workflows/php-stan.yml b/.github/workflows/php-stan.yml index 4bfaf245..bb88e94a 100644 --- a/.github/workflows/php-stan.yml +++ b/.github/workflows/php-stan.yml @@ -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 @@ -91,7 +91,7 @@ jobs: echo "::set-output name=dir::$(composer config cache-files-dir)" - 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') }} From d72d2c6163d71547b23536d8ef60c43327024851 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 16 Sep 2024 16:23:36 +0200 Subject: [PATCH 5/6] add chrome options, remove deprecations --- .github/workflows/codeception.yml | 2 +- .github/workflows/ecs.yml | 2 +- .github/workflows/php-stan.yml | 2 +- tests/_envs/github.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index cd254738..83554dec 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -108,7 +108,7 @@ 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@v4 diff --git a/.github/workflows/ecs.yml b/.github/workflows/ecs.yml index da562b5f..05f47f2c 100644 --- a/.github/workflows/ecs.yml +++ b/.github/workflows/ecs.yml @@ -88,7 +88,7 @@ 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@v4 diff --git a/.github/workflows/php-stan.yml b/.github/workflows/php-stan.yml index bb88e94a..6f42d8e3 100644 --- a/.github/workflows/php-stan.yml +++ b/.github/workflows/php-stan.yml @@ -88,7 +88,7 @@ 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@v4 diff --git a/tests/_envs/github.yml b/tests/_envs/github.yml index 0cd67170..1ef88e0f 100644 --- a/tests/_envs/github.yml +++ b/tests/_envs/github.yml @@ -7,6 +7,6 @@ modules: wait: 1 capabilities: 'goog:chromeOptions': - args: ['--no-sandbox', '--disable-extensions', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--window-size=1280,1024'] + args: ['--no-sandbox', '--disable-extensions', '--disable-search-engine-choice-screen', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--window-size=1280,1024'] prefs: download.default_directory: '%TEST_BUNDLE_TEST_DIR%/_data/downloads' \ No newline at end of file From b45e6c1501e31d95e89a6ff1e01e8bb6ebeca826 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 16 Sep 2024 16:42:07 +0200 Subject: [PATCH 6/6] remove chrome option --- tests/_envs/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_envs/github.yml b/tests/_envs/github.yml index 1ef88e0f..0cd67170 100644 --- a/tests/_envs/github.yml +++ b/tests/_envs/github.yml @@ -7,6 +7,6 @@ modules: wait: 1 capabilities: 'goog:chromeOptions': - args: ['--no-sandbox', '--disable-extensions', '--disable-search-engine-choice-screen', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--window-size=1280,1024'] + args: ['--no-sandbox', '--disable-extensions', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--window-size=1280,1024'] prefs: download.default_directory: '%TEST_BUNDLE_TEST_DIR%/_data/downloads' \ No newline at end of file