[BUGFIX] toTop Link reloads page with baseUrl in fluid_styled_content 53/45053/5
authorGianluigi Martino <gmartino27@gmail.com>
Sun, 29 Nov 2015 18:45:28 +0000 (19:45 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 1 Dec 2015 23:27:11 +0000 (00:27 +0100)
When using fluid_styled_content toTop option, the page reload if baseUrl
is set.

Change-Id: I6216dc6ddc6b56696710e234144c4b2bd7ac87dd
Resolves: #71695
Releases: master
Reviewed-on: https://review.typo3.org/45053
Reviewed-by: Gianluigi Martino <gmartino27@gmail.com>
Tested-by: Gianluigi Martino <gmartino27@gmail.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/SectionViewHelper.php [new file with mode: 0644]
typo3/sysext/fluid_styled_content/Resources/Private/Partials/Footer.html

diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/SectionViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/SectionViewHelper.php
new file mode 100644 (file)
index 0000000..1a57691
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Link;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+
+/**
+ * A view helper for creating a link to a section.
+ * If baseUrl is used, the path part of the current URL is prefixed.
+ *
+ * = Example =
+ *
+ * <code title="section link">
+ * <ce:link.section name="section">Jump to section</ce:link.section>
+ * </code>
+ *
+ * <output>
+ * <a href="#section">Jump to section</a> or
+ * <a href="<path part of current URL>#section">Jump to section</a>
+ * </output>
+ */
+class SectionViewHelper extends AbstractTagBasedViewHelper
+{
+    /**
+     * @var string
+     */
+    protected $tagName = 'a';
+
+    /**
+     * Arguments initialization
+     *
+     * @return void
+     */
+    public function initializeArguments()
+    {
+        $this->registerUniversalTagAttributes();
+    }
+
+    /**
+     * Render the view helper
+     *
+     * @param string $name The section name to be used
+     * @return string
+     */
+    public function render($name)
+    {
+        $fragment = '#' . $name;
+
+        // Prefix with current URL path if baseUrl is used
+        if (!empty($this->getTypoScriptFrontendController()->baseUrl)) {
+            $fragment = $this->getTypoScriptFrontendController()->cObj->getUrlToCurrentLocation() . $fragment;
+        }
+
+        $this->tag->addAttribute('href', $fragment);
+        $this->tag->setContent($this->renderChildren());
+
+        return $this->tag->render();
+    }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
+}
index 68d55e1..f6b1a79 100644 (file)
@@ -1,7 +1,7 @@
-<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
+<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:ce="http://typo3.org/ns/TYPO3/CMS/FluidStyledContent/ViewHelpers" data-namespace-typo3-fluid="true">
 <f:if condition="{data.linkToTop}">
 <p>
-       <a href="#"><f:translate key="toTop" extensionName="fluid_styled_content" /></a>
+       <ce:link.section name="top"><f:translate key="toTop" extensionName="fluid_styled_content" /></ce:link.section>
 </p>
 </f:if>
 </html>
\ No newline at end of file