Skip to content

Commit 643c271

Browse files
Move Font Awesome config to .disco-devbar.yaml file for simpler configuration
1 parent 001f811 commit 643c271

File tree

5 files changed

+35
-72
lines changed

5 files changed

+35
-72
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,24 @@ DiscoDevBar supports Font Awesome icons for widgets. You have two options for in
115115

116116
#### Option 1: Automatic Inclusion (Recommended for Quick Setup)
117117

118-
Enable automatic Font Awesome inclusion from CDN by creating `config/packages/disco_dev_bar.yaml`:
118+
Enable automatic Font Awesome inclusion from CDN in your `.disco-devbar.yaml` configuration file:
119119

120120
```yaml
121-
disco_dev_bar:
122-
font_awesome:
123-
enabled: true # Enable auto-include from CDN (default: false)
124-
version: '6.5.1' # Font Awesome version to use (default: '6.5.1')
121+
font_awesome:
122+
enabled: true # Enable auto-include from CDN (default: false)
123+
version: '6.5.1' # Font Awesome version to use (optional, default: 6.5.1)
124+
125+
widgets:
126+
left:
127+
- icon: "fa-flag-checkered"
128+
text: "1.0"
129+
url: "https://github.com/user/repo"
125130
```
126131

127132
**Benefits:**
128133
- Works out of the box - no additional setup needed
129134
- Icons display immediately
135+
- Configuration kept in one place with your widgets
130136

131137
**Note:** Only enable this if your application doesn't already include Font Awesome. If you have Font Awesome in your project, use Option 2 instead to avoid version conflicts.
132138

Resources/config/services.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ services:
1010
MarcinOrlowski\DiscoDevBar\Service\DiscoDevBarService:
1111
arguments:
1212
$projectDir: '%kernel.project_dir%'
13-
$fontAwesomeEnabled: '%disco_dev_bar.font_awesome.enabled%'
14-
$fontAwesomeVersion: '%disco_dev_bar.font_awesome.version%'
1513

1614
MarcinOrlowski\DiscoDevBar\Twig\DiscoDevBarExtension:
1715
tags: ['twig.extension']

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/DependencyInjection/DiscoDevBarExtension.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,11 @@ class DiscoDevBarExtension extends Extension
3434
{
3535
public function load(array $configs, ContainerBuilder $container): void
3636
{
37-
$configuration = new Configuration();
38-
$config = $this->processConfiguration($configuration, $configs);
39-
4037
$loader = new YamlFileLoader(
4138
$container,
4239
new FileLocator(\dirname(__DIR__) . '/../Resources/config')
4340
);
4441

4542
$loader->load('services.yaml');
46-
47-
// Store Font Awesome configuration as parameters for use in Twig
48-
$container->setParameter('disco_dev_bar.font_awesome.enabled', $config['font_awesome']['enabled']);
49-
$container->setParameter('disco_dev_bar.font_awesome.version', $config['font_awesome']['version']);
5043
}
5144
}

src/Service/DiscoDevBarService.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ class DiscoDevBarService
3636
'.debug-banner.yaml', // Legacy, kept for backward compatibility
3737
];
3838

39+
/**
40+
* Default Font Awesome version
41+
*/
42+
private const DEFAULT_FONT_AWESOME_VERSION = '6.5.1';
43+
3944
public function __construct(
40-
private readonly string $projectDir,
41-
private readonly bool $fontAwesomeEnabled = false,
42-
private readonly string $fontAwesomeVersion = '6.5.1'
45+
private readonly string $projectDir
4346
) {
4447
}
4548

@@ -59,8 +62,8 @@ public function getDiscoDevBarData(): DiscoDevBarData
5962
hasError: true,
6063
errorMessage: $errorMessage,
6164
version: $version,
62-
fontAwesomeEnabled: $this->fontAwesomeEnabled,
63-
fontAwesomeVersion: $this->fontAwesomeVersion
65+
fontAwesomeEnabled: false,
66+
fontAwesomeVersion: self::DEFAULT_FONT_AWESOME_VERSION
6467
);
6568
}
6669

@@ -71,6 +74,20 @@ public function getDiscoDevBarData(): DiscoDevBarData
7174
$config = [];
7275
}
7376

77+
// Extract Font Awesome configuration from YAML
78+
$fontAwesomeConfig = $config['font_awesome'] ?? [];
79+
$fontAwesomeEnabled = false;
80+
$fontAwesomeVersion = self::DEFAULT_FONT_AWESOME_VERSION;
81+
82+
if (\is_array($fontAwesomeConfig)) {
83+
$fontAwesomeEnabled = $fontAwesomeConfig['enabled'] ?? false;
84+
// Use user's version if provided and not null, otherwise use default
85+
$userVersion = $fontAwesomeConfig['version'] ?? null;
86+
if ($userVersion !== null && \is_string($userVersion)) {
87+
$fontAwesomeVersion = $userVersion;
88+
}
89+
}
90+
7491
$widgets = $config['widgets'] ?? [];
7592
if (!\is_array($widgets)) {
7693
$widgets = [];
@@ -90,8 +107,8 @@ public function getDiscoDevBarData(): DiscoDevBarData
90107
hasError: false,
91108
errorMessage: '',
92109
version: $version,
93-
fontAwesomeEnabled: $this->fontAwesomeEnabled,
94-
fontAwesomeVersion: $this->fontAwesomeVersion
110+
fontAwesomeEnabled: \is_bool($fontAwesomeEnabled) ? $fontAwesomeEnabled : false,
111+
fontAwesomeVersion: $fontAwesomeVersion
95112
);
96113
}
97114

0 commit comments

Comments
 (0)