[TASK] Link to extension manual 52/28352/6
authorXavier Perseguers <xavier@typo3.org>
Thu, 13 Mar 2014 15:30:03 +0000 (16:30 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Thu, 13 Mar 2014 19:34:51 +0000 (20:34 +0100)
If an extension manual is available locally, it should be
linked in Extension Manager.

Resolves: #56880
Releases: 6.2
Change-Id: I24572348e0dc79513ece37477e3aee186676d923
Reviewed-on: https://review.typo3.org/28352
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/documentation/Classes/Controller/DocumentController.php
typo3/sysext/documentation/Classes/Slots/ExtensionManager.php [new file with mode: 0644]
typo3/sysext/documentation/Classes/ViewHelpers/FormatsViewHelper.php
typo3/sysext/documentation/ext_localconf.php [new file with mode: 0644]

index eb47dd5..dce45dc 100644 (file)
@@ -69,17 +69,7 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
         * @return void
         */
        public function listAction() {
-               $language = $this->languageUtility->getDocumentationLanguage();
-               $documents = $this->documentRepository->findByLanguage($language);
-
-               $this->signalSlotDispatcher->dispatch(
-                       __CLASS__,
-                       'afterInitializeDocuments',
-                       array(
-                               'language'  => $language,
-                               'documents' => &$documents,
-                       )
-               );
+               $documents = $this->getDocuments();
 
                // Filter documents to be shown for current user
                $hideDocuments = $this->getBackendUser()->getTSConfigVal('mod.help_DocumentationDocumentation.documents.hide');
@@ -97,6 +87,28 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
        }
 
        /**
+        * Returns available documents.
+        *
+        * @return \TYPO3\CMS\Documentation\Domain\Model\Document[]
+        * @api
+        */
+       public function getDocuments() {
+               $language = $this->languageUtility->getDocumentationLanguage();
+               $documents = $this->documentRepository->findByLanguage($language);
+
+               $this->signalSlotDispatcher->dispatch(
+                       __CLASS__,
+                       'afterInitializeDocuments',
+                       array(
+                               'language'  => $language,
+                               'documents' => &$documents,
+                       )
+               );
+
+               return $documents;
+       }
+
+       /**
         * Shows documents to be downloaded/fetched from a remote location.
         *
         * @return void
diff --git a/typo3/sysext/documentation/Classes/Slots/ExtensionManager.php b/typo3/sysext/documentation/Classes/Slots/ExtensionManager.php
new file mode 100644 (file)
index 0000000..6324ea4
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+namespace TYPO3\CMS\Documentation\Slots;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Xavier Perseguers <xavier@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * This slot listens to a signal in Extension Manager to add links to
+ * manuals available locally.
+ */
+class ExtensionManager {
+
+       /**
+        * @var \TYPO3\CMS\Documentation\Domain\Model\Document[]
+        */
+       static protected $documents = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+        * @inject
+        */
+       protected $objectManager;
+
+       /**
+        * Processes the list of actions for a given extension and adds
+        * a link to the manual(s), if available.
+        *
+        * @param array $extension
+        * @param array $actions
+        * @return void
+        */
+       public function processActions(array $extension, array &$actions) {
+               if (static::$documents === NULL) {
+                       /** @var \TYPO3\CMS\Documentation\Controller\DocumentController $documentController */
+                       $documentController = $this->objectManager->get('TYPO3\\CMS\\Documentation\\Controller\\DocumentController');
+                       static::$documents = $documentController->getDocuments();
+               }
+
+               $extensionKey = $extension['key'];
+               $documentKey = 'typo3cms.extensions.' . $extensionKey;
+
+               if (isset(static::$documents[$documentKey])) {
+                       $document = static::$documents[$documentKey];
+
+                       /** @var \TYPO3\CMS\Documentation\ViewHelpers\FormatsViewHelper $formatsViewHelper */
+                       $formatsViewHelper = $this->objectManager->get('TYPO3\\CMS\\Documentation\\ViewHelpers\\FormatsViewHelper');
+
+                       foreach ($document->getTranslations() as $documentTranslation) {
+                               $actions[] = $formatsViewHelper->render($documentTranslation);
+                       }
+               }
+       }
+
+}
index 7210314..a496735 100644 (file)
@@ -46,8 +46,7 @@ class FormatsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
                        /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $format */
                        $output .= '<a ';
 
-                       // TODO: Encode uri with official TYPO3 API?
-                       $uri = $this->controllerContext->getRequest()->getBaseURI() . '../' . $format->getPath();
+                       $uri = '../' . $format->getPath();
                        $extension = substr($uri, strrpos($uri, '.') + 1);
                        if (strlen($extension) < 5) {
                                // This is direct link to a file
@@ -67,7 +66,7 @@ class FormatsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
                        );
                        $output .= ' title="' . htmlspecialchars($title) . '">';
                        $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($extension);
-                       $output .= $spriteIconHtml . '</a>';
+                       $output .= $spriteIconHtml . '</a>' . LF;
                }
                return $output;
        }
diff --git a/typo3/sysext/documentation/ext_localconf.php b/typo3/sysext/documentation/ext_localconf.php
new file mode 100644 (file)
index 0000000..76bda25
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+if (!defined ('TYPO3_MODE')) {
+       die('Access denied.');
+}
+
+// Open extension manual from within Extension Manager
+$signalSlotDispatcher->connect(
+       'TYPO3\\CMS\\Extensionmanager\\ViewHelpers\\ProcessAvailableActionsViewHelper',
+       'processActions',
+       'TYPO3\\CMS\Documentation\\Slots\\ExtensionManager',
+       'processActions'
+);
\ No newline at end of file