dmitryd / typo3-realurl

**Vintage** RealURL extension for TYPO3 CMS. Read the wiki if you have questions!
110 stars 127 forks source link

Allow NULL as a return value in user functions #109

Closed fgalinski closed 8 years ago

fgalinski commented 8 years ago

Hi Dmitry,

I created a patch for your extension, which allows that the return value of a user functions is NULL. This can be necessary if your URL segment doesn't always exists.

diff --git a/typo3conf/ext/realurl/class.tx_realurl.php b/typo3conf/ext/realurl/class.tx_realurl.php
index d44d06c..8be35e9 100644
--- a/typo3conf/ext/realurl/class.tx_realurl.php
+++ b/typo3conf/ext/realurl/class.tx_realurl.php
@@ -653,8 +653,12 @@ class tx_realurl extends tx_realurl_baseclass {
                                );
                                $prevVal = $GETvarVal;
                                $GETvarVal = $this->apiWrapper->callUserFunction($setup['userFunc'], $params, $this);
-                               $pathParts[] = rawurlencode($GETvarVal);
-                               $this->cHashParameters[$GETvar] = $prevVal;
+                               if ($GETvarVal === NULL) {
+                                   $this->rebuildCHash |= $parameterSet;
+                               } else {
+                                   $pathParts[] = rawurlencode($GETvarVal);
+                                   $this->cHashParameters[$GETvar] = $prevVal;
+                               }
                            } elseif (is_array($setup['lookUpTable'])) {
                                $prevVal = $GETvarVal;
                                $GETvarVal = $this->lookUpTranslation($setup['lookUpTable'], $GETvarVal);
@@ -1615,6 +1619,10 @@ class tx_realurl extends tx_realurl_baseclass {
                                    'setup' => $setup
                                );
                                $value = $this->apiWrapper->callUserFunction($setup['userFunc'], $params, $this);
+                               if ($value === NULL) {
+                                   array_unshift($pathParts, $origValue);
+                                   break;
+                               }
                            } elseif (is_array($setup['lookUpTable'])) {
                                $temp = $value;
                                $value = $this->lookUpTranslation($setup['lookUpTable'], $value, TRUE);

I hope you will integrate this patch :)

Kind regards, Fabian

dmitryd commented 8 years ago

Realurl 1.x is no longer supported or updated. Please, switch to realurl 2.

fgalinski commented 8 years ago

Thanks for your fast reply! We will check the new version as soon as possible. :)

dmitryd commented 8 years ago

Closed because applies to unsupported version.