Resolves #54160: List module broken on root page
[TYPO3CMS/Extensions/static_info_tables.git] / Classes / Controller / AbstractController.php
1 <?php
2 namespace SJBR\StaticInfoTables\Controller;
3 /***************************************************************
4 * Copyright notice
5 *
6 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
7 * (c) 2011 Bastian Waidelich <bastian@typo3.org>
8 * (c) 2013 Stanislas Rolland <typo3@sjbr.ca>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Abstract base controller for the StaticInfoTables extension
30 */
31 abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
32
33 /**
34 * @var string Name of the extension this controller belongs to
35 */
36 protected $extensionName = 'StaticInfoTables';
37
38 /**
39 * Override getErrorFlashMessage to presentn nice flash error messages.
40 *
41 * @return string
42 */
43 protected function getErrorFlashMessage() {
44 return FALSE;
45 }
46
47 /**
48 * helper function to render localized flashmessages
49 *
50 * @param string $message
51 * @param integer $severity optional severity code. One of the \TYPO3\CMS\Core\Messaging\FlashMessage constants
52 * @return void
53 */
54 protected function addFlashMessage($action, $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK) {
55 $messageLocallangKey = sprintf('flashmessage.%s.%s', $this->request->getControllerName(), $action);
56 $localizedMessage = $this->translate($messageLocallangKey, '[' . $messageLocallangKey . ']');
57 $titleLocallangKey = sprintf('%s.title', $messageLocallangKey);
58 $localizedTitle = $this->translate($titleLocallangKey, '[' . $titleLocallangKey . ']');
59 $this->flashMessageContainer->add($localizedMessage, $localizedTitle, $severity);
60 }
61
62 /**
63 * helper function to use localized strings in controllers
64 *
65 * @param string $key locallang key
66 * @param string $default the default message to show if key was not found
67 * @return string
68 */
69 protected function translate($key, $defaultMessage = '') {
70 $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $this->extensionName);
71 if ($message === NULL) {
72 $message = $defaultMessage;
73 }
74 return $message;
75 }
76
77 }
78
79 ?>