diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml
index 598eb31..2a0c113 100644
--- a/.github/workflows/diagnostics.yml
+++ b/.github/workflows/diagnostics.yml
@@ -23,10 +23,13 @@ jobs:
- php: 8.2
output: '-o github-action -o default'
phpcq_install: 'update'
+ - php: 8.3
+ output: '-o github-action -o default'
+ phpcq_install: 'update'
steps:
- name: Pull source
- uses: actions/checkout@v2
+ uses: actions/checkout@v4
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
@@ -34,7 +37,7 @@ jobs:
php-version: ${{ matrix.php }}
- name: Cache composer cache directory
- uses: actions/cache@v1
+ uses: actions/cache@v4
env:
cache-name: composer-cache-dir-${{ matrix.php }}
with:
@@ -42,7 +45,7 @@ jobs:
key: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Cache phpcq directory
- uses: actions/cache@v1
+ uses: actions/cache@v4
env:
cache-name: phpcq-${{ matrix.php }}
with:
@@ -74,7 +77,7 @@ jobs:
run: ./vendor/bin/phpcq run -v ${{ matrix.output }}
- name: Upload build directory to artifact
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v4
if: ${{ success() }} || ${{ failure() }}
with:
name: phpcq-builds-php-${{ matrix.php }}
diff --git a/.phpcq.lock b/.phpcq.lock
index 5ad3349..e6dd83b 100644
--- a/.phpcq.lock
+++ b/.phpcq.lock
@@ -1 +1 @@
-{"plugins":{"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.21.1","url":"https://github.com/vimeo/psalm/releases/download/5.21.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.21.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":"4.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.8.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.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.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},"phpspec":{"api-version":"1.0.0","version":"1.0.0","type":"php-file","url":"./vendor/netzmacht/phpspec-phpcq-plugin/src/phpspec-plugin.php","signature":null,"requirements":{},"checksum":{"type":"sha-512","value":"ad3a8fc0c07f59ad5f522e08d9ebafccb2a215d43c7a4ca8e96b2b05675f00a409406d0ec3c42a0cdf394d98d3d60c747a4d81477f8691cef1eef269fc4b0b8f"},"tools":{},"composerLock":null}},"tools":[]}
\ No newline at end of file
+{"plugins":{"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.26.1","url":"https://github.com/vimeo/psalm/releases/download/5.26.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.26.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":"4.12.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.12.0/composer-require-checker.phar","requirements":{"php":{"php":"~8.2.0 || ~8.3.0 || ~8.4.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.12.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},"phpspec":{"api-version":"1.0.0","version":"1.0.0","type":"php-file","url":"./vendor/netzmacht/phpspec-phpcq-plugin/src/phpspec-plugin.php","signature":null,"requirements":{},"checksum":{"type":"sha-512","value":"ad3a8fc0c07f59ad5f522e08d9ebafccb2a215d43c7a4ca8e96b2b05675f00a409406d0ec3c42a0cdf394d98d3d60c747a4d81477f8691cef1eef269fc4b0b8f"},"tools":{},"composerLock":null}},"tools":[]}
\ No newline at end of file
diff --git a/.phpcq.yaml.dist b/.phpcq.yaml.dist
index 02de2bb..438e2c3 100644
--- a/.phpcq.yaml.dist
+++ b/.phpcq.yaml.dist
@@ -47,6 +47,7 @@ phpcq:
- D2CCAC42F6295E7D
# PHP_CodeSniffer
- 31C7E470E2138192
+ - A978220305CD5C32
# Composer normalize
- C00543248C87FB13
# phpmd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9ba4eb..3972e85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,12 @@
## [Unreleased]
+## [1.6.0] - (2024-09-27)
+
+### Added
+
+ - Add support to select a placeholder template
+
## [1.5.0] - (2024-02-07)
### Changed
diff --git a/composer.json b/composer.json
index 6eab3fa..5dd6aa6 100644
--- a/composer.json
+++ b/composer.json
@@ -64,8 +64,8 @@
},
"extra": {
"branch-alias": {
- "dev-develop": "1.6.x-dev",
- "dev-master": "1.5.x-dev"
+ "dev-develop": "1.7.x-dev",
+ "dev-master": "1.6.x-dev"
},
"contao-manager-plugin": "Hofff\\Contao\\Consent\\Bridge\\ContaoManager\\Plugin"
}
diff --git a/psalm.xml b/psalm.xml
index f4c9f70..624bb2d 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -21,7 +21,9 @@
+
+
@@ -34,6 +36,11 @@
+
+
+
+
+
diff --git a/spec/BridgeSpec.php b/spec/BridgeSpec.php
index f601569..bfc840e 100644
--- a/spec/BridgeSpec.php
+++ b/spec/BridgeSpec.php
@@ -95,4 +95,19 @@ public function it_registers_frontend_modules(): void
$this->shouldThrow(UnsupportedFrontendModule::class)->during('frontendModuleRenderInformation', ['c']);
}
+
+ public function it_supports_multiple_render_information(): void
+ {
+ $this->supportContentElement('a', RenderInformation::autoRenderWithPlaceholder('tpl_a'));
+ $this->supportContentElement('a', RenderInformation::autoRenderWithPlaceholder('tpl_b'));
+
+ $this->contentElementRenderInformation('a')->placeholderTemplate()->shouldReturn('tpl_a');
+ $this->contentElementRenderInformation('a', 'tpl_b')->placeholderTemplate()->shouldReturn('tpl_b');
+
+ $this->supportFrontendModule('a', RenderInformation::autoRenderWithPlaceholder('tpl_a'));
+ $this->supportFrontendModule('a', RenderInformation::autoRenderWithPlaceholder('tpl_b'));
+
+ $this->frontendModuleRenderInformation('a')->placeholderTemplate()->shouldReturn('tpl_a');
+ $this->frontendModuleRenderInformation('a', 'tpl_b')->placeholderTemplate()->shouldReturn('tpl_b');
+ }
}
diff --git a/src/Bridge.php b/src/Bridge.php
index aab8b88..824758a 100644
--- a/src/Bridge.php
+++ b/src/Bridge.php
@@ -22,10 +22,10 @@ final class Bridge
*/
private array $consentIds = [];
- /** @var array */
+ /** @var array> */
private array $elements = [];
- /** @var array */
+ /** @var array> */
private array $modules = [];
/** @param Plugin[] $plugins */
@@ -55,14 +55,14 @@ public function registerConsentId(string ...$consentIdClasses): self
public function supportContentElement(string $type, RenderInformation $renderInformation): self
{
- $this->elements[$type] = $renderInformation;
+ $this->elements[$type][] = $renderInformation;
return $this;
}
public function supportFrontendModule(string $type, RenderInformation $renderInformation): self
{
- $this->modules[$type] = $renderInformation;
+ $this->modules[$type][] = $renderInformation;
return $this;
}
@@ -105,13 +105,21 @@ public function supportsContentElement(string $type): bool
return isset($this->elements[$type]);
}
- public function contentElementRenderInformation(string $type): RenderInformation
- {
+ public function contentElementRenderInformation(
+ string $type,
+ string|null $placeholderTemplate = null,
+ ): RenderInformation {
if (! isset($this->elements[$type])) {
throw UnsupportedContentElement::ofType($type);
}
- return $this->elements[$type];
+ return $this->determineBestMatchingRenderInformation($this->elements[$type], $placeholderTemplate);
+ }
+
+ /** @return list */
+ public function contentElementPlaceholderTemplates(string $type): array
+ {
+ return $this->extractPlaceholderTemplates($this->elements[$type] ?? []);
}
public function supportsFrontendModule(string $type): bool
@@ -119,12 +127,57 @@ public function supportsFrontendModule(string $type): bool
return isset($this->modules[$type]);
}
- public function frontendModuleRenderInformation(string $type): RenderInformation
- {
+ public function frontendModuleRenderInformation(
+ string $type,
+ string|null $placeholderTemplate = null,
+ ): RenderInformation {
if (! isset($this->modules[$type])) {
throw UnsupportedFrontendModule::ofType($type);
}
- return $this->modules[$type];
+ return $this->determineBestMatchingRenderInformation($this->modules[$type], $placeholderTemplate);
+ }
+
+ /** @return list */
+ public function frontendModulePlaceholderTemplates(string $type): array
+ {
+ return $this->extractPlaceholderTemplates($this->modules[$type] ?? []);
+ }
+
+ /** @param non-empty-list $collection */
+ private function determineBestMatchingRenderInformation(
+ array $collection,
+ string|null $placeholderTemplate = null,
+ ): RenderInformation {
+ foreach ($collection as $renderInformation) {
+ if ($renderInformation->placeholderTemplate() !== $placeholderTemplate) {
+ continue;
+ }
+
+ return $renderInformation;
+ }
+
+ return $collection[0];
+ }
+
+ /**
+ * @param list $collection
+ *
+ * @return list
+ */
+ private function extractPlaceholderTemplates(array $collection): array
+ {
+ $templates = [];
+
+ foreach ($collection as $renderInformation) {
+ $template = $renderInformation->placeholderTemplate();
+ if ($template === null) {
+ continue;
+ }
+
+ $templates[] = $template;
+ }
+
+ return $templates;
}
}
diff --git a/src/EventListener/Dca/ContentDcaListener.php b/src/EventListener/Dca/ContentDcaListener.php
index e9607cb..0a492a3 100644
--- a/src/EventListener/Dca/ContentDcaListener.php
+++ b/src/EventListener/Dca/ContentDcaListener.php
@@ -7,6 +7,7 @@
use Contao\BackendUser;
use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\DataContainer\PaletteNotFoundException;
+use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\CoreBundle\Framework\Adapter;
use Contao\DataContainer;
use Contao\Input;
@@ -17,10 +18,14 @@
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
+use function is_string;
final class ContentDcaListener
{
- /** @param Adapter $messageAdapter */
+ /**
+ * @param Adapter $messageAdapter
+ * @param Adapter $inputAdapter
+ */
public function __construct(
private readonly Bridge $bridge,
private readonly ConsentToolManager $consentToolManager,
@@ -28,18 +33,40 @@ public function __construct(
private readonly TranslatorInterface $translator,
private readonly BackendUser $backendUser,
private readonly Adapter $messageAdapter,
+ private readonly Adapter $inputAdapter,
) {
}
- public function initializePalettes(): void
+ public function initializePalettes(DataContainer $dataContainer): void
{
if (count($this->consentToolManager->consentTools()) === 0) {
return;
}
+ $fields = ['hofff_consent_bridge_tag'];
+
+ if ($this->inputAdapter->get('act') === 'edit') {
+ $result = $this->connection->executeQuery(
+ 'SELECT type FROM tl_content WHERE id=:id LIMIT 0,1',
+ ['id' => $dataContainer->id],
+ );
+
+ /** @psalm-var string|false $type */
+ $type = $result->fetchOne();
+
+ if (is_string($type)) {
+ $placeholderTemplates = $this->bridge->contentElementPlaceholderTemplates($type);
+ if (count($placeholderTemplates) > 0) {
+ $fields[] = 'hofff_consent_bridge_placeholder_template';
+ }
+ }
+ } else {
+ $fields[] = 'hofff_consent_bridge_placeholder_template';
+ }
+
$paletteManipulator = PaletteManipulator::create()
->addLegend('hofff_consent_bridge_legend', 'expert_legend')
- ->addField('hofff_consent_bridge_tag', 'hofff_consent_bridge_legend', PaletteManipulator::POSITION_APPEND);
+ ->addField($fields, 'hofff_consent_bridge_legend', PaletteManipulator::POSITION_APPEND);
foreach ($this->bridge->supportedContentElements() as $element) {
try {
@@ -80,4 +107,21 @@ public function showConsentInfo(DataContainer $dataContainer): void
[$this->translator->trans('tl_content.hofff_consent_bridge_tag_missing', [], 'contao_tl_content')],
);
}
+
+ /** @return list */
+ #[AsCallback('tl_content', 'fields.hofff_consent_bridge_placeholder_template.options')]
+ public function placeholderTemplate(DataContainer $dataContainer): array
+ {
+ /**
+ * @psalm-var string|null $type
+ * @psalm-suppress UndefinedMagicPropertyFetch
+ * @psalm-suppress MixedPropertyFetch
+ */
+ $type = $dataContainer->activeRecord?->type;
+ if ($type === null) {
+ return [];
+ }
+
+ return $this->bridge->contentElementPlaceholderTemplates($type);
+ }
}
diff --git a/src/EventListener/Dca/ModuleDcaListener.php b/src/EventListener/Dca/ModuleDcaListener.php
index 80f8717..0d62767 100644
--- a/src/EventListener/Dca/ModuleDcaListener.php
+++ b/src/EventListener/Dca/ModuleDcaListener.php
@@ -7,6 +7,7 @@
use Contao\BackendUser;
use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\DataContainer\PaletteNotFoundException;
+use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\CoreBundle\Framework\Adapter;
use Contao\DataContainer;
use Contao\Input;
@@ -17,10 +18,14 @@
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
+use function is_string;
final class ModuleDcaListener
{
- /** @param Adapter $messageAdapter */
+ /**
+ * @param Adapter $messageAdapter
+ * @param Adapter $inputAdapter
+ */
public function __construct(
private readonly Bridge $bridge,
private readonly ConsentToolManager $consentToolManager,
@@ -28,18 +33,40 @@ public function __construct(
private readonly TranslatorInterface $translator,
private readonly BackendUser $backendUser,
private readonly Adapter $messageAdapter,
+ private readonly Adapter $inputAdapter,
) {
}
- public function initializePalettes(): void
+ public function initializePalettes(DataContainer $dataContainer): void
{
if (count($this->consentToolManager->consentTools()) === 0) {
return;
}
+ $fields = ['hofff_consent_bridge_tag'];
+
+ if ($this->inputAdapter->get('act') === 'edit') {
+ $result = $this->connection->executeQuery(
+ 'SELECT type FROM tl_module WHERE id=:id LIMIT 0,1',
+ ['id' => $dataContainer->id],
+ );
+
+ /** @psalm-var string|false $type */
+ $type = $result->fetchOne();
+
+ if (is_string($type)) {
+ $placeholderTemplates = $this->bridge->frontendModulePlaceholderTemplates($type);
+ if (count($placeholderTemplates) > 0) {
+ $fields[] = 'hofff_consent_bridge_placeholder_template';
+ }
+ }
+ } else {
+ $fields[] = 'hofff_consent_bridge_placeholder_template';
+ }
+
$paletteManipulator = PaletteManipulator::create()
->addLegend('hofff_consent_bridge_legend', 'expert_legend')
- ->addField('hofff_consent_bridge_tag', 'hofff_consent_bridge_legend', PaletteManipulator::POSITION_APPEND);
+ ->addField($fields, 'hofff_consent_bridge_legend', PaletteManipulator::POSITION_APPEND);
foreach ($this->bridge->supportedFrontendModules() as $module) {
try {
@@ -80,4 +107,21 @@ public function showConsentInfo(DataContainer $dataContainer): void
[$this->translator->trans('tl_content.hofff_consent_bridge_tag_missing', [], 'contao_tl_content')],
);
}
+
+ /** @return list */
+ #[AsCallback('tl_module', 'fields.hofff_consent_bridge_placeholder_template.options')]
+ public function placeholderTemplates(DataContainer $dataContainer): array
+ {
+ /**
+ * @psalm-var string|null $type
+ * @psalm-suppress UndefinedMagicPropertyFetch
+ * @psalm-suppress MixedPropertyFetch
+ */
+ $type = $dataContainer->activeRecord?->type;
+ if ($type === null) {
+ return [];
+ }
+
+ return $this->bridge->frontendModulePlaceholderTemplates($type);
+ }
}
diff --git a/src/EventListener/Hook/RenderComponentsListener.php b/src/EventListener/Hook/RenderComponentsListener.php
index 66ff6fd..6f56fbf 100644
--- a/src/EventListener/Hook/RenderComponentsListener.php
+++ b/src/EventListener/Hook/RenderComponentsListener.php
@@ -43,7 +43,11 @@ public function onGetContentElement(ContentModel $contentModel, string $buffer):
return $buffer;
}
- $renderInformation = $this->bridge->contentElementRenderInformation($contentModel->type);
+ /** @psalm-suppress MixedArgument */
+ $renderInformation = $this->bridge->contentElementRenderInformation(
+ $contentModel->type,
+ $contentModel->hofff_consent_bridge_placeholder_template,
+ );
return $this->renderContent(
$buffer,
@@ -66,7 +70,11 @@ public function onGetFrontendModule(ModuleModel $moduleModel, string $buffer): s
return $buffer;
}
- $renderInformation = $this->bridge->frontendModuleRenderInformation($moduleModel->type);
+ /** @psalm-suppress MixedArgument */
+ $renderInformation = $this->bridge->frontendModuleRenderInformation(
+ $moduleModel->type,
+ $moduleModel->hofff_consent_bridge_placeholder_template,
+ );
return $this->renderContent(
$buffer,
diff --git a/src/Resources/config/listener.xml b/src/Resources/config/listener.xml
index ba0a58c..e7b6332 100644
--- a/src/Resources/config/listener.xml
+++ b/src/Resources/config/listener.xml
@@ -5,7 +5,7 @@
https://symfony.com/schema/dic/services/services-1.0.xsd">
-
+
@@ -50,6 +50,7 @@
+
@@ -59,6 +60,7 @@
+
diff --git a/src/Resources/contao/dca/tl_content.php b/src/Resources/contao/dca/tl_content.php
index 52e32ef..13fe039 100644
--- a/src/Resources/contao/dca/tl_content.php
+++ b/src/Resources/contao/dca/tl_content.php
@@ -9,7 +9,6 @@
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = [ContentDcaListener::class, 'showConsentInfo'];
$GLOBALS['TL_DCA']['tl_content']['fields']['hofff_consent_bridge_tag'] = [
- 'label' => &$GLOBALS['TL_LANG']['tl_content']['hofff_consent_bridge_tag'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => [ConsentIdOptions::class, '__invoke'],
@@ -21,3 +20,15 @@
],
'sql' => ['type' => 'string', 'default' => null, 'notnull' => false],
];
+
+$GLOBALS['TL_DCA']['tl_content']['fields']['hofff_consent_bridge_placeholder_template'] = [
+ 'exclude' => true,
+ 'inputType' => 'select',
+ 'eval' => [
+ 'tl_class' => 'w50',
+ 'includeBlankOption' => true,
+ 'chosen' => true,
+ 'multiple' => false,
+ ],
+ 'sql' => ['type' => 'string', 'length' => 255, 'default' => null, 'notnull' => false],
+];
diff --git a/src/Resources/contao/dca/tl_module.php b/src/Resources/contao/dca/tl_module.php
index 42836f0..7ec716a 100644
--- a/src/Resources/contao/dca/tl_module.php
+++ b/src/Resources/contao/dca/tl_module.php
@@ -22,3 +22,15 @@
],
'sql' => ['type' => 'string', 'default' => null, 'notnull' => false],
];
+
+$GLOBALS['TL_DCA']['tl_module']['fields']['hofff_consent_bridge_placeholder_template'] = [
+ 'exclude' => true,
+ 'inputType' => 'select',
+ 'eval' => [
+ 'tl_class' => 'w50',
+ 'includeBlankOption' => true,
+ 'chosen' => true,
+ 'multiple' => false,
+ ],
+ 'sql' => ['type' => 'string', 'length' => 255, 'default' => null, 'notnull' => false],
+];
diff --git a/src/Resources/contao/languages/de/tl_content.xlf b/src/Resources/contao/languages/de/tl_content.xlf
index b19586b..535f9f4 100644
--- a/src/Resources/contao/languages/de/tl_content.xlf
+++ b/src/Resources/contao/languages/de/tl_content.xlf
@@ -14,6 +14,14 @@
Bitte weisen Sie einen Datenverarbeitungsservice zu, für den die Einwillung erteilt werden muss, bevor das Inhaltselement angezeigt wird.
+
+
+ Benutzerdefinierte Platzhalter-Template
+
+
+
+ Sie können eine benutzerdefinierte Platzhalter-Template auswählen.
+
Es wurde kein Datenverarbeitungsservice konfiguriert. Bitte überprüfen Sie ob einer zugewiesen werden muss.
diff --git a/src/Resources/contao/languages/de/tl_module.xlf b/src/Resources/contao/languages/de/tl_module.xlf
index f9f0ada..d42f002 100644
--- a/src/Resources/contao/languages/de/tl_module.xlf
+++ b/src/Resources/contao/languages/de/tl_module.xlf
@@ -14,6 +14,14 @@
Bitte weisen Sie einen Datenverarbeitungsservice zu, für den die Einwillung erteilt werden muss, bevor das Frontendmodul ausgegeben wird.
+
+
+ Benutzerdefinierte Platzhalter-Template
+
+
+
+ Sie können eine benutzerdefinierte Platzhalter-Template auswählen.
+
Es wurde kein Datenverarbeitungsservice konfiguriert. Bitte überprüfen Sie ob einer zugewiesen werden muss.
diff --git a/src/Resources/contao/languages/en/tl_content.xlf b/src/Resources/contao/languages/en/tl_content.xlf
index c638396..0a1edd8 100644
--- a/src/Resources/contao/languages/en/tl_content.xlf
+++ b/src/Resources/contao/languages/en/tl_content.xlf
@@ -11,6 +11,12 @@
+
+
+
+
+
+
diff --git a/src/Resources/contao/languages/en/tl_module.xlf b/src/Resources/contao/languages/en/tl_module.xlf
index 9a9670a..7553f53 100644
--- a/src/Resources/contao/languages/en/tl_module.xlf
+++ b/src/Resources/contao/languages/en/tl_module.xlf
@@ -11,6 +11,12 @@
+
+
+
+
+
+