Browse code

Add a replaceInsertTagsListener

Benjamin Roth authored on28/02/2024 13:33:18
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,60 @@
1
+<?php
2
+
3
+/**
4
+ * OBG Customizations
5
+ *
6
+ * Copyright (c) 2021 vonRotenberg
7
+ *
8
+ * @license commercial
9
+ */
10
+
11
+namespace vonRotenberg\RealEstateListingBundle\EventListener;
12
+
13
+use Contao\Config;
14
+use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
15
+use Contao\Input;
16
+use vonRotenberg\RealEstateListingBundle\Model\RealEstateAssetsModel;
17
+
18
+#[AsHook('replaceInsertTags')]
19
+class ReplaceInsertTagsListener
20
+{
21
+    public function __invoke(
22
+        string $insertTag,
23
+        bool $useCache,
24
+        string $cachedValue,
25
+        array $flags,
26
+        array $tags,
27
+        array $cache,
28
+        int $_rit,
29
+        int $_cnt
30
+    )
31
+    {
32
+        $elements = explode('::', $insertTag,2);
33
+        $insertTag = array_shift($elements);
34
+
35
+        if ('re_asset' === $insertTag) {
36
+            if (!isset($_GET['items']) && Config::get('useAutoItem') && isset($_GET['auto_item']))
37
+            {
38
+                $varId = Input::get('auto_item');
39
+            } else {
40
+                $varId = Input::get('items');
41
+            }
42
+            if (($Asset = RealEstateAssetsModel::findPublishedByIdOrAlias($varId)) !== null)
43
+            {
44
+                if (isset($elements[0]))
45
+                {
46
+                    switch($elements[0])
47
+                    {
48
+                        case 'category_title':
49
+                            if (($Category = $Asset->getRelated('pid')) !== null)
50
+                            {
51
+                                return $Category->title;
52
+                            }
53
+                    }
54
+                }
55
+            }
56
+        }
57
+
58
+        return false;
59
+    }
60
+}