From 6ba15ccbbf6c9cabf8da1887d044088b89ed878f Mon Sep 17 00:00:00 2001 From: e-spin Date: Wed, 17 May 2023 16:04:34 +0200 Subject: [PATCH 1/7] Fix composer for phpsq --- .composer-require-checker.json | 10 +++++ .github/workflows/diagnostics.yml | 69 +++++++++++++++++++++---------- .phpcq.lock | 1 + build.xml | 12 ------ composer.json | 21 +++++----- psalm.xml | 15 +++++++ 6 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 .composer-require-checker.json create mode 100644 .phpcq.lock delete mode 100644 build.xml create mode 100644 psalm.xml diff --git a/.composer-require-checker.json b/.composer-require-checker.json new file mode 100644 index 0000000..4887b86 --- /dev/null +++ b/.composer-require-checker.json @@ -0,0 +1,10 @@ +{ + "symbol-whitelist": [ + "array", "bool", "false", "int", "null", "self", "static", "parent", "string", "true", "void", + "ampersand", "array_insert", "array_is_assoc", "nl2br_html5", "TL_ERROR", + "Contao\\ManagerBundle\\ContaoManagerBundle", + "Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface", + "Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig", + "Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface" + ] +} diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml index 78e3812..bddb943 100644 --- a/.github/workflows/diagnostics.yml +++ b/.github/workflows/diagnostics.yml @@ -1,50 +1,75 @@ -name: DC General Contao Frontend +name: Code Quality Diagnostics on: - push: pull_request: + push: + branches: jobs: build: runs-on: ubuntu-latest + name: 'PHP: ${{ matrix.php }} Contao: ${{ matrix.contao }}' strategy: + fail-fast: false matrix: - php: [8.1] - contao: [~4.13.0] + php: [ '8.1', '8.2' ] + contao: [ '~4.13.0' ] + phpcq_install: [ 'update' ] + output: [ '-o github-action -o default' ] steps: - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Pull source - uses: actions/checkout@v2 - with: - fetch-depth: 0 + - name: Pull source + uses: actions/checkout@v3 - # see https://github.com/shivammathur/setup-php - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Setup PHP. + - name: Setup PHP with PECL extension uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - coverage: none - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache composer cache directory - uses: actions/cache@v1 + # setup caches + - name: Cache composer cache directory + uses: actions/cache@v3 env: cache-name: composer-cache-dir with: path: ~/.cache/composer - key: ${{ runner.os }}-build-${{ env.cache-name }} + key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }} - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache vendor directory + - name: Cache vendor directory uses: actions/cache@v3 env: - cache-name: composer-vendor + cache-name: vendor with: path: vendor - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}- - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Install composer dependencies - run: composer update --prefer-dist --no-interaction --no-suggest + - name: Cache phpcq directory + uses: actions/cache@v3 + env: + cache-name: phpcq + with: + path: .phpcq + key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/.phpcq.lock') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}- + + # install dependencies and tools + - name: Install composer dependencies + run: | + composer require contao/core-bundle ${{ matrix.contao }} --no-update + composer install + - name: Install phpcq toolchain + run: ./vendor/bin/phpcq ${{ matrix.phpcq_install }} -v - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Run tests - run: ant -keep-going + # run tests + - name: Run tests + run: ./vendor/bin/phpcq run -v ${{ matrix.output }} + + - name: Upload build directory to artifact + uses: actions/upload-artifact@v3 + if: ${{ success() }} || ${{ failure() }} + with: + name: phpcq-builds-php-${{ matrix.php }}-${{ matrix.contao }} + path: .phpcq/build/ diff --git a/.phpcq.lock b/.phpcq.lock new file mode 100644 index 0000000..21bdc05 --- /dev/null +++ b/.phpcq.lock @@ -0,0 +1 @@ +{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.5.26","url":"https://phar.phpunit.de/phpunit-9.5.26.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"e36595f47bb81f244e03fc437328cfaa123e99ffd183c3217235926ff0978397"},"signature":"https://phar.phpunit.de/phpunit-9.5.26.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/psalm-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"4.29.0","url":"https://github.com/vimeo/psalm/releases/download/4.29.0/psalm.phar","requirements":{"php":{"php":"^7.1|^8","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/4.29.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.13.0","url":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.7.1","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar.asc"},"phpcbf":{"version":"3.7.1","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.28.3","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.28.3/composer-normalize.phar","requirements":{"php":{"php":"^7.4 || ^8.0"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.28.3/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/build.xml b/build.xml deleted file mode 100644 index 6c03cfd..0000000 --- a/build.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/composer.json b/composer.json index d6d7eb2..02d550c 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "source":"https://github.com/contao-community-alliance/dc-general-contao-frontend" }, "require": { - "php": "^8.0", + "php": "^8.1", "contao-community-alliance/dc-general": "^2.3@dev", "contao-community-alliance/url-builder": "~1.3", "contao-community-alliance/translator": "^2.3", @@ -34,7 +34,8 @@ "symfony/event-dispatcher": "^5.4" }, "require-dev": { - "contao/manager-plugin": "^2.8", + "roave/security-advisories": "dev-latest", + "contao/manager-bundle": "^4.13.0 <5.0", "phpcq/runner-bootstrap": "^1.0@dev" }, "autoload": { @@ -42,18 +43,18 @@ "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\": "src" } }, + "config": { + "allow-plugins": { + "contao-components/installer": false, + "ocramius/package-versions": false, + "contao/manager-plugin": false, + "php-http/discovery": true + } + }, "extra":{ "contao-manager-plugin": "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\ContaoManager\\Plugin", "branch-alias": { "dev-feature/2.3.0": "2.3.x-dev" } - }, - "config": { - "allow-plugins": { - "contao-components/installer": false, - "ocramius/package-versions": false, - "contao/manager-plugin": false - }, - "sort-packages": true } } diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..9dd9aef --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file From 0a16373f898aa85996f5798ead5720324c43b49e Mon Sep 17 00:00:00 2001 From: e-spin Date: Wed, 17 May 2023 16:04:34 +0200 Subject: [PATCH 2/7] Fix composer for phpsq --- .composer-require-checker.json | 20 ++++++ .github/workflows/diagnostics.yml | 69 +++++++++++++------ .phpcq.lock | 1 + build.xml | 12 ---- composer.json | 68 +++++++++--------- psalm.xml | 15 ++++ src/CcaDcGeneralContaoFrontendBundle.php | 6 +- .../CcaDcGeneralContaoFrontendExtension.php | 6 +- src/Event/DcGeneralFrontendEvents.php | 9 +-- src/Listener/HandleSubmitListener.php | 6 +- src/View/ActionHandler/CopyHandler.php | 6 +- src/View/DefaultWidgetBuilder.php | 15 ++-- src/View/EditMask.php | 20 ++++-- src/View/WidgetManager.php | 9 ++- src/Widgets/UploadOnSteroids.php | 42 ++++++----- 15 files changed, 189 insertions(+), 115 deletions(-) create mode 100644 .composer-require-checker.json create mode 100644 .phpcq.lock delete mode 100644 build.xml create mode 100644 psalm.xml diff --git a/.composer-require-checker.json b/.composer-require-checker.json new file mode 100644 index 0000000..481d373 --- /dev/null +++ b/.composer-require-checker.json @@ -0,0 +1,20 @@ +{ + "symbol-whitelist": [ + "array", "bool", "false", "int", "null", "self", "static", "parent", "string", "true", "void", + "ampersand", "array_insert", "array_is_assoc", "nl2br_html5", "TL_ERROR", + "BackendTemplate", + "ContaoCommunityAlliance\\Contao\\Bindings\\ContaoEvents", + "ContaoCommunityAlliance\\Contao\\Bindings\\Events\\Widget\\GetAttributesFromDcaEvent", + "Contao\\ManagerBundle\\ContaoManagerBundle", + "Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface", + "Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig", + "Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface", + "Doctrine\\DBAL\\Connection", "FrontendUser", "Symfony\\Component\\Config\\FileLocator", + "Symfony\\Component\\DependencyInjection\\ContainerBuilder", + "Symfony\\Component\\DependencyInjection\\Extension\\Extension", + "Symfony\\Component\\DependencyInjection\\Loader\\YamlFileLoader", + "Symfony\\Component\\HttpFoundation\\RequestStack", + "Symfony\\Component\\HttpKernel\\Bundle\\Bundle", + "Symfony\\Contracts\\Translation\\TranslatorInterface" + ] +} diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml index 78e3812..bddb943 100644 --- a/.github/workflows/diagnostics.yml +++ b/.github/workflows/diagnostics.yml @@ -1,50 +1,75 @@ -name: DC General Contao Frontend +name: Code Quality Diagnostics on: - push: pull_request: + push: + branches: jobs: build: runs-on: ubuntu-latest + name: 'PHP: ${{ matrix.php }} Contao: ${{ matrix.contao }}' strategy: + fail-fast: false matrix: - php: [8.1] - contao: [~4.13.0] + php: [ '8.1', '8.2' ] + contao: [ '~4.13.0' ] + phpcq_install: [ 'update' ] + output: [ '-o github-action -o default' ] steps: - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Pull source - uses: actions/checkout@v2 - with: - fetch-depth: 0 + - name: Pull source + uses: actions/checkout@v3 - # see https://github.com/shivammathur/setup-php - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Setup PHP. + - name: Setup PHP with PECL extension uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - coverage: none - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache composer cache directory - uses: actions/cache@v1 + # setup caches + - name: Cache composer cache directory + uses: actions/cache@v3 env: cache-name: composer-cache-dir with: path: ~/.cache/composer - key: ${{ runner.os }}-build-${{ env.cache-name }} + key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }} - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache vendor directory + - name: Cache vendor directory uses: actions/cache@v3 env: - cache-name: composer-vendor + cache-name: vendor with: path: vendor - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}- - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Install composer dependencies - run: composer update --prefer-dist --no-interaction --no-suggest + - name: Cache phpcq directory + uses: actions/cache@v3 + env: + cache-name: phpcq + with: + path: .phpcq + key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/.phpcq.lock') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}- + + # install dependencies and tools + - name: Install composer dependencies + run: | + composer require contao/core-bundle ${{ matrix.contao }} --no-update + composer install + - name: Install phpcq toolchain + run: ./vendor/bin/phpcq ${{ matrix.phpcq_install }} -v - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Run tests - run: ant -keep-going + # run tests + - name: Run tests + run: ./vendor/bin/phpcq run -v ${{ matrix.output }} + + - name: Upload build directory to artifact + uses: actions/upload-artifact@v3 + if: ${{ success() }} || ${{ failure() }} + with: + name: phpcq-builds-php-${{ matrix.php }}-${{ matrix.contao }} + path: .phpcq/build/ diff --git a/.phpcq.lock b/.phpcq.lock new file mode 100644 index 0000000..6217756 --- /dev/null +++ b/.phpcq.lock @@ -0,0 +1 @@ +{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.6.13","url":"https://phar.phpunit.de/phpunit-9.6.13.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"d67c4604908604f40cc80f75c5b55df1b685a06a1ea8191fedf78531cc5d01e5"},"signature":"https://phar.phpunit.de/phpunit-9.6.13.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.15.0","url":"https://github.com/vimeo/psalm/releases/download/5.15.0/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.15.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.14.1","url":"https://github.com/phpmd/phpmd/releases/download/2.14.1/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.14.1/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.7.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcs.phar.asc"},"phpcbf":{"version":"3.7.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.39.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.39.0/composer-normalize.phar","requirements":{"php":{"php":"~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.39.0/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/build.xml b/build.xml deleted file mode 100644 index 6c03cfd..0000000 --- a/build.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/composer.json b/composer.json index d6d7eb2..956f67e 100644 --- a/composer.json +++ b/composer.json @@ -1,59 +1,63 @@ { - "name":"contao-community-alliance/dc-general-contao-frontend", - "description":"DcGeneral frontend editing feature", - "keywords":["contao", "dc-general"], - "type":"contao-bundle", - "homepage":"https://c-c-a.org/", - "license":"LGPL-3.0-or-later", - "authors":[ + "name": "contao-community-alliance/dc-general-contao-frontend", + "description": "DcGeneral frontend editing feature", + "license": "LGPL-3.0-or-later", + "type": "contao-bundle", + "keywords": [ + "contao", + "dc-general" + ], + "authors": [ { - "name":"Christian Schiffler", - "email":"c.schiffler@cyberspectrum.de", - "homepage":"https://www.cyberspectrum.de", - "role":"Developer" + "name": "Christian Schiffler", + "email": "c.schiffler@cyberspectrum.de", + "homepage": "https://www.cyberspectrum.de", + "role": "Developer" }, { - "name":"Stefan Heimes", - "email":"stefan_heimes@hotmail.com", - "role":"Developer" + "name": "Stefan Heimes", + "email": "stefan_heimes@hotmail.com", + "role": "Developer" } ], + "homepage": "https://c-c-a.org/", "support": { - "email":"info@contao-community-alliance.org", - "issues":"https://github.com/contao-community-alliance/dc-general-contao-frontend/issues", - "wiki":"https://github.com/contao-community-alliance/dc-general-contao-frontend/wiki", - "irc":"irc://irc.freenode.org/contao.cca", - "source":"https://github.com/contao-community-alliance/dc-general-contao-frontend" + "email": "info@contao-community-alliance.org", + "issues": "https://github.com/contao-community-alliance/dc-general-contao-frontend/issues", + "wiki": "https://github.com/contao-community-alliance/dc-general-contao-frontend/wiki", + "irc": "irc://irc.freenode.org/contao.cca", + "source": "https://github.com/contao-community-alliance/dc-general-contao-frontend" }, "require": { - "php": "^8.0", + "php": "^8.1", "contao-community-alliance/dc-general": "^2.3@dev", - "contao-community-alliance/url-builder": "~1.3", "contao-community-alliance/translator": "^2.3", - "contao/core-bundle": "^4.13.0, <5.0", + "contao-community-alliance/url-builder": "^1.3", + "contao/core-bundle": "^4.13.0 <5.0", "symfony/event-dispatcher": "^5.4" }, "require-dev": { - "contao/manager-plugin": "^2.8", - "phpcq/runner-bootstrap": "^1.0@dev" + "contao/manager-bundle": "^4.13.0 <5.0", + "phpcq/runner-bootstrap": "^1.0@dev", + "roave/security-advisories": "dev-latest" }, "autoload": { "psr-4": { "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\": "src" } }, - "extra":{ - "contao-manager-plugin": "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\ContaoManager\\Plugin", - "branch-alias": { - "dev-feature/2.3.0": "2.3.x-dev" - } - }, "config": { "allow-plugins": { "contao-components/installer": false, + "contao/manager-plugin": false, "ocramius/package-versions": false, - "contao/manager-plugin": false + "php-http/discovery": true + } + }, + "extra": { + "branch-alias": { + "dev-feature/2.3.0": "2.3.x-dev" }, - "sort-packages": true + "contao-manager-plugin": "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\ContaoManager\\Plugin" } } diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..9dd9aef --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/CcaDcGeneralContaoFrontendBundle.php b/src/CcaDcGeneralContaoFrontendBundle.php index d059949..928272c 100644 --- a/src/CcaDcGeneralContaoFrontendBundle.php +++ b/src/CcaDcGeneralContaoFrontendBundle.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2017 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,7 +12,8 @@ * * @package contao-community-alliance/dc-general-contao-frontend * @author Richard Henkenjohann - * @copyright 2015-2017 Contao Community Alliance. + * @author Ingolf Steinhardt + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -26,5 +27,4 @@ */ class CcaDcGeneralContaoFrontendBundle extends Bundle { - } diff --git a/src/DependencyInjection/CcaDcGeneralContaoFrontendExtension.php b/src/DependencyInjection/CcaDcGeneralContaoFrontendExtension.php index 842a824..4eaebd5 100644 --- a/src/DependencyInjection/CcaDcGeneralContaoFrontendExtension.php +++ b/src/DependencyInjection/CcaDcGeneralContaoFrontendExtension.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2017 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,7 +12,8 @@ * * @package contao-community-alliance/dc-general-contao-frontend * @author Richard Henkenjohann - * @copyright 2015-2017 Contao Community Alliance. + * @author Ingolf Steinhardt + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -29,7 +30,6 @@ */ class CcaDcGeneralContaoFrontendExtension extends Extension { - /** * The files to load. * diff --git a/src/Event/DcGeneralFrontendEvents.php b/src/Event/DcGeneralFrontendEvents.php index 0f6f6a4..9576b95 100644 --- a/src/Event/DcGeneralFrontendEvents.php +++ b/src/Event/DcGeneralFrontendEvents.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,7 +12,8 @@ * * @package contao-community-alliance/dc-general-contao-frontend * @author Christian Schiffler - * @copyright 2015 Contao Community Alliance. + * @author Ingolf Steinhardt + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -29,12 +30,12 @@ class DcGeneralFrontendEvents * * @see ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Event\BuildWidgetEvent */ - const BUILD_WIDGET = 'dc-general.contao-frontend.build-widget'; + public const BUILD_WIDGET = 'dc-general.contao-frontend.build-widget'; /** * This event is being emitted when the edit mask has encountered a submit and post action shall be performed. * * @see ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Event\HandleSubmitEvent */ - const HANDLE_SUBMIT = 'dc-general.contao-frontend.handle-submit'; + public const HANDLE_SUBMIT = 'dc-general.contao-frontend.handle-submit'; } diff --git a/src/Listener/HandleSubmitListener.php b/src/Listener/HandleSubmitListener.php index 3dc9c8d..eb638b1 100644 --- a/src/Listener/HandleSubmitListener.php +++ b/src/Listener/HandleSubmitListener.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2018 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,8 @@ * @package contao-community-alliance/dc-general-contao-frontend * @author Christian Schiffler * @author Richard Henkenjohann - * @copyright 2015-2018 Contao Community Alliance. + * @author Ingolf Steinhardt + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -32,7 +33,6 @@ */ class HandleSubmitListener { - /** * The request scope determinator. * diff --git a/src/View/ActionHandler/CopyHandler.php b/src/View/ActionHandler/CopyHandler.php index 589b83f..e4260c2 100644 --- a/src/View/ActionHandler/CopyHandler.php +++ b/src/View/ActionHandler/CopyHandler.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2022 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,7 @@ * @package contao-community-alliance/dc-general-contao-frontend * @author Richard Henkenjohann * @author Ingolf Steinhardt - * @copyright 2015-2022 Contao Community Alliance. + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -37,6 +37,8 @@ /** * This class handles the copy actions in the frontend. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CopyHandler { diff --git a/src/View/DefaultWidgetBuilder.php b/src/View/DefaultWidgetBuilder.php index ec9594b..9f5c16b 100644 --- a/src/View/DefaultWidgetBuilder.php +++ b/src/View/DefaultWidgetBuilder.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2022 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Christian Schiffler * @author Richard Henkenjohann * @author Ingolf Steinhardt - * @copyright 2015-2022 Contao Community Alliance. + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -35,10 +35,11 @@ /** * Widget Builder to build Contao frontend widgets. + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ class DefaultWidgetBuilder { - /** * The request scope determinator. * @@ -109,14 +110,16 @@ public function buildWidget( ->setProperty($propertyName) ->setValue($model->getProperty($propertyName)); - $dispatcher->dispatch($event,$event::NAME); + $dispatcher->dispatch($event, $event::NAME); $varValue = $event->getValue(); $propExtra['required'] = ($varValue == '') && !empty($propExtra['mandatory']); $propExtra['tableless'] = true; - if (isset($propExtra['readonly']) + if ( + isset($propExtra['readonly']) && $propExtra['readonly'] - && \in_array($property->getWidgetType(), ['checkbox', 'select'], true)) { + && \in_array($property->getWidgetType(), ['checkbox', 'select'], true) + ) { $propExtra['disabled'] = true; } diff --git a/src/View/EditMask.php b/src/View/EditMask.php index 50ff8b8..182f47d 100644 --- a/src/View/EditMask.php +++ b/src/View/EditMask.php @@ -47,6 +47,9 @@ * This class manages the displaying of the edit/create mask containing the widgets. * * It also handles the persisting of the model. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ class EditMask { @@ -297,13 +300,16 @@ private function handlePostPersist() private function translateLabel($transString, $parameters = []) { $translator = $this->translator; - if ($transString !== ($label = - $translator->translate($transString, $this->definition->getName(), $parameters))) { + if ( + $transString !== ($label = + $translator->translate($transString, $this->definition->getName(), $parameters)) + ) { return $label; } - if ($transString !== ($label = - $translator->translate('MSC.'.$transString, $this->definition->getName(), $parameters)) + if ( + $transString !== ($label = + $translator->translate('MSC.' . $transString, $this->definition->getName(), $parameters)) ) { return $label; } @@ -392,7 +398,8 @@ private function buildFieldSet($widgetManager, $palette, $propertyValues) $this->ensurePropertyExists($propertyName, $propertyDefinitions); // If this property is invalid, fetch the error. - if ((!$isAutoSubmit) + if ( + (!$isAutoSubmit) && $propertyValues && $propertyValues->hasPropertyValue($propertyName) && $propertyValues->isPropertyValueInvalid($propertyName) @@ -461,7 +468,8 @@ private function storeVersion(ModelInterface $model) $dataProvider = $environment->getDataProvider($this->model->getProviderName()); $currentVersion = $dataProvider->getActiveVersion($modelId); // Compare version and current record. - if (!$currentVersion + if ( + !$currentVersion || !$dataProvider->sameModels($model, $dataProvider->getVersion($modelId, $currentVersion)) ) { $user = \FrontendUser::getInstance(); diff --git a/src/View/WidgetManager.php b/src/View/WidgetManager.php index b3da44d..5bb629c 100644 --- a/src/View/WidgetManager.php +++ b/src/View/WidgetManager.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2022 Contao Community Alliance. + * (c) 2015-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Christian Schiffler * @author Richard Henkenjohann * @author Ingolf Steinhardt - * @copyright 2015-2022 Contao Community Alliance. + * @copyright 2015-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -36,6 +36,8 @@ * Class WidgetManager. * * This class is responsible for creating widgets and processing data through them. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class WidgetManager { @@ -141,7 +143,8 @@ public function renderWidget($property, $ignoreErrors = false, PropertyValueBag $reflection->setAccessible(true); $reflection->setValue($widget, str_replace('error', '', $reflection->getValue($widget))); } else { - if ($valueBag && $valueBag->hasPropertyValue($property) + if ( + $valueBag && $valueBag->hasPropertyValue($property) && $valueBag->isPropertyValueInvalid($property) ) { foreach ($valueBag->getPropertyValueErrors($property) as $error) { diff --git a/src/Widgets/UploadOnSteroids.php b/src/Widgets/UploadOnSteroids.php index 0e234f6..6849428 100644 --- a/src/Widgets/UploadOnSteroids.php +++ b/src/Widgets/UploadOnSteroids.php @@ -131,23 +131,25 @@ class UploadOnSteroids extends FormFileUpload */ public function __set($key, $value) { - if (\in_array( - $key, - [ - 'deselect', - 'delete', - 'extendFolder', - 'normalizeExtendFolder', - 'normalizeFilename', - 'prefixFilename', - 'postfixFilename', - 'files', - 'showThumbnail', - 'multiple', - 'imageSize', - 'sortBy' - ] - )) { + if ( + \in_array( + $key, + [ + 'deselect', + 'delete', + 'extendFolder', + 'normalizeExtendFolder', + 'normalizeFilename', + 'prefixFilename', + 'postfixFilename', + 'files', + 'showThumbnail', + 'multiple', + 'imageSize', + 'sortBy' + ] + ) + ) { $this->arrConfiguration[$key] = $value; return; @@ -334,7 +336,8 @@ private function getMultipleUploadedFiles(): array */ private function deselectFile(string $inputName) { - if (!$this->deselect + if ( + !$this->deselect || $this->hasErrors() || !($post = $this->inputProvider()->post($inputName)) || !isset($post['reset'][0]) @@ -365,7 +368,8 @@ private function deselectFile(string $inputName) */ private function deleteFile(string $inputName) { - if (!$this->delete + if ( + !$this->delete || $this->hasErrors() || !($post = $this->inputProvider()->post($inputName)) || !isset($post['delete'][0]) From 3a06667b60f44500967e4316962e68bd99617f6c Mon Sep 17 00:00:00 2001 From: e-spin Date: Mon, 11 Mar 2024 18:57:18 +0100 Subject: [PATCH 3/7] Any fixes --- psalm.xml | 29 ++++++++++++++++++----------- src/View/EditMask.php | 23 +++++++++++------------ src/View/WidgetManager.php | 7 ++++--- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/psalm.xml b/psalm.xml index 034092e..abd61c3 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,15 +1,22 @@ - - - - - - + + + + + + + + + + + + + diff --git a/src/View/EditMask.php b/src/View/EditMask.php index 973ded4..5221453 100644 --- a/src/View/EditMask.php +++ b/src/View/EditMask.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ * @author Richard Henkenjohann * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -28,6 +28,7 @@ use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetEditModeButtonsEvent; use ContaoCommunityAlliance\DcGeneral\Controller\ControllerInterface; use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; +use ContaoCommunityAlliance\DcGeneral\DataDefinition\DataProviderInformationInterface; use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\PropertiesDefinitionInterface; use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\PaletteInterface; use ContaoCommunityAlliance\DcGeneral\Data\DataProviderInterface; @@ -86,9 +87,9 @@ class EditMask /** * The data provider of the model being edited. * - * @var DataProviderInterface + * @var DataProviderInformationInterface */ - private DataProviderInterface $modelProvider; + private DataProviderInformationInterface $modelProvider; /** * The model to be manipulated. @@ -156,7 +157,6 @@ public function __construct($environment, $model, $originalModel, $preFunction, * @return string * * @throws DcGeneralRuntimeException If the data container is not editable, closed. - * * @throws DcGeneralInvalidArgumentException If an unknown property is encountered in the palette. */ public function execute() @@ -177,8 +177,7 @@ public function execute() $palette = $palettesDefinition->findPalette($this->model); $propertyValues = $this->processInput($widgetManager); - assert($propertyValues instanceof PropertyValueBag); - if ($isSubmitted) { + if ($isSubmitted && null !== $propertyValues) { // Pass 2: Determine the real palette we want to work on if we have some data submitted. $palette = $palettesDefinition->findPalette($this->model, $propertyValues); @@ -365,9 +364,9 @@ private function getEditButtons(): array /** * Build the field sets. * - * @param WidgetManager $widgetManager The widget manager in use. - * @param PaletteInterface $palette The palette to use. - * @param PropertyValueBag $propertyValues The property values. + * @param WidgetManager $widgetManager The widget manager in use. + * @param PaletteInterface $palette The palette to use. + * @param PropertyValueBag|null $propertyValues The property values. * * @return array * @@ -379,7 +378,7 @@ private function getEditButtons(): array private function buildFieldSet( WidgetManager $widgetManager, PaletteInterface $palette, - PropertyValueBag $propertyValues + ?PropertyValueBag $propertyValues ): array { $propertyDefinitions = $this->definition->getPropertiesDefinition(); @@ -470,7 +469,7 @@ private function ensurePropertyExists(string $property, PropertiesDefinitionInte */ private function storeVersion(ModelInterface $model): void { - if (!$this->modelProvider->isVersioningEnabled() || null === $model) { + if (!$this->modelProvider->isVersioningEnabled()) { return; } diff --git a/src/View/WidgetManager.php b/src/View/WidgetManager.php index dad6e18..d42002e 100644 --- a/src/View/WidgetManager.php +++ b/src/View/WidgetManager.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Christian Schiffler * @author Richard Henkenjohann * @author Ingolf Steinhardt - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -27,6 +27,7 @@ use ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Event\BuildWidgetEvent; use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\EncodePropertyValueFromWidgetEvent; use ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Event\DcGeneralFrontendEvents; +use ContaoCommunityAlliance\DcGeneral\Controller\ControllerInterface; use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface; use ContaoCommunityAlliance\DcGeneral\Data\PropertyValueBag; use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; @@ -104,7 +105,7 @@ public function getWidget($property, PropertyValueBag $valueBag = null) $values = new PropertyValueBag($valueBag->getArrayCopy()); $controller = $this->environment->getController(); - assert($controller instanceof ContainerInterface); + assert($controller instanceof ControllerInterface); $controller->updateModelFromPropertyBag($model, $values); } From 0af1fc1b6aa2b48bea6876624578a3b4c6bbed5d Mon Sep 17 00:00:00 2001 From: Ingolf Steinardt Date: Wed, 3 Jul 2024 14:40:22 +0200 Subject: [PATCH 4/7] Any fixes --- .phpcq.lock | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.phpcq.lock b/.phpcq.lock index cd6ca52..25673df 100644 --- a/.phpcq.lock +++ b/.phpcq.lock @@ -1 +1 @@ -{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpunit/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.6.16","url":"https://phar.phpunit.de/phpunit-9.6.16.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"891d46f06284db3695498aff5dfd6a944f835e07db2981295db2c2bcf6cfd338"},"signature":"https://phar.phpunit.de/phpunit-9.6.16.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.20.0","url":"https://github.com/vimeo/psalm/releases/download/5.20.0/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.20.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-require-checker/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpmd/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.15.0","url":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcpd/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phploc/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.8.1","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcs.phar.asc"},"phpcbf":{"version":"3.8.1","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.41.1","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.41.1/composer-normalize.phar","requirements":{"php":{"php":"~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.41.1/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file +{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpunit/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.6.17","url":"https://phar.phpunit.de/phpunit-9.6.17.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"1a6990cf0a8d05c53c15dad39f68ee6fe413e1ab8261eaa14c5a4a647ed08ac7"},"signature":"https://phar.phpunit.de/phpunit-9.6.17.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.23.1","url":"https://github.com/vimeo/psalm/releases/download/5.23.1/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.23.1/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-require-checker/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpmd/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.15.0","url":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcpd/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phploc/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.9.0","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcs.phar.asc"},"phpcbf":{"version":"3.9.0","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.42.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar","requirements":{"php":{"php":"~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/composer.json b/composer.json index 1a80057..13a33d8 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "require": { "php": "^8.1", "contao-community-alliance/dc-general": "^2.3", - "contao-community-alliance/translator": "^2.3", + "contao-community-alliance/translator": "^2.4.2", "contao-community-alliance/url-builder": "^1.3", "contao/core-bundle": "^4.13.0 <5.0", "symfony/event-dispatcher": "^5.4" From 3c2b6392077b64769b7eea030f9773d6682ff91c Mon Sep 17 00:00:00 2001 From: Ingolf Steinardt Date: Thu, 25 Jul 2024 15:05:23 +0200 Subject: [PATCH 5/7] Any fixes for PHPCQ --- .phpcq.lock | 2 +- .phpcq.yaml.dist | 3 +- composer.json | 4 +- src/Event/BuildWidgetEvent.php | 9 +- src/FrontendEditor.php | 13 ++- .../widgets/form_upload-on-steroids.html5 | 4 +- src/View/ActionHandler/CreateHandler.php | 20 ++--- src/View/ActionHandler/DeleteHandler.php | 9 +- src/View/ActionHandler/EditHandler.php | 16 ++-- src/View/DefaultWidgetBuilder.php | 4 +- src/View/EditMask.php | 12 ++- src/View/ViewTemplate.php | 48 ++++++++--- src/Widgets/UploadOnSteroids.php | 85 +++++++++---------- 13 files changed, 121 insertions(+), 108 deletions(-) diff --git a/.phpcq.lock b/.phpcq.lock index 25673df..52ac3b1 100644 --- a/.phpcq.lock +++ b/.phpcq.lock @@ -1 +1 @@ -{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpunit/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.6.17","url":"https://phar.phpunit.de/phpunit-9.6.17.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"1a6990cf0a8d05c53c15dad39f68ee6fe413e1ab8261eaa14c5a4a647ed08ac7"},"signature":"https://phar.phpunit.de/phpunit-9.6.17.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.23.1","url":"https://github.com/vimeo/psalm/releases/download/5.23.1/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.23.1/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-require-checker/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpmd/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.15.0","url":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcpd/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phploc/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.9.0","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcs.phar.asc"},"phpcbf":{"version":"3.9.0","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.9.0/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.42.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar","requirements":{"php":{"php":"~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file +{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpunit/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.6.20","url":"https://phar.phpunit.de/phpunit-9.6.20.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"4b49fdf48a3fdb5f4f4b5b18c43a542e75787edaf6a6ab39713f579d0a018210"},"signature":"https://phar.phpunit.de/phpunit-9.6.20.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.25.0","url":"https://github.com/vimeo/psalm/releases/download/5.25.0/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.25.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-require-checker/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"4.11.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.11.0/composer-require-checker.phar","requirements":{"php":{"php":"~8.2.0 || ~8.3.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.11.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpmd/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.15.0","url":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcpd/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phploc/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"b6ed00306e76068a6af5e3b1dec837724f9e1900ef1049ce88e7ce195b0583524ca33a73613fba13244307a7ca853b6ddaa14ded69f651c3f184ac130bd1aaad"},"tools":{"phpcs":{"version":"3.10.2","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.10.2/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.10.2/phpcs.phar.asc"},"phpcbf":{"version":"3.10.2","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.10.2/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.10.2/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d9abda440b85d501c58abf9c81bf76f417594b397129215ffa8b777e9bb5e5eda37d7661d661db3c8d11c24f20345bc6fbe56f013b3b9435d459d2b94f086e0f"},"tools":{"composer-normalize":{"version":"2.43.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.43.0/composer-normalize.phar","requirements":{"php":{"php":"~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.43.0/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/.phpcq.yaml.dist b/.phpcq.yaml.dist index 5cf7a38..236f0aa 100644 --- a/.phpcq.yaml.dist +++ b/.phpcq.yaml.dist @@ -19,7 +19,7 @@ phpcq: requirements: composer-require-checker: signed: false - version: ^3.3 + version: ^4.0 phpmd: version: ^1.0 signed: false @@ -51,6 +51,7 @@ phpcq: - D2CCAC42F6295E7D # PHP_CodeSniffer - 31C7E470E2138192 + - A978220305CD5C32 # Composer normalize - C00543248C87FB13 # phpmd diff --git a/composer.json b/composer.json index 13a33d8..f07fd4a 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "type": "contao-bundle", "keywords": [ "contao", - "dc-general" + "dc-general", + "frontend" ], "authors": [ { @@ -25,7 +26,6 @@ "email": "info@contao-community-alliance.org", "issues": "https://github.com/contao-community-alliance/dc-general-contao-frontend/issues", "wiki": "https://github.com/contao-community-alliance/dc-general-contao-frontend/wiki", - "irc": "irc://irc.freenode.org/contao.cca", "source": "https://github.com/contao-community-alliance/dc-general-contao-frontend" }, "require": { diff --git a/src/Event/BuildWidgetEvent.php b/src/Event/BuildWidgetEvent.php index efa8afd..05cd3ac 100644 --- a/src/Event/BuildWidgetEvent.php +++ b/src/Event/BuildWidgetEvent.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,7 +12,8 @@ * * @package contao-community-alliance/dc-general-contao-frontend * @author Christian Schiffler - * @copyright 2015 Contao Community Alliance. + * @author Ingolf Steinhardt + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -48,9 +49,7 @@ class BuildWidgetEvent extends AbstractModelAwareEvent * Create a new event. * * @param EnvironmentInterface $environment The environment instance in use. - * * @param ModelInterface $model The model holding the data for the widget that shall be instantiated. - * * @param PropertyInterface $property The property for which the widget shall be instantiated. */ public function __construct( @@ -66,7 +65,7 @@ public function __construct( /** * Stores the widget instance into the event. * - * @param \Widget $widget The widget instance. + * @param Widget|null $widget The widget instance. * * @return BuildWidgetEvent */ diff --git a/src/FrontendEditor.php b/src/FrontendEditor.php index 00adb75..bd19e4d 100644 --- a/src/FrontendEditor.php +++ b/src/FrontendEditor.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ * @author Richard Henkenjohann * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -41,27 +41,26 @@ class FrontendEditor * * @var EventDispatcherInterface */ - private $dispatcher; + private EventDispatcherInterface $dispatcher; /** * The translator. * * @var TranslatorInterface */ - private $translator; + private TranslatorInterface $translator; /** * The already populated environments. * * @var EnvironmentInterface[] */ - private static $environments = []; + private static array $environments = []; /** * Create a new instance. * * @param EventDispatcherInterface $dispatcher The event dispatcher. - * * @param TranslatorInterface $translator The translator. */ public function __construct(EventDispatcherInterface $dispatcher, TranslatorInterface $translator) @@ -102,7 +101,7 @@ public function editFor($containerName, $defaultAction = 'showAll'): string $inputProvider->unsetParameter('act'); } - if (!$result = $event->getResponse()) { + if (null === ($result = $event->getResponse())) { return 'Action ' . $action->getName() . ' is not supported yet.'; } diff --git a/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 b/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 index b0ad124..6415986 100644 --- a/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 +++ b/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 @@ -34,9 +34,7 @@
deselect): ?>
- + diff --git a/src/View/ActionHandler/CreateHandler.php b/src/View/ActionHandler/CreateHandler.php index 312d628..ae5c858 100644 --- a/src/View/ActionHandler/CreateHandler.php +++ b/src/View/ActionHandler/CreateHandler.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Christian Schiffler * @author Ingolf Steinhardt * @author Richard Henkenjohann - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -34,7 +34,7 @@ use ContaoCommunityAlliance\DcGeneral\Exception\NotCreatableException; /** - * This class handles the create actions in the frontend. + * This class handles the actions of create in the frontend. */ class CreateHandler { @@ -69,12 +69,9 @@ public function handleEvent(ActionEvent $event): void return; } - $environment = $event->getEnvironment(); - $action = $event->getAction(); - - // Only handle if we do not have a manual sorting or we know where to insert. + // Only handle if we do not have a manual sorting, or we know where to insert. // Manual sorting is handled by clipboard. - if ('create' !== $action->getName()) { + if ('create' !== $event->getAction()->getName()) { return; } @@ -83,8 +80,7 @@ public function handleEvent(ActionEvent $event): void return; } - $response = $this->process($environment); - if ($response !== false) { + if ('' !== ($response = $this->process($event->getEnvironment()))) { $event->setResponse($response); } } @@ -94,7 +90,7 @@ public function handleEvent(ActionEvent $event): void * * @param EnvironmentInterface $environment The environment. * - * @return string|bool + * @return string * * @throws NotCreatableException If the data container is not editable, closed. */ @@ -110,7 +106,7 @@ public function process(EnvironmentInterface $environment) } // We only support flat tables, sorry. if (BasicDefinitionInterface::MODE_HIERARCHICAL === $basicDefinition->getMode()) { - return false; + return ''; } $dataProvider = $environment->getDataProvider(); diff --git a/src/View/ActionHandler/DeleteHandler.php b/src/View/ActionHandler/DeleteHandler.php index c7d1cdf..22350ae 100644 --- a/src/View/ActionHandler/DeleteHandler.php +++ b/src/View/ActionHandler/DeleteHandler.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,7 +13,7 @@ * @package contao-community-alliance/dc-general-contao-frontend * @author Richard Henkenjohann * @author Ingolf Steinhardt - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -40,7 +40,7 @@ use Symfony\Component\HttpFoundation\RequestStack; /** - * This class handles the edit actions in the frontend. + * This class handles the actions of edit in the frontend. * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -59,7 +59,6 @@ class DeleteHandler * DeleteHandler constructor. * * @param RequestScopeDeterminator $scopeDeterminator The request mode determinator. - * * @param RequestStack $requestStack The current request stack. */ public function __construct(RequestScopeDeterminator $scopeDeterminator, RequestStack $requestStack) @@ -155,6 +154,6 @@ public function process(EnvironmentInterface $environment): void $currentRequest = $this->requestStack->getCurrentRequest(); assert($currentRequest instanceof Request); - throw new RedirectResponseException($currentRequest->headers->get('referer')); + throw new RedirectResponseException($currentRequest->headers->get('referer') ?? ''); } } diff --git a/src/View/ActionHandler/EditHandler.php b/src/View/ActionHandler/EditHandler.php index f3fbd14..b6bd869 100644 --- a/src/View/ActionHandler/EditHandler.php +++ b/src/View/ActionHandler/EditHandler.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,7 +15,7 @@ * @author Richard Henkenjohann * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ @@ -38,7 +38,7 @@ use ContaoCommunityAlliance\DcGeneral\InputProviderInterface; /** - * This class handles the edit actions in the frontend. + * This class handles the actions of edit in the frontend. * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -76,10 +76,9 @@ public function handleEvent(ActionEvent $event): void return; } - $action = $event->getAction(); // Only handle if we do not have a manual sorting or we know where to insert. // Manual sorting is handled by clipboard. - if ('edit' !== $action->getName()) { + if ('edit' !== $event->getAction()->getName()) { return; } @@ -88,8 +87,7 @@ public function handleEvent(ActionEvent $event): void return; } - $response = $this->process($event->getEnvironment()); - if (false !== $response) { + if ('' !== ($response = $this->process($event->getEnvironment()))) { $event->setResponse($response); } } @@ -99,7 +97,7 @@ public function handleEvent(ActionEvent $event): void * * @param EnvironmentInterface $environment The environment. * - * @return string|bool + * @return string * * @throws PageNotFoundException If item to edit was not found. * @throws NotEditableException When the definition is not editable. @@ -117,7 +115,7 @@ public function process(EnvironmentInterface $environment) // We only support flat tables, sorry. if (BasicDefinitionInterface::MODE_HIERARCHICAL === $basicDefinition->getMode()) { - return false; + return ''; } $inputProvider = $environment->getInputProvider(); diff --git a/src/View/DefaultWidgetBuilder.php b/src/View/DefaultWidgetBuilder.php index 426762f..60c503e 100644 --- a/src/View/DefaultWidgetBuilder.php +++ b/src/View/DefaultWidgetBuilder.php @@ -21,6 +21,7 @@ namespace ContaoCommunityAlliance\DcGeneral\ContaoFrontend\View; +use Contao\Widget; use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents; use ContaoCommunityAlliance\Contao\Bindings\Events\Widget\GetAttributesFromDcaEvent; use ContaoCommunityAlliance\DcGeneral\Contao\Compatibility\DcCompat; @@ -86,7 +87,7 @@ public function handleEvent(BuildWidgetEvent $event) * @param PropertyInterface $property The property. * @param ModelInterface $model The current model. * - * @return \Widget + * @return Widget|null * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) @@ -191,6 +192,7 @@ public function buildWidget( } $widget = new $strClass($preparedConfig, new DcCompat($environment, $model, $propertyName)); + assert($widget instanceof Widget); $widget->currentRecord = $model->getId(); diff --git a/src/View/EditMask.php b/src/View/EditMask.php index 5221453..6a22693 100644 --- a/src/View/EditMask.php +++ b/src/View/EditMask.php @@ -139,8 +139,12 @@ public function __construct($environment, $model, $originalModel, $preFunction, { $providerName = $model->getProviderName(); $this->environment = $environment; - $this->translator = $environment->getTranslator(); - $this->dispatcher = $environment->getEventDispatcher(); + $translator = $environment->getTranslator(); + assert($translator instanceof TranslatorInterface); + $this->translator = $translator; + $dispatcher = $environment->getEventDispatcher(); + assert($dispatcher instanceof EventDispatcherInterface); + $this->dispatcher = $dispatcher; $dataDefinition = $environment->getDataDefinition(); assert($dataDefinition instanceof ContainerInterface); $this->definition = $dataDefinition; @@ -479,10 +483,12 @@ private function storeVersion(ModelInterface $model): void assert($dataProvider instanceof DataProviderInterface); $currentVersion = $dataProvider->getActiveVersion($modelId); + $version = $dataProvider->getVersion($modelId, $currentVersion); + assert($version instanceof ModelInterface); // Compare version and current record. if ( !$currentVersion - || !$dataProvider->sameModels($model, $dataProvider->getVersion($modelId, $currentVersion)) + || !$dataProvider->sameModels($model, $version) ) { $user = \FrontendUser::getInstance(); $username = '(frontend anonymous)'; diff --git a/src/View/ViewTemplate.php b/src/View/ViewTemplate.php index 18e5068..2453630 100644 --- a/src/View/ViewTemplate.php +++ b/src/View/ViewTemplate.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2023 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,27 +13,30 @@ * @package contao-community-alliance/dc-general-contao-frontend * @author Christian Schiffler * @author Ingolf Steinhardt - * @copyright 2015-2023 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ namespace ContaoCommunityAlliance\DcGeneral\ContaoFrontend\View; +use Contao\BackendTemplate; use ContaoCommunityAlliance\DcGeneral\View\ViewTemplateInterface; use ContaoCommunityAlliance\Translator\TranslatorInterface; /** * This class is used for the contao frontend view as template. + * + * @psalm-suppress PropertyNotSetInConstructor */ -class ViewTemplate extends \BackendTemplate implements ViewTemplateInterface, TranslatorInterface +class ViewTemplate extends BackendTemplate implements ViewTemplateInterface, TranslatorInterface { /** * The translator. * * @var TranslatorInterface */ - protected $translator; + protected TranslatorInterface $translator; /** * Get the translator. @@ -92,11 +95,7 @@ public function get($name) */ public function translate($string, $domain = null, array $parameters = [], $locale = null) { - if ($this->translator) { - return $this->translator->translate($string, $domain, $parameters, $locale); - } - - return $string; + return $this->translator->translate($string, $domain, $parameters, $locale); } /** @@ -104,10 +103,33 @@ public function translate($string, $domain = null, array $parameters = [], $loca */ public function translatePluralized($string, $number, $domain = null, array $parameters = [], $locale = null) { - if ($this->translator) { - return $this->translator->translatePluralized($string, $number, $domain, $parameters, $locale); - } + return $this->translator->translatePluralized($string, $number, $domain, $parameters, $locale); + } + + // @codingStandardsIgnoreStart + /** + * {@inheritDoc} + */ + public function getData() + { + return parent::getData(); + } - return $string; + /** + * {@inheritDoc} + */ + public function parse() + { + return parent::parse(); + } + + /** + * {@inheritDoc} + */ + public function output() + { + /** @psalm-suppress DeprecatedMethod */ + parent::output(); } + // @codingStandardsIgnoreEnd } diff --git a/src/Widgets/UploadOnSteroids.php b/src/Widgets/UploadOnSteroids.php index 2a72e99..06cf533 100644 --- a/src/Widgets/UploadOnSteroids.php +++ b/src/Widgets/UploadOnSteroids.php @@ -64,6 +64,10 @@ * * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * + * @psalm-suppress PropertyNotSetInConstructor + * @psalm-suppress UndefinedThisPropertyFetch + * @psalm-suppress UndefinedThisPropertyAssignment */ class UploadOnSteroids extends FormFileUpload { @@ -133,11 +137,11 @@ class UploadOnSteroids extends FormFileUpload /** * {@inheritDoc} */ - public function __set($key, $value) + public function __set($strKey, $varValue) { if ( \in_array( - $key, + $strKey, [ 'deselect', 'delete', @@ -154,12 +158,12 @@ public function __set($key, $value) ] ) ) { - $this->arrConfiguration[$key] = $value; + $this->arrConfiguration[$strKey] = $varValue; return; } - parent::__set($key, $value); + parent::__set($strKey, $varValue); } /** @@ -198,7 +202,7 @@ public function parseFilename(string $filename): string /** * {@inheritDoc} */ - public function validate() + public function validate(): void { $inputName = $this->name; @@ -207,8 +211,9 @@ public function validate() } if ($this->extendFolder) { + /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ $uploadFolder = $this->filesModel()->findByUuid($this->uploadFolder); - $uploadFolderPath = $uploadFolder->path . DIRECTORY_SEPARATOR . $this->extendFolder; + $uploadFolderPath = (string) $uploadFolder?->path . DIRECTORY_SEPARATOR . $this->extendFolder; $newUploadFolder = null; @@ -217,13 +222,15 @@ public function validate() $newUploadFolder = Dbafs::addResource($uploadFolderPath); } - if (!$newUploadFolder) { + if (null === $newUploadFolder) { + /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ $newUploadFolder = $this->filesModel()->findByPath($uploadFolderPath); } - $this->uploadFolder = $newUploadFolder->uuid; + $this->uploadFolder = $newUploadFolder?->uuid ?? ''; } + /** @psalm-suppress DeprecatedMethod */ $this->validateSingleUpload(); $this->validateMultipleUpload(); $this->deselectFile($inputName); @@ -237,6 +244,8 @@ public function validate() * * @throws \Exception * @SuppressWarnings(PHPMD.Superglobals) + * + * @deprecated Use multiple upload. */ private function validateSingleUpload(): void { @@ -245,7 +254,7 @@ private function validateSingleUpload(): void } $inputName = $this->name; - $_FILES[$inputName]['name'] = $this->parseFilename($_FILES[$inputName]['name']); + $_FILES[$inputName]['name'] = $this->parseFilename($_FILES[$inputName]['name'] ?? ''); parent::validate(); @@ -325,7 +334,7 @@ private function getMultipleUploadedFiles(): array $files = []; foreach ($_FILES[$this->name] as $propertyName => $values) { - foreach ($values as $key => $value) { + foreach ((array) $values as $key => $value) { $files[$key][$propertyName] = $value; } } @@ -342,6 +351,7 @@ private function getMultipleUploadedFiles(): array */ private function deselectFile(string $inputName): void { + /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ if ( !$this->deselect || $this->hasErrors() @@ -374,6 +384,7 @@ private function deselectFile(string $inputName): void */ private function deleteFile(string $inputName): void { + /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ if ( !$this->delete || $this->hasErrors() @@ -386,14 +397,14 @@ private function deleteFile(string $inputName): void if (!$this->multiple && (StringUtil::binToUuid($this->value) === $post['delete'][0])) { $this->value = ''; + /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ $file = $this->filesModel()->findByUuid($this->value); - if ($file) { + if (null !== $file) { $this->filesystem->remove($file->path); $file->delete(); + Dbafs::deleteResource($file->path); } - Dbafs::deleteResource($file->path); - return; } @@ -401,8 +412,9 @@ private function deleteFile(string $inputName): void $diffValues = \array_values(\array_diff($values, $post['delete'])); foreach ($post['delete'] as $delete) { + /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ $file = $this->filesModel()->findByUuid(StringUtil::uuidToBin($delete)); - if (!$file) { + if (null === $file) { continue; } @@ -424,8 +436,8 @@ private function deleteFile(string $inputName): void private function convertFilename(string $filename): string { $fileInfo = \pathinfo($filename); - $extension = $fileInfo['extension']; - $filename = $fileInfo['filename']; + $extension = $fileInfo['extension'] ?? ''; + $filename = $fileInfo['filename'] ?? ''; if ($this->normalizeFilename) { $extension = $this->slugGenerator()->generate($extension, $this->getSlugOptions()); @@ -453,15 +465,15 @@ private function preOrPostFixFilename(string $filename): string $prefix = $this->prefixFilename; if ($this->prefixFilename && $this->normalizeFilename) { $prefix = \str_repeat('-', \strspn($this->prefixFilename, '-')) . - $this->slugGenerator()->generate($this->prefixFilename, $this->getSlugOptions()) . - \str_repeat('-', \strspn(\strrev($this->prefixFilename), '-')); + $this->slugGenerator()->generate($this->prefixFilename, $this->getSlugOptions()) . + \str_repeat('-', \strspn(\strrev($this->prefixFilename), '-')); } $postfix = $this->postfixFilename; if ($this->postfixFilename && $this->normalizeFilename) { $postfix = \str_repeat('-', \strspn($this->postfixFilename, '-')) . - $this->slugGenerator()->generate($this->postfixFilename, $this->getSlugOptions()) . - \str_repeat('-', \strspn(\strrev($this->postfixFilename), '-')); + $this->slugGenerator()->generate($this->postfixFilename, $this->getSlugOptions()) . + \str_repeat('-', \strspn(\strrev($this->postfixFilename), '-')); } return $prefix . $filename . $postfix; @@ -489,9 +501,7 @@ private function addFiles($sortBy): void $connection = self::getContainer()->get('database_connection'); $platform = $connection->getDatabasePlatform(); - assert($platform instanceof AbstractPlatform); - - $builder = $connection->createQueryBuilder(); + $builder = $connection->createQueryBuilder(); switch ($sortBy) { case 'name_desc': @@ -549,10 +559,13 @@ private function addFiles($sortBy): void $fileList = []; $container = System::getContainer(); $projectDir = $container->getParameter('kernel.project_dir'); + assert(\is_string($projectDir)); foreach ($statement->fetchAllAssociative() as $file) { - $objFile = FilesModel::findByUuid($file['uuid']); + if (null === ($objFile = FilesModel::findByUuid($file['uuid']))) { + continue; + } $src = $container->get('contao.image.image_factory') - ->create($projectDir . '/' . rawurldecode($objFile->path), $this->imageSize) + ?->create($projectDir . '/' . rawurldecode($objFile->path), $this->imageSize) ->getUrl($projectDir); $objThumbnailFile = new File(rawurldecode($src)); @@ -628,7 +641,7 @@ private function addIsMultiple(): void return; } - $this->prefix .= $this->multiple ? ' is-multiple' : ''; + $this->prefix .= ' is-multiple'; $this->addAttribute('multiple', 'multiple'); } @@ -640,10 +653,6 @@ private function addIsMultiple(): void */ private function inputProvider(): Input|Adapter { - if (!$this->inputProvider) { - $this->inputProvider = self::getContainer()->get('contao.framework')->getAdapter(Input::class); - } - return $this->inputProvider; } @@ -654,10 +663,6 @@ private function inputProvider(): Input|Adapter */ private function filesModel(): FilesModel|Adapter { - if (!$this->filesModel) { - $this->filesModel = self::getContainer()->get('contao.framework')->getAdapter(FilesModel::class); - } - return $this->filesModel; } @@ -668,10 +673,6 @@ private function filesModel(): FilesModel|Adapter */ private function filesystem(): Filesystem { - if (!$this->filesystem) { - $this->filesystem = self::getContainer()->get('filesystem'); - } - return $this->filesystem; } @@ -682,10 +683,6 @@ private function filesystem(): Filesystem */ private function slugGenerator(): SlugGenerator { - if (!$this->slugGenerator) { - $this->slugGenerator = System::getContainer()->get('contao.slug'); - } - return $this->slugGenerator; } @@ -706,10 +703,6 @@ protected function getSlugOptions(): array */ private function translator(): TranslatorInterface { - if (!$this->translator) { - $this->translator = self::getContainer()->get('translator'); - } - return $this->translator; } From 32a6fa380148b8ec944450150ed1680a27db7900 Mon Sep 17 00:00:00 2001 From: Ingolf Steinardt Date: Thu, 25 Jul 2024 15:15:56 +0200 Subject: [PATCH 6/7] Add changes from #45 --- .../contao/templates/widgets/form_upload-on-steroids.html5 | 4 ++-- src/Widgets/UploadOnSteroids.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 b/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 index 6415986..7a499b1 100644 --- a/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 +++ b/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 @@ -17,7 +17,7 @@
    files as $key => $file): ?> -
  • +
  • showThumbnail): ?> ', @@ -26,7 +26,7 @@ $file['thumbnail']['height'], $file['name'] ) ?> -

    +
    diff --git a/src/Widgets/UploadOnSteroids.php b/src/Widgets/UploadOnSteroids.php index 06cf533..0d0eec8 100644 --- a/src/Widgets/UploadOnSteroids.php +++ b/src/Widgets/UploadOnSteroids.php @@ -285,7 +285,7 @@ private function validateMultipleUpload(): void } $inputName = $this->name; - $values = \array_map('\Contao\StringUtil::binToUuid', $this->value); + $values = \array_map('\Contao\StringUtil::binToUuid', (array) $this->value); $files = []; $inputFiles = $this->getMultipleUploadedFiles(); @@ -367,7 +367,7 @@ private function deselectFile(string $inputName): void return; } - $values = \array_map('\Contao\StringUtil::binToUuid', $this->value); + $values = \array_map('\Contao\StringUtil::binToUuid', (array) $this->value); $diffValues = \array_values(\array_diff($values, $post['reset'])); $this->value = \array_map('\Contao\StringUtil::uuidToBin', $diffValues); @@ -408,7 +408,7 @@ private function deleteFile(string $inputName): void return; } - $values = \array_map('\Contao\StringUtil::binToUuid', $this->value); + $values = \array_map('\Contao\StringUtil::binToUuid', (array) $this->value); $diffValues = \array_values(\array_diff($values, $post['delete'])); foreach ($post['delete'] as $delete) { From 5fc2a612854b2e0386ce36714ec744228f58f9d0 Mon Sep 17 00:00:00 2001 From: Ingolf Steinardt Date: Mon, 29 Jul 2024 20:35:05 +0200 Subject: [PATCH 7/7] Fix PHPCQ & file upload --- composer.json | 3 +- src/Resources/config/listeners.yml | 5 +- .../contao/templates/dcfe_general_edit.html5 | 37 +++-- .../widgets/form_upload-on-steroids.html5 | 8 +- src/View/DefaultWidgetBuilder.php | 27 +++- src/Widgets/UploadOnSteroids.php | 152 +++++++++--------- 6 files changed, 131 insertions(+), 101 deletions(-) diff --git a/composer.json b/composer.json index f07fd4a..71b490e 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,8 @@ }, "extra": { "branch-alias": { - "dev-feature/2.3.0": "2.3.x-dev" + "dev-feature/2.3.0": "2.3.x-dev", + "dev-hotfix/update_phpcq": "2.3.x-dev" }, "contao-manager-plugin": "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\ContaoManager\\Plugin" } diff --git a/src/Resources/config/listeners.yml b/src/Resources/config/listeners.yml index afd0d78..723936e 100644 --- a/src/Resources/config/listeners.yml +++ b/src/Resources/config/listeners.yml @@ -1,10 +1,11 @@ services: cca.dc-general.contao_frontend.view.build_widget_listener: class: ContaoCommunityAlliance\DcGeneral\ContaoFrontend\View\DefaultWidgetBuilder - tags: - - { name: kernel.event_listener, event: 'dc-general.contao-frontend.build-widget', method: handleEvent } arguments: - '@cca.dc-general.scope-matcher' + - '@translator' + tags: + - { name: kernel.event_listener, event: 'dc-general.contao-frontend.build-widget', method: handleEvent } cca.dc-general.contao_frontend.handle_submit_listener: class: ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Listener\HandleSubmitListener diff --git a/src/Resources/contao/templates/dcfe_general_edit.html5 b/src/Resources/contao/templates/dcfe_general_edit.html5 index 0e4d400..bb015a8 100644 --- a/src/Resources/contao/templates/dcfe_general_edit.html5 +++ b/src/Resources/contao/templates/dcfe_general_edit.html5 @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/dc-general-contao-frontend. * - * (c) 2015-2021 Contao Community Alliance. + * (c) 2015-2024 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,40 +13,45 @@ * @package contao-community-alliance/dc-general-contao-frontend * @author Christian Schiffler * @author Ingolf Steinhardt - * @copyright 2015-2021 Contao Community Alliance. + * @copyright 2015-2024 Contao Community Alliance. * @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0 * @filesource */ + +use Contao\StringUtil; +use Contao\System; + +$requestToken = System::getContainer()->get('contao.csrf.token_manager')->getDefaultTokenValue(); ?>

    subHeadline; ?>

    -getMessages(); ?> +getMessages() ?>
    - - - error): ?>

    ', $this->error); ?>

    + + + error): ?>

    ', $this->error) ?>

    fieldsets as $arrFieldset): ?> -
    - - +
    + +
    -
    - +
    +
    - editButtons); ?> + editButtons) ?>
    diff --git a/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 b/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 index 7a499b1..f909006 100644 --- a/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 +++ b/src/Resources/contao/templates/widgets/form_upload-on-steroids.html5 @@ -35,17 +35,15 @@ deselect): ?>
    -
    delete): ?>
    - - trans('MSC.delete') ?> +
    diff --git a/src/View/DefaultWidgetBuilder.php b/src/View/DefaultWidgetBuilder.php index 60c503e..04ec1d6 100644 --- a/src/View/DefaultWidgetBuilder.php +++ b/src/View/DefaultWidgetBuilder.php @@ -21,6 +21,7 @@ namespace ContaoCommunityAlliance\DcGeneral\ContaoFrontend\View; +use Contao\System; use Contao\Widget; use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents; use ContaoCommunityAlliance\Contao\Bindings\Events\Widget\GetAttributesFromDcaEvent; @@ -35,6 +36,7 @@ use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\PropertyInterface; use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface; use Psr\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Widget Builder to build Contao frontend widgets. @@ -51,14 +53,23 @@ class DefaultWidgetBuilder */ private RequestScopeDeterminator $scopeDeterminator; + /** + * The translator. + * + * @var TranslatorInterface + */ + private TranslatorInterface $translator; + /** * DefaultWidgetBuilder constructor. * * @param RequestScopeDeterminator $scopeDeterminator The request scope determinator. + * @param TranslatorInterface $translator The translator. */ - public function __construct(RequestScopeDeterminator $scopeDeterminator) + public function __construct(RequestScopeDeterminator $scopeDeterminator, TranslatorInterface $translator) { $this->scopeDeterminator = $scopeDeterminator; + $this->translator = $translator; } /** @@ -159,12 +170,18 @@ public function buildWidget( $propExtra['class'] = $this->addCssClass($propExtra['class'], $propExtra['tl_class']); } + // If no description present, pass as string instead of array. + $label = $this->translator->trans($property->getLabel(), [], $defName); + if ('' !== $description = $property->getDescription()) { + $label = [ + $label, + $this->translator->trans($description, [], $defName), + ]; + } + $arrConfig = [ 'inputType' => $property->getWidgetType(), - 'label' => [ - $property->getLabel(), - $property->getDescription() - ], + 'label' => $label, 'options' => $this->getOptionsForWidget($environment, $property, $model), 'eval' => $propExtra, ]; diff --git a/src/Widgets/UploadOnSteroids.php b/src/Widgets/UploadOnSteroids.php index 0d0eec8..780b83a 100644 --- a/src/Widgets/UploadOnSteroids.php +++ b/src/Widgets/UploadOnSteroids.php @@ -22,6 +22,7 @@ namespace ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Widgets; use Contao\Controller; +use Contao\CoreBundle\Image\ImageFactory; use Contao\CoreBundle\Slug\Slug as SlugGenerator; use Contao\CoreBundle\Framework\Adapter; use Contao\Dbafs; @@ -34,8 +35,9 @@ use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -93,46 +95,46 @@ class UploadOnSteroids extends FormFileUpload protected $strPrefix = 'widget widget-upload widget-upload-on-steroids'; /** - * Image sizes. + * Image sizes as serialisized string. * - * @var array + * @var string */ - protected $imageSize; + protected string $imageSize; /** * The translator. * - * @var TranslatorInterface + * @var TranslatorInterface|null */ - protected $translator; + protected ?TranslatorInterface $translator = null; /** * The input provider. * - * @var Adapter|Input + * @var Adapter */ - protected $inputProvider; + protected ?Adapter $inputProvider = null; /** * The file model. * - * @var Adapter|FilesModel + * @var Adapter|null */ - private Adapter|FilesModel $filesModel; + private ?Adapter $filesModel = null; /** * The filesystem. * - * @var Filesystem + * @var Filesystem|null */ - private Filesystem $filesystem; + private ?Filesystem $filesystem = null; /** * The slug generator. * - * @var SlugGenerator + * @var SlugGenerator|null */ - private SlugGenerator $slugGenerator; + private ?SlugGenerator $slugGenerator = null; /** * {@inheritDoc} @@ -175,7 +177,6 @@ public function parse($arrAttributes = null) $this->addIsDeselectable(); $this->addIsMultiple(); $this->addShowThumbnail(); - $this->getImageSize(); $this->addFiles($this->sortBy); $this->value = \implode(',', \array_map('\Contao\StringUtil::binToUuid', (array) $this->value)); @@ -230,7 +231,6 @@ public function validate(): void $this->uploadFolder = $newUploadFolder?->uuid ?? ''; } - /** @psalm-suppress DeprecatedMethod */ $this->validateSingleUpload(); $this->validateMultipleUpload(); $this->deselectFile($inputName); @@ -244,8 +244,6 @@ public function validate(): void * * @throws \Exception * @SuppressWarnings(PHPMD.Superglobals) - * - * @deprecated Use multiple upload. */ private function validateSingleUpload(): void { @@ -355,20 +353,19 @@ private function deselectFile(string $inputName): void if ( !$this->deselect || $this->hasErrors() - || !($post = $this->inputProvider()->post($inputName)) - || !isset($post['reset'][0]) + || [] === ($post = (array) ($this->getCurrentRequest()?->request->get($inputName . '__reset') ?? [])) ) { return; } - if (!$this->multiple && (StringUtil::binToUuid($this->value) === $post['reset'][0])) { + if (!$this->multiple && (StringUtil::binToUuid($this->value) === $post[0])) { $this->value = ''; return; } $values = \array_map('\Contao\StringUtil::binToUuid', (array) $this->value); - $diffValues = \array_values(\array_diff($values, $post['reset'])); + $diffValues = \array_values(\array_diff($values, $post)); $this->value = \array_map('\Contao\StringUtil::uuidToBin', $diffValues); } @@ -388,32 +385,30 @@ private function deleteFile(string $inputName): void if ( !$this->delete || $this->hasErrors() - || !($post = $this->inputProvider()->post($inputName)) - || !isset($post['delete'][0]) + || [] === ($post = (array) ($this->getCurrentRequest()?->request->get($inputName . '__delete') ?? [])) ) { return; } - if (!$this->multiple && (StringUtil::binToUuid($this->value) === $post['delete'][0])) { - $this->value = ''; - + if (!$this->multiple && (StringUtil::binToUuid($this->value) === $post[0])) { /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ $file = $this->filesModel()->findByUuid($this->value); if (null !== $file) { - $this->filesystem->remove($file->path); + $this->filesystem()->remove($file->path); $file->delete(); Dbafs::deleteResource($file->path); } + $this->value = ''; return; } $values = \array_map('\Contao\StringUtil::binToUuid', (array) $this->value); - $diffValues = \array_values(\array_diff($values, $post['delete'])); + $diffValues = \array_values(\array_diff($values, $post)); - foreach ($post['delete'] as $delete) { + foreach ($post as $delete) { /** @psalm-suppress InternalMethod - Class ContaoFramework is internal, not the getAdapter() method. */ - $file = $this->filesModel()->findByUuid(StringUtil::uuidToBin($delete)); + $file = $this->filesModel()->findByUuid(StringUtil::uuidToBin((string) $delete)); if (null === $file) { continue; } @@ -499,9 +494,7 @@ private function addFiles($sortBy): void /** @var Connection $connection */ $connection = self::getContainer()->get('database_connection'); - - $platform = $connection->getDatabasePlatform(); - $builder = $connection->createQueryBuilder(); + $builder = $connection->createQueryBuilder(); switch ($sortBy) { case 'name_desc': @@ -523,24 +516,24 @@ private function addFiles($sortBy): void $builder ->select( - $platform->quoteIdentifier('id'), - $platform->quoteIdentifier('pid'), - $platform->quoteIdentifier('tstamp'), - $platform->quoteIdentifier('uuid'), - $platform->quoteIdentifier('type'), - $platform->quoteIdentifier('path'), - $platform->quoteIdentifier('extension'), - $platform->quoteIdentifier('hash'), - $platform->quoteIdentifier('found'), - $platform->quoteIdentifier('name'), - $platform->quoteIdentifier('importantPartX'), - $platform->quoteIdentifier('importantPartY'), - $platform->quoteIdentifier('importantPartWidth'), - $platform->quoteIdentifier('importantPartHeight'), - $platform->quoteIdentifier('meta') + 't.id', + 't.pid', + 't.tstamp', + 't.uuid', + 't.type', + 't.path', + 't.extension', + 't.hash', + 't.found', + 't.name', + 't.importantPartX', + 't.importantPartY', + 't.importantPartWidth', + 't.importantPartHeight', + 't.meta' ) - ->from($platform->quoteIdentifier('tl_files')) - ->where($builder->expr()->in($platform->quoteIdentifier('uuid'), ':uuids')) + ->from('tl_files', 't') + ->where($builder->expr()->in('t.uuid', ':uuids')) ->setParameter('uuids', (array) $this->value, ArrayParameterType::STRING); $statement = $builder->executeQuery(); @@ -560,12 +553,14 @@ private function addFiles($sortBy): void $container = System::getContainer(); $projectDir = $container->getParameter('kernel.project_dir'); assert(\is_string($projectDir)); + $imageFactory = $container->get('contao.image.image_factory'); + assert($imageFactory instanceof ImageFactory); foreach ($statement->fetchAllAssociative() as $file) { if (null === ($objFile = FilesModel::findByUuid($file['uuid']))) { continue; } - $src = $container->get('contao.image.image_factory') - ?->create($projectDir . '/' . rawurldecode($objFile->path), $this->imageSize) + $src = $imageFactory + ->create($projectDir . '/' . rawurldecode($objFile->path), $this->imageSize) ->getUrl($projectDir); $objThumbnailFile = new File(rawurldecode($src)); @@ -646,23 +641,28 @@ private function addIsMultiple(): void $this->addAttribute('multiple', 'multiple'); } - /** - * Get the input provider. - * - * @return Adapter|Input - */ - private function inputProvider(): Input|Adapter + private function getCurrentRequest(): ?Request { - return $this->inputProvider; + $requestStack = \Contao\System::getContainer()->get('request_stack'); + if (!$requestStack instanceof RequestStack) { + return null; + } + return $requestStack->getCurrentRequest(); } /** * Get the files model. * - * @return Adapter|FilesModel + * @return Adapter */ - private function filesModel(): FilesModel|Adapter + private function filesModel(): Adapter { + if (null === $this->filesModel) { + $filesModel = self::getContainer()->get('contao.framework')?->getAdapter(FilesModel::class); + assert($filesModel instanceof Adapter); + $this->filesModel = $filesModel; + } + return $this->filesModel; } @@ -673,6 +673,12 @@ private function filesModel(): FilesModel|Adapter */ private function filesystem(): Filesystem { + if (null === $this->filesystem) { + $filesystem = self::getContainer()->get('filesystem'); + assert($filesystem instanceof Filesystem); + $this->filesystem = $filesystem; + } + return $this->filesystem; } @@ -683,6 +689,12 @@ private function filesystem(): Filesystem */ private function slugGenerator(): SlugGenerator { + if (null === $this->slugGenerator) { + $slugGenerator = System::getContainer()->get('contao.slug'); + assert($slugGenerator instanceof SlugGenerator); + $this->slugGenerator = $slugGenerator; + } + return $this->slugGenerator; } @@ -703,16 +715,12 @@ protected function getSlugOptions(): array */ private function translator(): TranslatorInterface { - return $this->translator; - } + if (null === $this->translator) { + $translator = self::getContainer()->get('translator'); + assert($translator instanceof TranslatorInterface); + $this->translator = $translator; + } - /** - * Get the image sizes. - * - * @return void - */ - private function getImageSize(): void - { - $this->imageSize = StringUtil::deserialize($this->imageSize, true); + return $this->translator; } }