Skip to content

Commit 58511ca

Browse files
committed
New: Add settings helpers
Service, FusionObject &EelHelper
1 parent 1d6ec97 commit 58511ca

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed

Classes/EelHelper/MauticHelper.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Garagist\Mautic\EelHelper;
4+
5+
use Neos\Eel\ProtectedContextAwareInterface;
6+
use Neos\Flow\Annotations as Flow;
7+
use Garagist\Mautic\Service\SettingsService;
8+
9+
class MauticHelper implements ProtectedContextAwareInterface
10+
{
11+
12+
#[Flow\Inject]
13+
protected SettingsService $settingsService;
14+
15+
public function settings(string $settingPath, ?string $siteName = null, $rootPackage = 'Garagist.Mautic'): string
16+
{
17+
return $this->settingsService->path($settingPath, $siteName, $rootPackage);
18+
}
19+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Garagist\Mautic\FusionObjects;
4+
5+
use Neos\Flow\Annotations as Flow;
6+
use Neos\Fusion\FusionObjects\AbstractFusionObject;
7+
use Garagist\Mautic\Service\SettingsService;
8+
9+
class SettingsImplementation extends AbstractFusionObject
10+
{
11+
#[Flow\Inject]
12+
protected SettingsService $settingsService;
13+
14+
/**
15+
* Get setting path
16+
*
17+
* @return string|null
18+
*/
19+
protected function getPath(): ?string
20+
{
21+
return $this->fusionValue('path');
22+
}
23+
24+
/**
25+
* Get site name
26+
*
27+
* @return string|null
28+
*/
29+
protected function siteName(): ?string
30+
{
31+
return $this->fusionValue('siteName');
32+
}
33+
34+
/**
35+
* @return string
36+
*/
37+
public function evaluate()
38+
{
39+
$path = $this->getPath();
40+
$siteName = $this->siteName();
41+
42+
return $this->settingsService->path($path, $siteName);
43+
}
44+
}

Classes/Service/SettingsService.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Garagist\Mautic\Service;
6+
7+
use Neos\Flow\Annotations as Flow;
8+
use Neos\Flow\Configuration\ConfigurationManager;
9+
10+
#[Flow\Scope('singleton')]
11+
class SettingsService
12+
{
13+
#[Flow\Inject]
14+
protected ConfigurationManager $configurationManager;
15+
16+
/**
17+
* Get configuration based on the setting path and sitename
18+
*
19+
* @return string
20+
*/
21+
public function path(string $settingPath, ?string $siteName = null, $rootPackage = 'Garagist.Mautic'): string
22+
{
23+
$siteSettings = $this->getSetting($rootPackage, $settingPath, $siteName);
24+
25+
if (isset($siteSettings)) {
26+
return $siteSettings;
27+
}
28+
29+
return $this->getSetting($rootPackage, $settingPath);
30+
}
31+
32+
/**
33+
* Get the setting from the configuration
34+
*
35+
* @param string $settingPath
36+
* @param string|null $siteName
37+
* @return mixed
38+
*/
39+
protected function getSetting(string $rootPackage, string $settingPath, ?string $siteName = null): mixed
40+
{
41+
if ($siteName) {
42+
$settingPath = sprintf('siteSettings.%s.%s', $siteName, $settingPath);
43+
}
44+
if (!str_starts_with($settingPath, $rootPackage)) {
45+
$settingPath = sprintf('%s.%s', $rootPackage, $settingPath);
46+
}
47+
48+
$setting = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $settingPath);
49+
return $setting ?? null;
50+
}
51+
}

Configuration/Settings.Garagist.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
Garagist:
22
Mautic:
3+
# Override any of the settings below by add the site name
4+
# Example:
5+
# siteSettings:
6+
# rootNodeName:
7+
# enableTracking: true
8+
siteSettings: null
9+
310
routeArgument:
411
htmlTemplate: email
512
plaintextTemplate: plaintext

Configuration/Settings.Neos.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Neos:
1919
logFileURL: '%FLOW_PATH_DATA%Logs/Mautic.log'
2020
createParentDirectories: true
2121
severityThreshold: '%LOG_DEBUG%'
22+
Fusion:
23+
defaultContext:
24+
Mautic: 'Garagist\Mautic\EelHelper\MauticHelper'
2225
Neos:
2326
userInterface:
2427
translation:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
prototype(Garagist.Mautic:Settings) {
2+
@class = 'Garagist\\Mautic\\FusionObjects\\SettingsImplementation'
3+
4+
siteName = ${site.name}
5+
path = null
6+
}

0 commit comments

Comments
 (0)