b124d609bbaf — Eddie Barraco 5 years ago
Make tag label csv proof
3 files changed, 18 insertions(+), 4 deletions(-)

M src/Entity/Tag.php
M src/Form/TagLabelFilterType.php
M src/Twig/AppExtension.php
M src/Entity/Tag.php +9 -0
@@ 18,6 18,15 @@ class Tag
         $this->updatedAt = $date;
     }
 
+    public function getCsvProofLabel(?string $enclosure = '"')
+    {
+        if (preg_match('/ /', $this->label)) {
+            return sprintf('%s%s%1$s', $enclosure, $this->label);
+        }
+
+        return $this->label;
+    }
+
     public function getId(): ?Uuid
     {
         return $this->id;

          
M src/Form/TagLabelFilterType.php +8 -3
@@ 29,12 29,17 @@ class TagLabelFilterType extends Abstrac
 
                     return $labels;
                 },
-                function ($tagsAsString) {
-                    if (null === $tagsAsString) {
+                function ($labelsAsString) {
+                    if (null === $labelsAsString) {
                         return [];
                     }
 
-                    return explode(' ', $tagsAsString);
+                    $labels = str_getcsv($labelsAsString);
+                    foreach ($labels as $key => $label) {
+                        $labels[$key] = trim($label);
+                    }
+
+                    return array_filter($labels);
                 }
             ))
         ;

          
M src/Twig/AppExtension.php +1 -1
@@ 28,7 28,7 @@ class AppExtension extends AbstractExten
     {
         $labels = [];
         foreach ($article->tags as $tag) {
-            $labels[] = $tag->label;
+            $labels[] = $tag->getCsvProofLabel();
         }
 
         $form = $this->formFactory->create(TagLabelFilterType::class, [