[BUGFIX] Workspace preview links for multiple languages 17/42417/3
authorStefan Rotsch <stefan.rotsch@aoemedia.de>
Wed, 22 Jan 2014 12:30:54 +0000 (13:30 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 8 Aug 2015 16:13:59 +0000 (18:13 +0200)
The workspace preview link will only be generated for one language at
a time, so it might require some effort to generate preview links for
multiple languages.

For convenience of editors, preview links will now be generated for
all available translations of a certain page in a batch.

Resolves: #20852
Resolves: #12970
Releases: master, 6.2
Change-Id: I6de6f2c7b741e238fc373f0756bc29f0100a19f0
Reviewed-on: http://review.typo3.org/42417
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/workspaces/Classes/ExtDirect/ActionHandler.php
typo3/sysext/workspaces/Classes/Service/WorkspaceService.php
typo3/sysext/workspaces/Resources/Private/Language/locallang.xlf
typo3/sysext/workspaces/Resources/Private/Layouts/Module.html
typo3/sysext/workspaces/Resources/Public/JavaScript/actions.js

index bf6d85e..fd4e270 100644 (file)
@@ -47,6 +47,16 @@ class ActionHandler extends \TYPO3\CMS\Workspaces\ExtDirect\AbstractHandler {
        }
 
        /**
+        * Generates workspace preview links for all available languages of a page.
+        *
+        * @param integer $uid
+        * @return array
+        */
+       public function generateWorkspacePreviewLinksForAllLanguages($uid) {
+               return $this->getWorkspaceService()->generateWorkspacePreviewLinksForAllLanguages($uid);
+       }
+
+       /**
         * Swaps a single record.
         *
         * @param string $table
index 6bf72f3..1be1ad6 100644 (file)
@@ -647,6 +647,24 @@ class WorkspaceService implements SingletonInterface {
        }
 
        /**
+        * Generate workspace preview links for all available languages of a page
+        *
+        * @param int $uid
+        * @return array
+        */
+       public function generateWorkspacePreviewLinksForAllLanguages($uid) {
+               $previewUrl = $this->generateWorkspacePreviewLink($uid);
+               $previewLanguages = $this->getAvailableLanguages($uid);
+               $previewLinks = array();
+
+               foreach ($previewLanguages as $languageUid => $language) {
+                       $previewLinks[$language] = $previewUrl . '&L=' . $languageUid;
+               }
+
+               return $previewLinks;
+       }
+
+       /**
         * Find the Live-Uid for a given page,
         * the results are cached at run-time to avoid too many database-queries
         *
@@ -734,4 +752,36 @@ class WorkspaceService implements SingletonInterface {
                return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
        }
 
+       /**
+        * Get the available languages of a certain page
+        *
+        * @param int $pageId
+        * @return array
+        */
+       public function getAvailableLanguages($pageId) {
+               $languageOptions = array();
+               /** @var \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider $translationConfigurationProvider */
+               $translationConfigurationProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider');
+               $systemLanguages = $translationConfigurationProvider->getSystemLanguages($pageId);
+
+               if ($GLOBALS['BE_USER']->checkLanguageAccess(0)) {
+                       // Use configured label for default language
+                       $languageOptions[0] = $systemLanguages[0]['title'];
+               }
+               $pages = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $pageId);
+
+               if (!is_array($pages)) {
+                       return $languageOptions;
+               }
+
+               foreach ($pages as $page) {
+                       $languageId = (int)$page['sys_language_uid'];
+                       // Only add links to active languages the user has access to
+                       if (isset($systemLanguages[$languageId]) && $GLOBALS['BE_USER']->checkLanguageAccess($languageId)) {
+                               $languageOptions[$page['sys_language_uid']] = $systemLanguages[$languageId]['title'];
+                       }
+               }
+
+               return $languageOptions;
+       }
 }
index e274f1e..7fb98c4 100644 (file)
@@ -95,7 +95,7 @@
                                </source>
                        </trans-unit>
                        <trans-unit id="tooltip.generatePagePreview" xml:space="preserve">
-                               <source>Generate page preview</source>
+                               <source>Generate page preview links</source>
                        </trans-unit>
                        <trans-unit id="previewLink" xml:space="preserve">
                                <source>Preview Link</source>
                        <trans-unit id="label_doaction_discard" xml:space="preserve">
                                <source>Discard</source>
                        </trans-unit>
-                       <trans-unit id="label_doaction_generatePreviewLink" xml:space="preserve">
-                               <source>Generate Workspace Preview Link</source>
+                       <trans-unit id="label_doaction_generatePreviewLinks" xml:space="preserve">
+                               <source>Generate Workspace Preview Links</source>
                        </trans-unit>
                        <trans-unit id="info.elementAlreadyModified" xml:space="preserve">
                                <source>Element is in workspace stage "%s", modifications will send it back to "%s".</source>
                        </trans-unit>
                </body>
        </file>
-</xliff>
+</xliff>
\ No newline at end of file
index 6cf2882..3fc1b95 100644 (file)
@@ -10,9 +10,9 @@
                <div class="typo3-docheader-buttons">
                        <div class="left">
                                <f:if condition="{showPreviewLink}">
-                                       <a href="#" onclick="TYPO3.Workspaces.Actions.generateWorkspacePreviewLink();return false;" title="{f:translate(key:'tooltip.generatePagePreview')}" id="goPreviewLinkButton">
+                                       <a href="#" onclick="TYPO3.Workspaces.Actions.generateWorkspacePreviewLinksForAllLanguages();return false;" title="{f:translate(key:'tooltip.generatePagePreview')}" id="goPreviewLinkButton">
                                                <span class="t3-icon t3-icon-extensions t3-icon-extensions-workspaces t3-icon-workspaces-generatepreviewlink">&nbsp;</span>
-                                               <f:translate key="label_doaction_generatePreviewLink">Generate Workspace Preview Link</f:translate>
+                                               <f:translate key="label_doaction_generatePreviewLinks">Generate Workspace Preview Links</f:translate>
                                        </a>
                                </f:if>
                        </div>
index 8fda17d..7e23d0f 100644 (file)
@@ -375,5 +375,31 @@ TYPO3.Workspaces.Actions = {
                };
 
                top.TYPO3.Dialog.QuestionDialog(configuration);
+       },
+
+       /**
+        * Generate workspace preview links for all available languages of a page
+        *
+        * @return {void}
+        */
+       generateWorkspacePreviewLinksForAllLanguages: function() {
+               TYPO3.Workspaces.ExtDirectActions.generateWorkspacePreviewLinksForAllLanguages(TYPO3.settings.Workspaces.id, function(response) {
+
+                       var msg = '<ul>';
+
+                       for (language in response) {
+                               var url = response[language];
+
+                               msg += String.format('<li style="margin: 0 0 8px;"><strong>{1}</strong><br /><a href="{0}" target="_blank">{0}</a></li>', url, language);
+                       }
+
+                       msg += '</ul>';
+
+                       top.TYPO3.Dialog.InformationDialog({
+                               title: TYPO3.l10n.localize('previewLink'),
+                               minWidth: '400',
+                               msg: msg
+                       });
+               });
        }
 };