[FEATURE] Add new possibility to retrieve session data in TS 20/52320/3
authorMarkus Klein <markus.klein@typo3.org>
Sun, 2 Apr 2017 20:02:04 +0000 (22:02 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 3 Apr 2017 21:57:40 +0000 (23:57 +0200)
Since the session API has been adjusted it is no longer possible
to access FE session data via getData access in TS.
TSFE:fe_user|sesData|myext|mydata

Instead a new an cleaner approach is now available:
session:myext|mydata

Releases: master
Resolves: #80154
Change-Id: I5ea3cf4f20b03176332f28a21b01d1976868a9d4
Reviewed-on: https://review.typo3.org/52320
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/8.6/Breaking-70316-AbstractUserAuthenticationPropertiesAndMethodsDroppedAndChanged.rst
typo3/sysext/core/Documentation/Changelog/8.7/Feature-80154-RetrieveSessionDataInTS.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index 07513b6..94d44ad 100644 (file)
@@ -24,6 +24,8 @@ Impact
 Accessing one of these properties will raise a PHP warning.
 Calling the method :php:`fetchSessionData()` will cause a PHP fatal error.
 
+Moreover it is not possible anymore to use the getData function from within TypoScript
+to access session data. This functionality is replaced by a new API. (see :issue:`80154`)
 
 Affected Installations
 ======================
diff --git a/typo3/sysext/core/Documentation/Changelog/8.7/Feature-80154-RetrieveSessionDataInTS.rst b/typo3/sysext/core/Documentation/Changelog/8.7/Feature-80154-RetrieveSessionDataInTS.rst
new file mode 100644 (file)
index 0000000..7109180
--- /dev/null
@@ -0,0 +1,29 @@
+.. include:: ../../Includes.txt
+
+=============================================
+Feature: #80154 - Retrieve session data in TS
+=============================================
+
+See :issue:`80154`
+
+Description
+===========
+
+As the session API has been modified, it is no longer possible to access
+session data from TypoScript by accessing the formerly public property of
+the fe_user with:
+
+.. code-block:: typoscript
+
+   page.10 = TEXT
+   page.10.data = TSFE:fe_user|sesData|myext|mydata
+
+
+This is being replaced by a more direct way, which allows for the same functionality:
+
+.. code-block:: typoscript
+
+   page.10 = TEXT
+   page.10.data = session:myext|mydata
+
+.. index:: Frontend, TypoScript
\ No newline at end of file
index 82cfecb..f8f467f 100644 (file)
@@ -5271,6 +5271,24 @@ class ContentObjectRenderer
                             }
                         }
                         break;
+                    case 'session':
+                        $keyParts = GeneralUtility::trimExplode('|', $key, true);
+                        $sessionKey = array_shift($keyParts);
+                        $retVal = $this->getTypoScriptFrontendController()->fe_user->getSessionData($sessionKey);
+                        foreach ($keyParts as $keyPart) {
+                            if (is_object($retVal)) {
+                                $retVal = $retVal->{$keyPart};
+                            } elseif (is_array($retVal)) {
+                                $retVal = $retVal[$keyPart];
+                            } else {
+                                $retVal = '';
+                                break;
+                            }
+                        }
+                        if (!is_scalar($retVal)) {
+                            $retVal = '';
+                        }
+                        break;
                 }
             }
             if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getData'])) {
index e2b8171..74ce232 100644 (file)
@@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\DebugUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
 use TYPO3\CMS\Frontend\ContentObject\CaseContentObject;
 use TYPO3\CMS\Frontend\ContentObject\ContentContentObject;
@@ -1263,6 +1264,26 @@ class ContentObjectRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTe
     }
 
     /**
+     * Checks if getData() works with type "session"
+     *
+     * @test
+     */
+    public function getDataWithTypeSession()
+    {
+        $frontendUser = $this->getMockBuilder(FrontendUserAuthentication::class)
+            ->setMethods(['getSessionData'])
+            ->getMock();
+        $frontendUser->expects($this->once())->method('getSessionData')->with('myext')->willReturn([
+            'mydata' => [
+                'someValue' => 42,
+            ],
+        ]);
+        $GLOBALS['TSFE']->fe_user = $frontendUser;
+
+        $this->assertEquals(42, $this->subject->getData('session:myext|mydata|someValue'));
+    }
+
+    /**
      * Checks if getData() works with type "level"
      *
      * @test