Skip to content

Commit

Permalink
Fix non-empty label preference in backed lead list (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabauss authored Dec 18, 2024
1 parent 1aa3063 commit de533d4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/EventListener/DataContainer/LeadLabelListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ public function __invoke(array $row, string $label): string
$records = $this->connection->fetchAllAssociative('SELECT name, value, label FROM tl_lead_data WHERE pid=?', [$row['id']]);

foreach ($records as $record) {
// Try to use label over value if it is a non-empty scalar value or a non-empty array
foreach ([$record['label'], $record['value']] as $value) {
$value = StringUtil::deserialize($value);

if (
(!\is_array($value) && '' !== (string) $value)
|| (\is_array($value) && [] !== array_filter($value))
) {
break;
}
}

if ($this->stringParser) {
$this->stringParser->flatten(StringUtil::deserialize($record['label'] ?: $record['value']), $record['name'], $tokens);
$this->stringParser->flatten($value, $record['name'], $tokens);
} else {
\Haste\Util\StringUtil::flatten(StringUtil::deserialize($record['label'] ?: $record['value']), $record['name'], $tokens);
\Haste\Util\StringUtil::flatten($value, $record['name'], $tokens);
}
}

Expand Down

0 comments on commit de533d4

Please sign in to comment.