Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,26 @@ Exposes Consent Manager's startup data. This is for internal use; extension inte

For extensions or templates that render iframe-based external media **outside** phpBB's bbcode engine, only output the deferred Consent Manager wrapper when the embedded media category is enabled. Otherwise, keep rendering the normal iframe.

Twig example:
Let's look at how we would handle the following iframe:

```html
<iframe src="https://media.example.com/embed/123" width="640" height="360" allowfullscreen></iframe>
```

### Pattern 1: Twig template example

```twig
{% if S_CONSENTMANAGER_MEDIA_ENABLED %}
<span data-consent-media-container="1" data-consent-category="media">
<span data-consent-media-placeholder="1" data-consent-link="https://media.example.com/watch/123"></span>
<span data-consent-media-content="1" hidden="hidden">
<iframe
data-consent-media-frame="1"
data-consent-src="https://media.example.com/embed/123"
width="640"
height="360"
allowfullscreen></iframe>
</span>
<iframe
data-consent-media-content="1"
data-consent-media-frame="1"
hidden="hidden"
data-consent-src="https://media.example.com/embed/123"
width="640"
height="360"
allowfullscreen></iframe>
</span>
{% else %}
<iframe
Expand All @@ -611,7 +617,30 @@ Use this pattern for:

- extension template files that print iframes directly
- integrations that embed third-party widgets with raw iframes instead of bbcode
- custom board markup where iframes were added manually, whether by editing phpBB files directly or through another extension that allows custom HTML/Twig
- custom markup where iframes were added manually, whether by editing phpBB files directly or through an extension that allows Twig template code injection

### Pattern 2: Manual markup

Use this when the iframe is injected outside phpBB's Twig template system, and you know Consent Manager is installed with the embedded media category enabled. This pattern does not include a fallback because static non-Twig HTML cannot check `S_CONSENTMANAGER_MEDIA_ENABLED`.

```html
<span data-consent-media-container="1" data-consent-category="media">
<span data-consent-media-placeholder="1" data-consent-link="https://media.example.com/watch/123"></span>
<iframe
data-consent-media-frame="1"
data-consent-media-content="1"
hidden="hidden"
data-consent-src="https://media.example.com/embed/123"
width="640"
height="360"
allowfullscreen></iframe>
</span>
```

Use this pattern for:

- ACP/custom-code features that inject raw HTML into pages
- integrations that output iframe markup after phpBB's bbcode and Twig rendering have already finished

## Examples of Consent Manager integrations

Expand Down
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<delete file="${dir}/package-lock.json" />
<delete file="${dir}/phpunit.xml.dist" />
<delete file="${dir}/README.md" />
<delete file="${dir}/DOCUMENTATION.md" />
</target>

<!--
Expand Down
2 changes: 1 addition & 1 deletion event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ public function inject_frontend()
*/
protected function is_acp_or_installer()
{
return defined('ADMIN_START') || defined('IN_INSTALL');
return defined('IN_ADMIN') || defined('IN_INSTALL');
}
}
9 changes: 8 additions & 1 deletion tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ public function test_inject_frontend_skips_category_blocks_when_frontend_disable
$template->expects(self::never())
->method('assign_block_vars');

$this->create_listener($helper, $consent_manager, $template)->inject_frontend();
$listener = new class($helper, $this->language, $consent_manager, $template, $this->media_manager) extends \phpbb\consentmanager\event\listener {
protected function is_acp_or_installer()
{
return false;
}
};

$listener->inject_frontend();
}
}
Loading