[BUGFIX] Workspace preview links for multiple languages 93/26993/10
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 15:58:04 +0000 (17:58 +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/26993
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
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 da1b853..ede8671 100644 (file)
@@ -46,6 +46,16 @@ class ActionHandler extends 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 b386672..8afebf6 100644 (file)
@@ -641,6 +641,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
         *
@@ -728,4 +746,36 @@ class WorkspaceService implements SingletonInterface {
                return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
        }
 
+       /**
+        * 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::class);
+               $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 a0ce1c8..45037cc 100644 (file)
@@ -95,7 +95,7 @@
                                </source>
                        </trans-unit>
                        <trans-unit id="tooltip.generatePagePreview">
-                               <source>Generate page preview</source>
+                               <source>Generate page preview links</source>
                        </trans-unit>
                        <trans-unit id="previewLink">
                                <source>Preview Link</source>
                        <trans-unit id="label_doaction_discard">
                                <source>Discard</source>
                        </trans-unit>
-                       <trans-unit id="label_doaction_generatePreviewLink">
-                               <source>Generate Workspace Preview Link</source>
+                       <trans-unit id="label_doaction_generatePreviewLinks">
+                               <source>Generate Workspace Preview Links</source>
                        </trans-unit>
                        <trans-unit id="info.elementAlreadyModified">
                                <source>Element is in workspace stage "%s", modifications will send it back to "%s".</source>
index e437255..de1b85e 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 f1f3534..25eccdb 100644 (file)
@@ -367,5 +367,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
+                       });
+               });
        }
 };