[BUGFIX] Notify user about insufficient language configuration 70/43270/6
authorNicole Cordes <typo3@cordes.co>
Sun, 13 Sep 2015 11:43:18 +0000 (13:43 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 16 Sep 2015 13:57:17 +0000 (15:57 +0200)
The language records are necessary within FormEngine and FlexForm
handling. If a language has a missing language_isocode, the output of
RTE elements might break because of missing identifier information.
This patch adds a notification to the user to check the language
record configuration and set a proper language_isocode.

Resolves: #69757
Releases: master
Change-Id: Ic969217ee6f7b4ca46b55d0d274d53391b080c5b
Reviewed-on: http://review.typo3.org/43270
Reviewed-by: Thorsten Bringewatt <t.bringewatt@mittwald.de>
Tested-by: Thorsten Bringewatt <t.bringewatt@mittwald.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseSystemLanguageRows.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseSystemLanguageRowsTest.php
typo3/sysext/lang/locallang_core.xlf

index 62adf4b..41984b8 100644 (file)
@@ -17,8 +17,11 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Fill the "systemLanguageRows" part of the result array
@@ -74,7 +77,28 @@ class DatabaseSystemLanguageRows implements FormDataProviderInterface {
                                        $dbRow['iso'] = $lg_iso_2['lg_iso_2'];
                                }
                        } else {
-                               // @todo: Not having iso code at all is maybe a bad idea ... throw an exception instead?
+                               // No iso code could be found. This is currently possible in the system but discouraged.
+                               // So, code within FormEngine has to be suited to work with an empty iso code. However,
+                               // it may impact certain multi language scenarios, so we add a flash message hinting for
+                               // incomplete configuration here.
+                               // It might be possible to convert this to a non-catchable exception later if
+                               // it iso code is enforced on a different layer of the system (tca required + migration wizard).
+                               $message = sprintf(
+                                       $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:error.missingLanguageIsocode'),
+                                       $dbRow['title'],
+                                       $dbRow['uid']
+                               );
+                               /** @var FlashMessage $flashMessage */
+                               $flashMessage = GeneralUtility::makeInstance(
+                                               FlashMessage::class,
+                                               $message,
+                                               '',
+                                               FlashMessage::ERROR
+                               );
+                               /** @var $flashMessageService FlashMessageService */
+                               $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
+                               $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+                               $defaultFlashMessageQueue->enqueue($flashMessage);
                                $dbRow['iso'] = '';
                        }
                        unset($dbRow['language_isocode']);
@@ -93,4 +117,11 @@ class DatabaseSystemLanguageRows implements FormDataProviderInterface {
        protected function getDatabase() {
                return $GLOBALS['TYPO3_DB'];
        }
+
+       /**
+        * @return LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
 }
index 2fc02ba..bff0df1 100644 (file)
@@ -18,8 +18,13 @@ use Prophecy\Argument;
 use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseSystemLanguageRows;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
+use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Test case
@@ -135,4 +140,53 @@ class DatabaseSystemLanguageRowsTest extends UnitTestCase {
                $this->assertSame($expected, $this->subject->addData([]));
        }
 
+       /**
+        * @test
+        */
+       public function addDataAddFlashMessageWithMissingIsoCode() {
+               $dbRows = [
+                       [
+                               'uid' => 3,
+                               'title' => 'french',
+                               'language_isocode' => '',
+                               'static_lang_isocode' => '',
+                       ],
+               ];
+               $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode', 'sys_language', 'pid=0 AND hidden=0')->shouldBeCalled()->willReturn($dbRows);
+               // Needed for backendUtility::getRecord()
+               $GLOBALS['TCA']['static_languages'] = [ 'foo' ];
+               $expected = [
+                       'systemLanguageRows' => [
+                               0 => [
+                                       'uid' => 0,
+                                       'title' => 'Default Language',
+                                       'iso' => 'DEF',
+                               ],
+                               3 => [
+                                       'uid' => 3,
+                                       'title' => 'french',
+                                       'iso' => '',
+                               ],
+                       ],
+               ];
+
+               $languageService = $this->prophesize(LanguageService::class);
+               $GLOBALS['LANG'] = $languageService->reveal();
+               $languageService->sL(Argument::cetera())->willReturnArgument(0);
+
+               /** @var FlashMessage|ObjectProphecy $flashMessage */
+               $flashMessage = $this->prophesize(FlashMessage::class);
+               GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
+               /** @var FlashMessageService|ObjectProphecy $flashMessageService */
+               $flashMessageService = $this->prophesize(FlashMessageService::class);
+               GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
+               /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */
+               $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
+               $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
+
+               $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
+
+               $this->assertSame($expected, $this->subject->addData([]));
+       }
+
 }
index 26733a7..065ae35 100644 (file)
@@ -1254,6 +1254,9 @@ Check also the following points:\n
                        <trans-unit id="error.backendUserGroupListTypeError.message">
                                <source>Editing of at least one plugin was enabled but editing the page content type "Insert Plugin" is still disallowed. Group members won't be able to edit plugins unless you activate editing for the content type.</source>
                        </trans-unit>
+                       <trans-unit id="error.missingLanguageIsocode">
+                               <source>Missing ISO code for language "%s" (UID %d), please edit the language record and set it.</source>
+                       </trans-unit>
                        <trans-unit id="labels.deleteTitle">
                                <source>Revert to default Constant</source>
                        </trans-unit>