Browse code

Extend child record label for form fields in Backend

Benjamin Roth authored on20/01/2023 14:45:19
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,57 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of formilicious bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license LGPL-3.0-or-later
11
+ */
12
+
13
+namespace vonRotenberg\FormiliciousBundle\EventListener\DataContainer;
14
+
15
+use Contao\CoreBundle\ServiceAnnotation\Callback;
16
+
17
+/**
18
+ * @Callback(table="tl_form_field", target="list.sorting.child_record")
19
+ */
20
+class FormFieldChildRecordListener
21
+{
22
+
23
+    public function __invoke(array $arrRow): string
24
+    {
25
+        $dcaClass = new \tl_form_field();
26
+
27
+        $buffer = $dcaClass->listFormFields($arrRow);
28
+
29
+        if (!$arrRow['eSM_fl_width'] && !$arrRow['eSM_fl_clear'])
30
+        {
31
+            return $buffer;
32
+        }
33
+
34
+        $entry = new \DOMDocument();
35
+        $entry->loadHTML($buffer);
36
+        $finder = new \DomXPath($entry);
37
+
38
+        $cteLabel = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' cte_type ')]");
39
+        if ($cteLabel->length)
40
+        {
41
+            /** @var \DOMElement $item */
42
+            foreach($cteLabel as $item)
43
+            {
44
+                if ($arrRow['eSM_fl_width'])
45
+                {
46
+                    $item->nodeValue.= ' ['.(isset($GLOBALS['TL_LANG']['tl_form_field']['ref_width'][$arrRow['eSM_fl_width']]) ? $GLOBALS['TL_LANG']['tl_form_field']['ref_width'][$arrRow['eSM_fl_width']] : 'w' . $arrRow['eSM_fl_width']).']';
47
+                }
48
+                if ($arrRow['eSM_fl_clear'])
49
+                {
50
+                    $item->nodeValue.= ' ↲';
51
+                }
52
+            }
53
+        }
54
+
55
+        return $entry->saveHTML();
56
+    }
57
+}