Skip to content

Commit

Permalink
Make leads 3 compatible with Haste 4
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Aug 30, 2024
1 parent e50eccd commit 5a8b532
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
2 changes: 2 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

return (new Configuration())
->ignoreUnknownClasses(['Haste\Util\StringUtil'])

// Optional integrations
->ignoreErrorsOnPackage('dompdf/dompdf', [ErrorType::DEV_DEPENDENCY_IN_PROD])
->ignoreErrorsOnPackage('mpdf/mpdf', [ErrorType::DEV_DEPENDENCY_IN_PROD])
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require": {
"php": "^8.1",
"contao/core-bundle": "^4.13 || ^5.0",
"codefog/contao-haste": "^5.0",
"codefog/contao-haste": "^4.25 || ^5.0",
"menatwork/contao-multicolumnwizard-bundle": "^3.6",
"phpoffice/phpspreadsheet": "^1.26 || ^2.0",
"doctrine/dbal": "^3.0",
Expand Down Expand Up @@ -72,6 +72,7 @@
"config": {
"allow-plugins": {
"contao-components/installer": false,
"contao-community-alliance/composer-plugin": false,
"php-http/discovery": false,
"contao/manager-plugin": false,
"terminal42/contao-build-tools": true
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
parameters:
ignoreErrors:
- '#no value type specified in iterable type array#'
- '#unknown class Haste\\Util\\StringUtil#'
14 changes: 11 additions & 3 deletions src/EventListener/DataContainer/LeadLabelListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LeadLabelListener
{
public function __construct(
private readonly Connection $connection,
private readonly StringParser $stringParser,
private readonly StringParser|null $stringParser = null,
) {
}

Expand Down Expand Up @@ -48,10 +48,18 @@ public function __invoke(array $row, string $label): string
$values = $this->connection->fetchAllKeyValue('SELECT name, value FROM tl_lead_data WHERE pid=?', [$row['id']]);

foreach ($values as $name => $value) {
$this->stringParser->flatten(StringUtil::deserialize($value), $name, $tokens);
if ($this->stringParser) {
$this->stringParser->flatten(StringUtil::deserialize($value), $name, $tokens);
} else {
\Haste\Util\StringUtil::flatten(StringUtil::deserialize($value), $name, $tokens);
}
}

return $this->stringParser->recursiveReplaceTokensAndTags($lead['leadLabel'], $tokens);
if ($this->stringParser) {
return $this->stringParser->recursiveReplaceTokensAndTags($lead['leadLabel'], $tokens);
}

return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($lead['leadLabel'], $tokens);
}

private function formatToken(string $title, int|string $value): string
Expand Down
34 changes: 26 additions & 8 deletions src/Export/AbstractExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
private readonly ServiceLocator $formatters,
private readonly Connection $connection,
private readonly TranslatorInterface $translator,
private readonly StringParser $parser,
private readonly StringParser|null $parser,
private readonly ExpressionLanguage|null $expressionLanguage = null,
) {
}
Expand Down Expand Up @@ -308,9 +308,15 @@ protected function getColumns(): array
$this->columns = [];

foreach (StringUtil::deserialize($this->config['tokenFields'], true) as $config) {
if ($this->parser) {
$value = fn ($lead) => $this->parser->recursiveReplaceTokensAndTags($config['tokensValue'], $this->getTokens($lead));
} else {
$value = fn ($lead) => \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($config['tokensValue'], $this->getTokens($lead));
}

$this->columns[] = [
'name' => $config['headerField'],
'value' => fn ($lead) => $this->parser->recursiveReplaceTokensAndTags($config['tokensValue'], $this->getTokens($lead)),
'value' => $value,
'label' => static fn () => '',
'output' => 'value',
'targetColumn' => $config['targetColumn'],
Expand All @@ -335,11 +341,19 @@ protected function getFilename(): string
'datim' => Date::parse(Config::get('datimFormat')),
];

$filename = $this->parser->recursiveReplaceTokensAndTags(
$filename,
$tokens,
StringParser::NO_TAGS & StringParser::NO_BREAKS & StringParser::NO_ENTITIES,
);
if ($this->parser) {
$filename = $this->parser->recursiveReplaceTokensAndTags(
$filename,
$tokens,
StringParser::NO_TAGS & StringParser::NO_BREAKS & StringParser::NO_ENTITIES,
);
} else {
$filename = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags(
$filename,
$tokens,
\Haste\Util\StringUtil::NO_TAGS & \Haste\Util\StringUtil::NO_BREAKS & \Haste\Util\StringUtil::NO_ENTITIES,
);
}

if (!str_contains($filename, '.')) {
return $filename.$this->getFileExtension();
Expand Down Expand Up @@ -391,7 +405,11 @@ protected function getTokens(array $lead): array
];

foreach ($lead['data'] as $data) {
$this->parser->flatten(StringUtil::deserialize($data['value']), $data['name'], $tokens);
if ($this->parser) {
$this->parser->flatten(StringUtil::deserialize($data['value']), $data['name'], $tokens);
} else {
\Haste\Util\StringUtil::flatten(StringUtil::deserialize($data['value']), $data['name'], $tokens);
}
}

return $tokens;
Expand Down
2 changes: 1 addition & 1 deletion src/Export/PhpSpreadsheetExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
ServiceLocator $formatters,
Connection $connection,
TranslatorInterface $translator,
StringParser $parser,
StringParser|null $parser = null,
ExpressionLanguage|null $expressionLanguage = null,
) {
parent::__construct($formatters, $connection, $translator, $parser, $expressionLanguage);
Expand Down

0 comments on commit 5a8b532

Please sign in to comment.