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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
},
"require": {
"php": "^8.2",
"croct/plug-php": "0.1.0",
"croct/plug-symfony": "0.1.0"
"croct/plug-php": "0.2.0",
"croct/plug-symfony": "0.2.0"
},
"require-dev": {
"croct/coding-standard": "^0.4.5",
Expand Down
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions croct.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
- '@Drupal\croct\LanguageManagerLocaleResolver'
- null
- '@logger.channel.croct'
- '%croct.debug%'
- 86400
- '@Drupal\croct\AccountIdentityResolver'
tags:
Expand Down
9 changes: 9 additions & 0 deletions src/CroctServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function register(ContainerBuilder $container): void
$container->setParameter('croct.app_id', self::setting('croct.app_id'));
$container->setParameter('croct.api_key', self::setting('croct.api_key'));

// Forwards a debug flag to the browser SDK. Off by default; enable it in settings.php
// (where Drupal's other development toggles live) with $settings['croct.debug'] = true.
$container->setParameter('croct.debug', self::debug());

// The SDK loader is served first-party from croct.script.url through CroctScriptProvider;
// default to the CDN loader, allowing an override (e.g. a pinned version) via settings.
$container->setParameter('croct.script.url', self::scriptUrl());
Expand Down Expand Up @@ -76,4 +80,9 @@ private static function storyblokEnabled(): bool
{
return Settings::get('croct.storyblok.enabled', true) !== false;
}

private static function debug(): bool
{
return Settings::get('croct.debug', false) === true;
}
}
24 changes: 24 additions & 0 deletions tests/CroctServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ public function testBridgesCredentialsFromSettings(): void
self::assertSame('', $container->getParameter('croct.api_key'));
}

#[TestDox('Defaults debug to off.')]
public function testDefaultsDebugOff(): void
{
new Settings([]);

$container = new ContainerBuilder();

(new CroctServiceProvider())->register($container);

self::assertFalse($container->getParameter('croct.debug'));
}

#[TestDox('Enables debug through settings.')]
public function testEnablesDebugThroughSettings(): void
{
new Settings(['croct.debug' => true]);

$container = new ContainerBuilder();

(new CroctServiceProvider())->register($container);

self::assertTrue($container->getParameter('croct.debug'));
}

#[TestDox('Defaults the loader URL to the CDN script.')]
public function testDefaultsScriptUrl(): void
{
Expand Down
Loading