From b06ee61ef54373097ce3c868e8590ad24a068841 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 11:58:07 +0200 Subject: [PATCH 01/36] [!!!] Move Dashboard module to user section The system section is meant for administration of the TYPO3 system, while a dashboard is a typical user module as every dashboard is bound to individual users. --- .../JavaScript/Backend/DashboardManager/ViewModel.js | 8 ++++---- ext_tables.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js b/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js index 22a759b..81c014e 100644 --- a/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js +++ b/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js @@ -131,7 +131,7 @@ define(['jquery', */ Wizard.addFinalProcessingSlide(function() { $.post(_dashboardManagerApp.getAjaxEndpoint('create'), { - tx_dashboard_system_dashboarddashboardmod1: { + tx_dashboard_user_dashboarddashboardmod1: { dashboardName: Wizard.setup.settings['dashboardName'] } }, function(data, textStatus, jqXHR) { @@ -220,7 +220,7 @@ define(['jquery', */ Wizard.addFinalProcessingSlide(function() { $.post(_dashboardManagerApp.getAjaxEndpoint('createWidget'), { - tx_dashboard_system_dashboarddashboardmod1: { + tx_dashboard_user_dashboarddashboardmod1: { widgetType: Wizard.setup.settings['widgetType'], id: dashboard.id } @@ -278,7 +278,7 @@ define(['jquery', }); }); $.post(_dashboardManagerApp.getAjaxEndpoint('change'), { - tx_dashboard_system_dashboarddashboardmod1: { + tx_dashboard_user_dashboarddashboardmod1: { items: itemsData } }, function(data, textStatus, jqXHR) { @@ -330,7 +330,7 @@ define(['jquery', Icons.getIcon('spinner-circle-dark', Icons.sizes.large, null, null).done(function(markup) { $(target).html($('
', {class: 'text-center'}).append(markup)); $.post(_dashboardManagerApp.getAjaxEndpoint('renderWidget'), { - tx_dashboard_system_dashboarddashboardmod1: { + tx_dashboard_user_dashboarddashboardmod1: { widgetId: widgetId } }, function(data, textStatus, jqXHR) { diff --git a/ext_tables.php b/ext_tables.php index bece321..1f7272f 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -10,7 +10,7 @@ */ \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( 'TYPO3\CMS.' . $_EXTKEY, - 'system', // Make module a submodule of 'user' + 'user', // Make module a submodule of 'user' 'dashboardmod1', // Submodule key '', // Position array( From e7aea87645d69d0814dc552519ebe11df442d54f Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 11:58:29 +0200 Subject: [PATCH 02/36] Minor cleanups in controller --- Classes/Controller/DashboardController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 0ae90d0..1998c40 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -51,6 +51,11 @@ class DashboardController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContro */ protected $dashboardSettings; + /** + * @var BackendTemplateView + */ + protected $view; + /** * Default View Container * @@ -97,11 +102,11 @@ public function initializeAction() if ($this->request->hasArgument('id')) { $this->dashboard = $this->dashboardRepository->findByUid($this->request->getArgument('id')); - if ($this->dashboard->getBeUser()->getuid() != $this->getBackendUser()->user['uid']) { + if ($this->dashboard->getBeUser()->getUid() !== (int)$this->getBackendUser()->user['uid']) { throw new \Exception("Access denied to selected dashboard", 1); } } else { - $this->dashboard = $this->dashboardRepository->findByBeuser($this->getBackendUser()->user['uid'])->getFirst(); + $this->dashboard = $this->dashboardRepository->findOneByBeuser($this->getBackendUser()->user['uid']); }; } @@ -445,7 +450,6 @@ protected function getNextRow(int $dasboardId): int { $retval = 0; - /** @var QueryBuilder $queryBuilder */ $queryBuilder = GeneralUtility::makeInstance( \TYPO3\CMS\Core\Database\ConnectionPool::class From c7488df4e027a956abbbf3ab42619af73667aa4d Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 12:06:21 +0200 Subject: [PATCH 03/36] Fix and enforce coding style --- .gitignore | 1 + .php_cs.dist | 77 ++++ .styleci.yml | 59 +++ Classes/Controller/DashboardController.php | 31 +- Classes/DashboardWidgetInterface.php | 1 - Classes/DashboardWidgets/AbstractWidget.php | 9 +- Classes/DashboardWidgets/ActionWidget.php | 20 +- Classes/DashboardWidgets/IframeWidget.php | 9 +- Classes/DashboardWidgets/RssWidget.php | 436 +++++++++--------- Classes/DashboardWidgets/SysNewsWidget.php | 13 +- Classes/Domain/Model/Dashboard.php | 1 - .../Domain/Model/DashboardWidgetSettings.php | 25 +- .../DashboardWidget/EditOnClickViewHelper.php | 1 - .../GridAttributesViewHelper.php | 9 +- .../Be/DashboardWidget/IconSrcViewHelper.php | 1 - .../Be/DashboardWidget/SizeViewHelper.php | 3 +- .../Be/DashboardWidgetViewHelper.php | 4 +- .../tx_dashboard_domain_model_dashboard.php | 19 +- ...d_domain_model_dashboardwidgetsettings.php | 35 +- .../Controller/DashboardControllerTest.php | 7 +- Tests/Unit/Domain/Model/DashboardTest.php | 5 +- .../Model/DashboardWidgetSettingsTest.php | 1 - .../Unit/Domain/Model/DashboardWidgetTest.php | 1 - .../Model/DashboardWidgetWelcomeTest.php | 1 - ext_localconf.php | 2 +- ext_tables.php | 35 +- ext_typoscript_setup.txt | 11 +- 27 files changed, 467 insertions(+), 350 deletions(-) create mode 100644 .gitignore create mode 100644 .php_cs.dist create mode 100644 .styleci.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4d83b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.php_cs.cache diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..b13755c --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,77 @@ +setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'binary_operator_spaces' => true, + 'concat_space' => [ + 'spacing' => 'one', + ], + 'function_typehint_space' => true, + 'hash_to_slash_comment' => true, + 'linebreak_after_opening_tag' => true, + 'lowercase_cast' => true, + 'method_separation' => true, + 'native_function_casing' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => [ + 'continue', + 'curly_brace_block', + 'extra', + 'parenthesis_brace_block', + 'square_brace_block', + 'throw', + ], + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unneeded_control_parentheses' => [ + 'break', + 'clone', + 'continue', + 'echo_print', + 'return', + 'switch_case', + ], + 'no_unreachable_default_argument_value' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_no_package' => true, + 'phpdoc_order' => true, + 'phpdoc_scalar' => true, + 'phpdoc_types' => true, + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'single_quote' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline_array' => true, + 'whitespace_after_comma_in_array' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->exclude('Resources') + ->notName('ext_emconf.php') + ); diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..5573af3 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,59 @@ +preset: psr2 + +enabled: + - alpha_ordered_imports + - binary_operator_spaces + - concat_with_spaces + - function_typehint_space + - hash_to_slash_comment + - linebreak_after_opening_tag + - lowercase_cast + - method_separation + - native_function_casing + - new_with_braces + - no_alias_functions + - no_blank_lines_after_class_opening + - no_blank_lines_after_phpdoc + - no_blank_lines_before_namespace + - no_empty_comment + - no_empty_phpdoc + - no_empty_statement + - no_extra_block_blank_lines + - no_extra_consecutive_blank_lines + - no_leading_import_slash + - no_leading_namespace_whitespace + - no_multiline_whitespace_around_double_arrow + - no_multiline_whitespace_before_semicolons + - no_short_bool_cast + - no_singleline_whitespace_before_semicolons + - no_trailing_comma_in_list_call + - no_trailing_comma_in_singleline_array + - no_unneeded_control_parentheses + - no_unreachable_default_argument_value + - no_unused_imports + - no_useless_else + - no_useless_return + - no_whitespace_before_comma_in_array + - no_whitespace_in_blank_line + - normalize_index_brace + - phpdoc_add_missing_param_annotation + - phpdoc_no_package + - phpdoc_order + - phpdoc_scalar + - phpdoc_types + - self_accessor + - short_array_syntax + - short_scalar_cast + - single_quote + - standardize_not_equals + - ternary_operator_spaces + - trailing_comma_in_multiline_array + - whitespace_after_comma_in_array + +finder: + name: + - "*.php" + exclude: + - "Resources" + not-name: + - "ext_emconf.php" diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 1998c40..2e6cecb 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -26,26 +26,25 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Extbase\Object\ObjectManager; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\PathUtility; -use TYPO3\CMS\Core\Page\PageRenderer; +use TYPO3\CMS\Backend\Template\Components\ButtonBar; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\BackendTemplateView; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; -use TYPO3\CMS\Lang\LanguageService; use TYPO3\CMS\Core\Imaging\Icon; -use TYPO3\CMS\Backend\Template\Components\ButtonBar; +use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\ArrayUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\PathUtility; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; +use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Form\Service\TranslationService; -use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Lang\LanguageService; /** * DashboardController */ class DashboardController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController { - /** * @var array */ @@ -103,11 +102,11 @@ public function initializeAction() if ($this->request->hasArgument('id')) { $this->dashboard = $this->dashboardRepository->findByUid($this->request->getArgument('id')); if ($this->dashboard->getBeUser()->getUid() !== (int)$this->getBackendUser()->user['uid']) { - throw new \Exception("Access denied to selected dashboard", 1); + throw new \Exception('Access denied to selected dashboard', 1); } } else { $this->dashboard = $this->dashboardRepository->findOneByBeuser($this->getBackendUser()->user['uid']); - }; + } } /** @@ -273,10 +272,10 @@ public function renderWidgetAction() $content = $this->getHtmlErrorMessage($errorTitle, $localizedError); } } else { - $content = $this->getHtmlErrorMessage($errorTitle, 'Class : ' . $widgetClassName .' could not be found!'); + $content = $this->getHtmlErrorMessage($errorTitle, 'Class : ' . $widgetClassName . ' could not be found!'); } } else { - $content = $this->getHtmlErrorMessage($errorTitle, 'Widget [' . $widgetId .'] could not be found!'); + $content = $this->getHtmlErrorMessage($errorTitle, 'Widget [' . $widgetId . '] could not be found!'); } } return $content; @@ -344,7 +343,7 @@ protected function registerDocheaderButtons() ->setDataAttributes( [ 'identifier' => 'newDashboardWidgetSetting', - 'dashboardid' => $this->dashboard->getUid() + 'dashboardid' => $this->dashboard->getUid(), ] ) ->setHref('#') @@ -442,9 +441,9 @@ protected function getWidgetSettings(string $widgetIdentifier): array /** * Returns next available "row" * - * @param integer $dasboardId + * @param int $dasboardId * - * @return integer + * @return int */ protected function getNextRow(int $dasboardId): int { diff --git a/Classes/DashboardWidgetInterface.php b/Classes/DashboardWidgetInterface.php index 6f6e81a..43e717d 100644 --- a/Classes/DashboardWidgetInterface.php +++ b/Classes/DashboardWidgetInterface.php @@ -6,7 +6,6 @@ */ interface DashboardWidgetInterface { - /** * Render content * diff --git a/Classes/DashboardWidgets/AbstractWidget.php b/Classes/DashboardWidgets/AbstractWidget.php index 0d5a7f6..c2de70e 100644 --- a/Classes/DashboardWidgets/AbstractWidget.php +++ b/Classes/DashboardWidgets/AbstractWidget.php @@ -15,16 +15,17 @@ * */ use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Service\FlexFormService; use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; +use TYPO3\CMS\Extbase\Service\FlexFormService; -class AbstractWidget { - +class AbstractWidget +{ /** * @param DashboardWidgetSettings $dashboardWidgetSetting * @return array */ - public function getFlexFormSettings($dashboardWidgetSetting) { + public function getFlexFormSettings($dashboardWidgetSetting) + { $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); /** @var FlexFormService $flexFormService */ $flexFormService = $objectManager->get('TYPO3\\CMS\\Extbase\\Service\\FlexFormService'); diff --git a/Classes/DashboardWidgets/ActionWidget.php b/Classes/DashboardWidgets/ActionWidget.php index 47e4b32..e09e168 100644 --- a/Classes/DashboardWidgets/ActionWidget.php +++ b/Classes/DashboardWidgets/ActionWidget.php @@ -15,15 +15,15 @@ * */ use TYPO3\CMS\Backend\Utility\BackendUtility; -#use TYPO3\CMS\Backend\Utility\IconUtility; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Fluid\View\StandaloneView; -use TYPO3\CMS\Dashboard\DashboardWidgetInterface; -use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; - +//use TYPO3\CMS\Backend\Utility\IconUtility; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; use TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; + +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Dashboard\DashboardWidgetInterface; +use TYPO3\CMS\Fluid\View\StandaloneView; class ActionWidget extends AbstractWidget implements DashboardWidgetInterface { @@ -32,7 +32,7 @@ class ActionWidget extends AbstractWidget implements DashboardWidgetInterface /** * Limit, If set, it will limit the results in the list. * - * @var integer + * @var int */ protected $limit = 0; @@ -62,13 +62,13 @@ private function initialize($dashboardWidgetSetting = null) /** * Generates the content - * @return string * @throws 1910010001 + * @return string */ private function generateContent() { if (!ExtensionManagementUtility::isLoaded('sys_action')) { - throw new \Exception("Extension sys_actions is not enabled", 1910010001); + throw new \Exception('Extension sys_actions is not enabled', 1910010001); } $actionEntries = []; $widgetTemplateName = $this->widget['template']; @@ -154,7 +154,7 @@ protected function getActions() . '&SET[function]=sys_action.' . \TYPO3\CMS\SysAction\ActionTask::class . '&show=' - . (int)$actionRow['uid'] + . (int)$actionRow['uid'], ]; } diff --git a/Classes/DashboardWidgets/IframeWidget.php b/Classes/DashboardWidgets/IframeWidget.php index 6d326c6..777e099 100644 --- a/Classes/DashboardWidgets/IframeWidget.php +++ b/Classes/DashboardWidgets/IframeWidget.php @@ -20,7 +20,6 @@ class IframeWidget extends AbstractWidget implements DashboardWidgetInterface { - const IDENTIFIER = '1487642496'; /** @@ -42,7 +41,7 @@ class IframeWidget extends AbstractWidget implements DashboardWidgetInterface * * @var array */ - protected $widget = array(); + protected $widget = []; /** * Renders content @@ -80,10 +79,10 @@ private function generateContent() $actionView = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); $template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($widgetTemplateName); $actionView->setTemplatePathAndFilename($template); - $actionView->assignMultiple(array( + $actionView->assignMultiple([ 'url' => $this->url, - 'scrolling' => $this->scrolling - )); + 'scrolling' => $this->scrolling, + ]); return $actionView->render(); } } diff --git a/Classes/DashboardWidgets/RssWidget.php b/Classes/DashboardWidgets/RssWidget.php index b0890f7..17e2f1c 100644 --- a/Classes/DashboardWidgets/RssWidget.php +++ b/Classes/DashboardWidgets/RssWidget.php @@ -3,230 +3,232 @@ /** * Class RssWidget - * @package TYPO3\CMS\Dashboard\DashboardWidgets */ - use TYPO3\CMS\Dashboard\DashboardWidgetInterface; -class RssWidget extends AbstractWidget implements DashboardWidgetInterface { - - const IDENTIFIER = '41385600'; - - /** - * Feed URL - * - * @var string - * @validate NotEmpty - */ - protected $feedUrl = ''; - - /** - * Limit, If set, it will limit the results in the list. - * - * @var integer - */ - protected $feedLimit = 0; - - /** - * Limit, If set, it will limit the results in the list. - * - * @var integer - */ - protected $cacheLifetime = NULL; - - /** - * Widget settings - * - * @var array - */ - protected $widget = NULL; - - /** - * Renders content - * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting - * @return string the rendered content - */ - public function render($dashboardWidgetSetting = NULL) { - - $this->initialize($dashboardWidgetSetting); - - $content = false; - if ($this->cacheLifetime == NULL) { - $content = $this->generateContent(); - } else { - /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ - $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Core\\Cache\\CacheManager'); - $cacheIdentifier = 'dashboardWidget_' . (int)$dashboardWidgetSetting->getUid(); - - if (TRUE === $cacheManager->hasCache('dashboard') && TRUE === $cacheManager->getCache('dashboard')->has($cacheIdentifier)) { - $content = $cacheManager->getCache('dashboard')->get($cacheIdentifier); - } else { - $content = $this->generateContent(); - $cacheManager->getCache('dashboard')->set($cacheIdentifier, $content, array(), $this->cacheLifetime); - } - unset($cacheManager); - } - return $content; - } - - /** - * Initializes settings from flexform - * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting - * @return void - */ - private function initialize($dashboardWidgetSetting = NULL) { +class RssWidget extends AbstractWidget implements DashboardWidgetInterface +{ + const IDENTIFIER = '41385600'; + + /** + * Feed URL + * + * @var string + * @validate NotEmpty + */ + protected $feedUrl = ''; + + /** + * Limit, If set, it will limit the results in the list. + * + * @var int + */ + protected $feedLimit = 0; + + /** + * Limit, If set, it will limit the results in the list. + * + * @var int + */ + protected $cacheLifetime = null; + + /** + * Widget settings + * + * @var array + */ + protected $widget = null; + + /** + * Renders content + * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @return string the rendered content + */ + public function render($dashboardWidgetSetting = null) + { + $this->initialize($dashboardWidgetSetting); + + $content = false; + if ($this->cacheLifetime == null) { + $content = $this->generateContent(); + } else { + /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ + $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Core\\Cache\\CacheManager'); + $cacheIdentifier = 'dashboardWidget_' . (int)$dashboardWidgetSetting->getUid(); + + if (true === $cacheManager->hasCache('dashboard') && true === $cacheManager->getCache('dashboard')->has($cacheIdentifier)) { + $content = $cacheManager->getCache('dashboard')->get($cacheIdentifier); + } else { + $content = $this->generateContent(); + $cacheManager->getCache('dashboard')->set($cacheIdentifier, $content, [], $this->cacheLifetime); + } + unset($cacheManager); + } + return $content; + } + + /** + * Initializes settings from flexform + * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @return void + */ + private function initialize($dashboardWidgetSetting = null) + { $flexformSettings = $this->getFlexFormSettings($dashboardWidgetSetting); $this->feedUrl = $flexformSettings['settings']['feedUrl']; $this->feedLimit = (int)$flexformSettings['settings']['feedLimit']; $this->cacheLifetime = (int)$flexformSettings['settings']['cacheLifetime'] * 60; $this->widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$dashboardWidgetSetting->getWidgetIdentifier()]; - } - - /** - * Generates the content - * @return string - */ - private function generateContent() { - $widgetTemplateName = $this->widget['template']; + } + + /** + * Generates the content + * @return string + */ + private function generateContent() + { + $widgetTemplateName = $this->widget['template']; $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); - $rssView = $objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); - $template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($widgetTemplateName); - $rssView->setTemplatePathAndFilename($template); - $feed = $this->getFeed(); - $rssView->assign('feed', $feed); - $rssView->assign('currentdate', time()); - $rssView->assign('cacheLifetime', $this->cacheLifetime); - return $rssView->render(); - } - - /** - * Loads feed and cuts unneeded items - * - * @return array Array from xml - */ - private function getFeed() { - $feed = []; - $report = []; - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($this->feedUrl)) { - - $content = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl( - $this->feedUrl, - 0, - null, - $report - ); - if (!$content) { - if (isset($report['message'])) { - throw new \Exception($report['message'], $report['error']); - } else { - throw new \Exception("The response was empty", 1910020001); - } - } - if (!empty($content)) { - $simpleXmlElement = simplexml_load_string( $content ,'SimpleXMLElement'); - if (!$simpleXmlElement) { - throw new \Exception('The response is not valid XML', 1910020003); - } - $feed['channel'] = $this->rssToArray($simpleXmlElement); - if ((int)$this->feedLimit > 0) { - $feed['channel']['item'] = array_splice($feed['channel']['item'], 0, $this->feedLimit); - } - } else { - throw new \Exception('An error occured', 1910020002); - } - } else { - throw new \Exception('The provided url is not valid', 1910020004); - } - return $feed; - } - - /** - * rssToArray RSS to array from a SimpleXMLElement - * @param \SimpleXmlElement $simpleXmlElement - * @return array - */ - private function rssToArray($simpleXmlElement) { - $rss2Array = array(); - $rss2Array = $this->sxeToArray($simpleXmlElement->channel); - foreach($simpleXmlElement->channel->item as $simpleXmlElementItem) { - $simpleXmlElementArray = $this->sxeToArray($simpleXmlElementItem); - if ($simpleXmlElementArray) { - $rss2Array['item'][] = $simpleXmlElementArray; - } - } - return $rss2Array; - } - - /** - * sxeToArray Generates the base array for the element, also includes namespaces. - * @param \SimpleXMLElement $simpleXmlElement The element to create an array of - * @return array - */ - private function sxeToArray($simpleXmlElement) { - $returnArray = false; - $children = $simpleXmlElement->children(); - $sxeChildrenToArray = $this->sxeChildrenToArray($children); - if ($sxeChildrenToArray) { - $returnArray = $sxeChildrenToArray; - } - $namespaces = $simpleXmlElement->getNamespaces(TRUE); - foreach ($namespaces as $ns => $nsuri) { - $children = $simpleXmlElement->children($ns, true); - $sxeChildrenToArray = $this->sxeChildrenToArray($children); - if ($sxeChildrenToArray) { - $returnArray[$ns] = $sxeChildrenToArray; - } - } - return $returnArray; - } - - /** - * sxeChildrenToArray Returns an array of the elements children and attributes recursively - * @param mixed $children The children of a element - * @return array - */ - private function sxeChildrenToArray($children) { - $nodeData = array(); - if (count($children) > 0) { - foreach ($children as $elementName => $node) { - $nodeName = $this->stringToArrayKey((string)$elementName); - $nodeData[$nodeName] = array(); - $nodeAttributes = $node->attributes(); - if (count($nodeAttributes) > 0) { - foreach ($nodeAttributes as $nodeAttributeName => $nodeAttributeValue) { - $arrayKey = $this->stringToArrayKey((string)$nodeAttributeName); - $arrayValue = trim((string)$nodeAttributeValue->__toString()); - $nodeData[$nodeName][$arrayKey] = $arrayValue; - } - } - $nodeValue = trim((string)$node); - if (strlen($nodeValue) > 0) { - if (count($nodeAttributes) == 0) { - $nodeData[$nodeName] = $nodeValue; - } else { - $nodeData[$nodeName]['value'] = $nodeValue; - } - } else { - if ($nodeName != 'item') { - $childs = $this->sxeToArray($node); - if ($childs) { - $nodeData[$nodeName] = $childs; - } - } - } - } - return $nodeData; - } else { - return false; - } - } - - /** - * stringToArrayKey Returns a string which is ok to use as array key - * @param string $key The array key to check - * @return string - */ - private function stringToArrayKey($key) { - return str_replace('.', '_', trim((string)$key)); - } + $rssView = $objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); + $template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($widgetTemplateName); + $rssView->setTemplatePathAndFilename($template); + $feed = $this->getFeed(); + $rssView->assign('feed', $feed); + $rssView->assign('currentdate', time()); + $rssView->assign('cacheLifetime', $this->cacheLifetime); + return $rssView->render(); + } + + /** + * Loads feed and cuts unneeded items + * + * @return array Array from xml + */ + private function getFeed() + { + $feed = []; + $report = []; + if (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($this->feedUrl)) { + $content = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl( + $this->feedUrl, + 0, + null, + $report + ); + if (!$content) { + if (isset($report['message'])) { + throw new \Exception($report['message'], $report['error']); + } + throw new \Exception('The response was empty', 1910020001); + } + if (!empty($content)) { + $simpleXmlElement = simplexml_load_string($content, 'SimpleXMLElement'); + if (!$simpleXmlElement) { + throw new \Exception('The response is not valid XML', 1910020003); + } + $feed['channel'] = $this->rssToArray($simpleXmlElement); + if ((int)$this->feedLimit > 0) { + $feed['channel']['item'] = array_splice($feed['channel']['item'], 0, $this->feedLimit); + } + } else { + throw new \Exception('An error occured', 1910020002); + } + } else { + throw new \Exception('The provided url is not valid', 1910020004); + } + return $feed; + } + + /** + * rssToArray RSS to array from a SimpleXMLElement + * @param \SimpleXmlElement $simpleXmlElement + * @return array + */ + private function rssToArray($simpleXmlElement) + { + $rss2Array = []; + $rss2Array = $this->sxeToArray($simpleXmlElement->channel); + foreach ($simpleXmlElement->channel->item as $simpleXmlElementItem) { + $simpleXmlElementArray = $this->sxeToArray($simpleXmlElementItem); + if ($simpleXmlElementArray) { + $rss2Array['item'][] = $simpleXmlElementArray; + } + } + return $rss2Array; + } + + /** + * sxeToArray Generates the base array for the element, also includes namespaces. + * @param \SimpleXMLElement $simpleXmlElement The element to create an array of + * @return array + */ + private function sxeToArray($simpleXmlElement) + { + $returnArray = false; + $children = $simpleXmlElement->children(); + $sxeChildrenToArray = $this->sxeChildrenToArray($children); + if ($sxeChildrenToArray) { + $returnArray = $sxeChildrenToArray; + } + $namespaces = $simpleXmlElement->getNamespaces(true); + foreach ($namespaces as $ns => $nsuri) { + $children = $simpleXmlElement->children($ns, true); + $sxeChildrenToArray = $this->sxeChildrenToArray($children); + if ($sxeChildrenToArray) { + $returnArray[$ns] = $sxeChildrenToArray; + } + } + return $returnArray; + } + + /** + * sxeChildrenToArray Returns an array of the elements children and attributes recursively + * @param mixed $children The children of a element + * @return array + */ + private function sxeChildrenToArray($children) + { + $nodeData = []; + if (count($children) > 0) { + foreach ($children as $elementName => $node) { + $nodeName = $this->stringToArrayKey((string)$elementName); + $nodeData[$nodeName] = []; + $nodeAttributes = $node->attributes(); + if (count($nodeAttributes) > 0) { + foreach ($nodeAttributes as $nodeAttributeName => $nodeAttributeValue) { + $arrayKey = $this->stringToArrayKey((string)$nodeAttributeName); + $arrayValue = trim((string)$nodeAttributeValue->__toString()); + $nodeData[$nodeName][$arrayKey] = $arrayValue; + } + } + $nodeValue = trim((string)$node); + if (strlen($nodeValue) > 0) { + if (count($nodeAttributes) == 0) { + $nodeData[$nodeName] = $nodeValue; + } else { + $nodeData[$nodeName]['value'] = $nodeValue; + } + } else { + if ($nodeName != 'item') { + $childs = $this->sxeToArray($node); + if ($childs) { + $nodeData[$nodeName] = $childs; + } + } + } + } + return $nodeData; + } + return false; + } + + /** + * stringToArrayKey Returns a string which is ok to use as array key + * @param string $key The array key to check + * @return string + */ + private function stringToArrayKey($key) + { + return str_replace('.', '_', trim((string)$key)); + } } diff --git a/Classes/DashboardWidgets/SysNewsWidget.php b/Classes/DashboardWidgets/SysNewsWidget.php index 6cf3086..d2779ab 100644 --- a/Classes/DashboardWidgets/SysNewsWidget.php +++ b/Classes/DashboardWidgets/SysNewsWidget.php @@ -19,13 +19,12 @@ class SysNewsWidget extends AbstractWidget implements DashboardWidgetInterface { - - const IDENTIFIER = '1439446997'; + const IDENTIFIER = '1439446997'; /** * Limit, If set, it will limit the results in the list. * - * @var integer + * @var int */ protected $limit = 0; @@ -77,7 +76,7 @@ private function generateContent() protected function getSystemNews() { $systemNewsTable = 'sys_news'; - $systemNews = array(); + $systemNews = []; $systemNewsRecords = $this->getDatabaseConnection()->exec_SELECTgetRows( 'title, content, crdate', $systemNewsTable, @@ -87,11 +86,11 @@ protected function getSystemNews() $this->getLimit() ); foreach ($systemNewsRecords as $systemNewsRecord) { - $systemNews[] = array( + $systemNews[] = [ 'date' => $systemNewsRecord['crdate'], 'header' => $systemNewsRecord['title'], - 'content' => $systemNewsRecord['content'] - ); + 'content' => $systemNewsRecord['content'], + ]; } return $systemNews; } diff --git a/Classes/Domain/Model/Dashboard.php b/Classes/Domain/Model/Dashboard.php index 124011e..80cc0d1 100644 --- a/Classes/Domain/Model/Dashboard.php +++ b/Classes/Domain/Model/Dashboard.php @@ -31,7 +31,6 @@ */ class Dashboard extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { - /** * Title * diff --git a/Classes/Domain/Model/DashboardWidgetSettings.php b/Classes/Domain/Model/DashboardWidgetSettings.php index 273a086..70c48d2 100644 --- a/Classes/Domain/Model/DashboardWidgetSettings.php +++ b/Classes/Domain/Model/DashboardWidgetSettings.php @@ -31,7 +31,6 @@ */ class DashboardWidgetSettings extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { - /** * Title * @@ -56,28 +55,28 @@ class DashboardWidgetSettings extends \TYPO3\CMS\Extbase\DomainObject\AbstractEn /** * x * - * @var integer + * @var int */ protected $x = 0; /** * y * - * @var integer + * @var int */ protected $y = 0; /** * width * - * @var integer + * @var int */ protected $width = 0; /** * height * - * @var integer + * @var int */ protected $height = 0; @@ -133,7 +132,7 @@ public function setState($state) /** * Returns the x * - * @return integer $x + * @return int $x */ public function getX() { @@ -143,7 +142,7 @@ public function getX() /** * Sets the x * - * @param integer $x + * @param int $x * @return void */ public function setX($x) @@ -154,7 +153,7 @@ public function setX($x) /** * Returns the y * - * @return integer $y + * @return int $y */ public function getY() { @@ -164,7 +163,7 @@ public function getY() /** * Sets the y * - * @param integer $y + * @param int $y * @return void */ public function setY($y) @@ -175,7 +174,7 @@ public function setY($y) /** * Returns the width * - * @return integer $width + * @return int $width */ public function getWidth() { @@ -185,7 +184,7 @@ public function getWidth() /** * Sets the width * - * @param integer $width + * @param int $width * @return void */ public function setWidth($width) @@ -196,7 +195,7 @@ public function setWidth($width) /** * Returns the height * - * @return integer $height + * @return int $height */ public function getHeight() { @@ -206,7 +205,7 @@ public function getHeight() /** * Sets the height * - * @param integer $height + * @param int $height * @return void */ public function setHeight($height) diff --git a/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php index ba82d08..8626dcc 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php @@ -46,7 +46,6 @@ */ class EditOnClickViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { - /** * Renders a record list as known from the TYPO3 list module * Note: This feature is experimental! diff --git a/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php index ab3dfc4..925c8fb 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php @@ -21,7 +21,6 @@ * The TYPO3 project - inspiring people to share! * * */ -use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper; class GridAttributesViewHelper extends AbstractBackendViewHelper @@ -30,7 +29,7 @@ class GridAttributesViewHelper extends AbstractBackendViewHelper * Returns a widget drop and drop attributes * * @param TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $widgetSetting - * @param integer $index + * @param int $index * @param string $className * * @return string element grid attributes @@ -73,8 +72,8 @@ public function render($widgetSetting, $index, $className = 'grid-item') /** * Returns the correct grid item width * - * @param integer $width - * @param integer $numberOfCols + * @param int $width + * @param int $numberOfCols * @return string css class name */ protected function getItemWidth($width, $numberOfCols) @@ -92,7 +91,7 @@ protected function getItemWidth($width, $numberOfCols) /** * Returns the correct grid item height * - * @param integer $height + * @param int $height * @return string css class name */ protected function getItemHeight($height) diff --git a/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php index 063bdac..ff7e92a 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php @@ -22,7 +22,6 @@ * */ class IconSrcViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { - /** * Returns path to widget icon * diff --git a/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php index ec7fb4e..5d90dc4 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php @@ -22,7 +22,6 @@ * */ class SizeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { - /** * Returns path to widget icon * @@ -33,7 +32,7 @@ public function render($widgetIdentifier) { $widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widgetIdentifier]; list($width, $height) = explode('x', $widget['size']); - return $this->getColumnClassName((int)$width) . " " . $this->getHeightClassName((int)$height); + return $this->getColumnClassName((int)$width) . ' ' . $this->getHeightClassName((int)$height); } /** diff --git a/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php index e81c517..2d73e0e 100644 --- a/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php @@ -46,7 +46,6 @@ */ class DashboardWidgetViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { - /** * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface * @inject @@ -73,8 +72,7 @@ public function render($dashboardWidgetSetting) if (class_exists($widgetClassName)) { $widgetClass = $this->objectManager->get($widgetClassName); return $widgetClass->render($dashboardWidgetSetting); - } else { - return 'Class : ' . $widgetClassName .' could not be found!'; } + return 'Class : ' . $widgetClassName . ' could not be found!'; } } diff --git a/Configuration/TCA/tx_dashboard_domain_model_dashboard.php b/Configuration/TCA/tx_dashboard_domain_model_dashboard.php index 32fc189..826d723 100644 --- a/Configuration/TCA/tx_dashboard_domain_model_dashboard.php +++ b/Configuration/TCA/tx_dashboard_domain_model_dashboard.php @@ -1,7 +1,7 @@ [ - 'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboard', + 'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboard', 'label' => 'title', 'tstamp' => 'tstamp', 'crdate' => 'crdate', @@ -19,7 +19,7 @@ 'endtime' => 'endtime', ], 'searchFields' => 'title,description,dashboard_widget_settings,beuser,', - 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboard.gif' + 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboard.gif', ], 'interface' => [ 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title, description, dashboard_widget_settings, beuser', @@ -48,7 +48,7 @@ 'items' => [ [ '', - 0 + 0, ], ], 'foreign_table' => 'tx_dashboard_domain_model_dashboard', @@ -66,7 +66,6 @@ 'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden', 'config' => [ 'type' => 'check', - ], ], 'starttime' => [ @@ -81,7 +80,7 @@ 'checkbox' => 0, 'default' => 0, 'range' => [ - 'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y')) + 'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y')), ], ], ], @@ -97,7 +96,7 @@ 'checkbox' => 0, 'default' => 0, 'range' => [ - 'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y')) + 'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y')), ], ], ], @@ -107,7 +106,7 @@ 'config' => [ 'type' => 'input', 'size' => 30, - 'eval' => 'trim,required' + 'eval' => 'trim,required', ], ], 'description' => [ @@ -116,7 +115,7 @@ 'config' => [ 'type' => 'input', 'size' => 30, - 'eval' => 'trim' + 'eval' => 'trim', ], ], 'dashboard_widget_settings' => [ @@ -134,7 +133,7 @@ 'levelLinksPosition' => 'top', 'showSynchronizationLink' => 1, 'showPossibleLocalizationRecords' => 1, - 'showAllLocalizationLink' => 1 + 'showAllLocalizationLink' => 1, ], ], ], @@ -152,7 +151,7 @@ 'levelLinksPosition' => 'top', 'showSynchronizationLink' => 1, 'showPossibleLocalizationRecords' => 1, - 'showAllLocalizationLink' => 1 + 'showAllLocalizationLink' => 1, ], ], ], diff --git a/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php b/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php index dfc180c..e6b0548 100644 --- a/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php +++ b/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php @@ -1,7 +1,7 @@ [ - 'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboardwidgetsettings', + 'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboardwidgetsettings', 'label' => 'title', 'tstamp' => 'tstamp', 'crdate' => 'crdate', @@ -14,20 +14,19 @@ 'delete' => 'deleted', 'enablecolumns' => [], 'searchFields' => 'title,widget_identifier,position,settings_flexform,', - 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboardwidgetsettings.gif' - + 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboardwidgetsettings.gif', ], 'interface' => [ 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, title, widget_identifier, position, settings_flexform, dashboard, x, y, width, height', ], 'types' => [ '1' => [ - 'showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, title, widget_identifier, position, settings_flexform, dashboard, x, y, width, height, ' + 'showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, title, widget_identifier, position, settings_flexform, dashboard, x, y, width, height, ', ], ], 'palettes' => [ '1' => [ - 'showitem' => '' + 'showitem' => '', ], ], 'columns' => [ @@ -64,7 +63,7 @@ 'config' => [ 'type' => 'input', 'size' => 30, - 'eval' => 'trim' + 'eval' => 'trim', ], ], 'widget_identifier' => [ @@ -77,23 +76,23 @@ 'items' => [ [ '-- Label --', - '0' + '0', ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', - \TYPO3\CMS\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER + \TYPO3\CMS\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER, ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', - \TYPO3\CMS\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER + \TYPO3\CMS\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER, ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', - \TYPO3\CMS\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER + \TYPO3\CMS\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER, ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', - \TYPO3\CMS\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER + \TYPO3\CMS\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER, ], ], 'size' => 1, @@ -109,7 +108,7 @@ 'type' => 'input', 'readOnly' => 1, 'size' => 30, - 'eval' => 'int' + 'eval' => 'int', ], ], 'y' => [ @@ -117,9 +116,9 @@ 'label' => 'y', 'config' => [ 'type' => 'input', - 'readOnly' => 1, + 'readOnly' => 1, 'size' => 30, - 'eval' => 'int' + 'eval' => 'int', ], ], 'width' => [ @@ -127,9 +126,9 @@ 'label' => 'width', 'config' => [ 'type' => 'input', - 'readOnly' => 1, + 'readOnly' => 1, 'size' => 30, - 'eval' => 'int' + 'eval' => 'int', ], ], 'height' => [ @@ -137,9 +136,9 @@ 'label' => 'height', 'config' => [ 'type' => 'input', - 'readOnly' => 1, + 'readOnly' => 1, 'size' => 30, - 'eval' => 'int' + 'eval' => 'int', ], ], 'settings_flexform' => [ diff --git a/Tests/Unit/Controller/DashboardControllerTest.php b/Tests/Unit/Controller/DashboardControllerTest.php index 1a0ff54..4540244 100644 --- a/Tests/Unit/Controller/DashboardControllerTest.php +++ b/Tests/Unit/Controller/DashboardControllerTest.php @@ -30,7 +30,6 @@ */ class DashboardControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** * @var \TYPO3\CMS\Dashboard\Controller\DashboardController */ @@ -38,7 +37,7 @@ class DashboardControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase protected function setUp() { - $this->subject = $this->getMock('TYPO3\\CMS\\Dashboard\\Controller\\DashboardController', array('redirect', 'forward', 'addFlashMessage'), array(), '', false); + $this->subject = $this->getMock('TYPO3\\CMS\\Dashboard\\Controller\\DashboardController', ['redirect', 'forward', 'addFlashMessage'], [], '', false); } protected function tearDown() @@ -51,9 +50,9 @@ protected function tearDown() */ public function listActionFetchesAllDashboardsFromRepositoryAndAssignsThemToView() { - $allDashboards = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array(), array(), '', false); + $allDashboards = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', [], [], '', false); - $dashboardRepository = $this->getMock('TYPO3\\CMS\\Dashboard\\Domain\\Repository\\DashboardRepository', array('findAll'), array(), '', false); + $dashboardRepository = $this->getMock('TYPO3\\CMS\\Dashboard\\Domain\\Repository\\DashboardRepository', ['findAll'], [], '', false); $dashboardRepository->expects($this->once())->method('findAll')->will($this->returnValue($allDashboards)); $this->inject($this->subject, 'dashboardRepository', $dashboardRepository); diff --git a/Tests/Unit/Domain/Model/DashboardTest.php b/Tests/Unit/Domain/Model/DashboardTest.php index c40cd4d..2facec7 100644 --- a/Tests/Unit/Domain/Model/DashboardTest.php +++ b/Tests/Unit/Domain/Model/DashboardTest.php @@ -1,5 +1,4 @@ getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array('attach'), array(), '', false); + $dashboardWidgetSettingsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', ['attach'], [], '', false); $dashboardWidgetSettingsObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($dashboardWidgetSetting)); $this->inject($this->subject, 'dashboardWidgetSettings', $dashboardWidgetSettingsObjectStorageMock); @@ -148,7 +147,7 @@ public function addDashboardWidgetSettingToObjectStorageHoldingDashboardWidgetSe public function removeDashboardWidgetSettingFromObjectStorageHoldingDashboardWidgetSettings() { $dashboardWidgetSetting = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings(); - $dashboardWidgetSettingsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array('detach'), array(), '', false); + $dashboardWidgetSettingsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', ['detach'], [], '', false); $dashboardWidgetSettingsObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($dashboardWidgetSetting)); $this->inject($this->subject, 'dashboardWidgetSettings', $dashboardWidgetSettingsObjectStorageMock); diff --git a/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php b/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php index 2a4248a..b6e7c58 100644 --- a/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php +++ b/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php @@ -1,5 +1,4 @@ 'index, change, create, createWidget, renderWidget', - ), - array( + ], + [ 'access' => 'user,group', - 'icon' => 'EXT:' . $_EXTKEY . '/ext_icon.png', + 'icon' => 'EXT:' . $_EXTKEY . '/ext_icon.png', 'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_dashboardmod1.xlf', - ) + ] ); } @@ -34,9 +33,9 @@ $GLOBALS['TCA']['tx_dashboard_domain_model_dashboardwidgetsettings']['ctrl']['requestUpdate'] = 'widget_identifier'; -$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = array( - 'widgets' => array( - \TYPO3\CMS\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => array( +$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ + 'widgets' => [ + \TYPO3\CMS\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png', @@ -45,8 +44,8 @@ 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', - ), - \TYPO3\CMS\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => array( + ], + \TYPO3\CMS\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/ActionWidget.png', @@ -55,8 +54,8 @@ 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', - ), - \TYPO3\CMS\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => array( + ], + \TYPO3\CMS\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/SysNewsWidget.png', @@ -65,8 +64,8 @@ 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', - ), - \TYPO3\CMS\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => array( + ], + \TYPO3\CMS\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/frameWidget.png', @@ -75,6 +74,6 @@ 'defaultWidth' => '12', 'defaultHeight' => '6', 'minWidth' => '3', - ) - ) -); + ], + ], +]; diff --git a/ext_typoscript_setup.txt b/ext_typoscript_setup.txt index fbb1a38..3d16a29 100644 --- a/ext_typoscript_setup.txt +++ b/ext_typoscript_setup.txt @@ -11,15 +11,12 @@ module.tx_dashboard { viewModel = TYPO3/CMS/Dashboard/Backend/DashboardManager/ViewModel } selectablePrototypesConfiguration { - 100 { - identifier = standard - label = dashboardManager.selectablePrototypesConfiguration.standard.label + 100 { + identifier = standard + label = dashboardManager.selectablePrototypesConfiguration.standard.label } } translationFile = EXT:dashboard/Resources/Private/Language/locallang.xlf javaScriptTranslationFile = EXT:dashboard/Resources/Private/Language/locallang_dashboard_javascript.xlf - includeJsFiles { - # default = EXT:dashboard/Resources/Public/Js/dashboard.js - } } -} \ No newline at end of file +} From 3440f21bb460fc97be14d02e7ae6ead365abf87e Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 12:38:54 +0200 Subject: [PATCH 04/36] [!!!] Deprecate AbstractWidget The abstract widget only contains a helper method to convert a flexform string to an array, which really should be done in the widget settings model already. Deprecate the abstract and add a method to the model to return the array directly. This is breaking for widgets, that did not use the "settings" namespace in their flexforms --- Classes/DashboardWidgets/AbstractWidget.php | 15 ++++---- .../Domain/Model/DashboardWidgetSettings.php | 36 +++++++++++++++++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Classes/DashboardWidgets/AbstractWidget.php b/Classes/DashboardWidgets/AbstractWidget.php index c2de70e..ac96c94 100644 --- a/Classes/DashboardWidgets/AbstractWidget.php +++ b/Classes/DashboardWidgets/AbstractWidget.php @@ -14,21 +14,20 @@ * Public License for more details. * * */ -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; -use TYPO3\CMS\Extbase\Service\FlexFormService; -class AbstractWidget +/** + * @deprecated + */ +abstract class AbstractWidget { /** * @param DashboardWidgetSettings $dashboardWidgetSetting * @return array + * @deprecated */ - public function getFlexFormSettings($dashboardWidgetSetting) + public function getFlexFormSettings(DashboardWidgetSettings $dashboardWidgetSetting) { - $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); - /** @var FlexFormService $flexFormService */ - $flexFormService = $objectManager->get('TYPO3\\CMS\\Extbase\\Service\\FlexFormService'); - return $flexFormService->convertFlexFormContentToArray($dashboardWidgetSetting->getSettingsFlexform()); + return ['settings' => $dashboardWidgetSetting->getSettings()]; } } diff --git a/Classes/Domain/Model/DashboardWidgetSettings.php b/Classes/Domain/Model/DashboardWidgetSettings.php index 70c48d2..532f3a2 100644 --- a/Classes/Domain/Model/DashboardWidgetSettings.php +++ b/Classes/Domain/Model/DashboardWidgetSettings.php @@ -26,11 +26,34 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Service\FlexFormService; + /** - * Dashboard Widget Settings + * Represents dashboard widget Settings */ class DashboardWidgetSettings extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { + /** + * @var FlexFormService + */ + private $flexFormService; + + public function __construct(FlexFormService $flexFormService = null) + { + $this->flexFormService = $flexFormService ?: GeneralUtility::makeInstance(FlexFormService::class); + } + + /** + * Make sure a thawed object also gets this dependency injected + * + * @param FlexFormService $flexFormService + */ + public function injectFlexFormService(FlexFormService $flexFormService) + { + $this->flexFormService = $flexFormService; + } + /** * Title * @@ -39,7 +62,7 @@ class DashboardWidgetSettings extends \TYPO3\CMS\Extbase\DomainObject\AbstractEn protected $title = ''; /** - * Widget Indetifier + * Widget Identifier * * @var string */ @@ -217,12 +240,21 @@ public function setHeight($height) * Returns the settingsFlexform * * @return string $settingsFlexform + * @deprecated */ public function getSettingsFlexform() { return $this->settingsFlexform; } + public function getSettings(): array + { + if (empty($this->settingsFlexform)) { + return []; + } + return $this->flexFormService->convertFlexFormContentToArray($this->settingsFlexform)['settings'] ?? []; + } + /** * Sets the settingsFlexform * From 7bd5cee25e7148cee074ec369c47b4bd561a56ba Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:08:23 +0200 Subject: [PATCH 05/36] Move all settings related code to wizard settings class --- Classes/Controller/DashboardController.php | 56 +++++------ Classes/DashboardWidgets/ActionWidget.php | 8 +- Classes/DashboardWidgets/IframeWidget.php | 10 +- Classes/DashboardWidgets/RssWidget.php | 18 ++-- Classes/DashboardWidgets/SysNewsWidget.php | 18 ++-- .../Domain/Model/DashboardWidgetSettings.php | 99 ++++++------------- .../GridAttributesViewHelper.php | 5 +- .../Be/DashboardWidget/IconSrcViewHelper.php | 5 +- .../Be/DashboardWidget/SizeViewHelper.php | 5 +- .../Be/DashboardWidgetViewHelper.php | 57 +---------- .../Backend/DashboardManager/ViewModel.js | 2 +- 11 files changed, 97 insertions(+), 186 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 2e6cecb..c23a6a4 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -35,8 +35,10 @@ use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; +use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter; use TYPO3\CMS\Form\Service\TranslationService; use TYPO3\CMS\Lang\LanguageService; @@ -155,29 +157,28 @@ public function indexAction() $this->view->assign('dashboard', $this->dashboard); } + public function initializeChangeAction() + { + $configuration = $this->arguments->getArgument('items') + ->getPropertyMappingConfiguration(); + + $configuration->allowAllProperties(); + $configuration->forProperty('*')->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true); + $configuration->forProperty('*.*')->allowAllProperties(); + } + /** * action change * + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings> $items * @return string */ - public function changeAction() + public function changeAction($items) { - $getVars = $this->request->getArguments(); - $items = $getVars['items']; - if (!empty($items) && is_array($items)) { - foreach ($items as $index => $item) { - $widget = $this->dashboardWidgetSettingsRepository->findByUid($item['uid']); - $widget->setX($item['x']); - $widget->setY($item['y']); - $widget->setWidth($item['width']); - $widget->setHeight($item['height']); - $this->dashboardWidgetSettingsRepository->update($widget); - } - $this->objectManager - ->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class) - ->persistAll(); + foreach ($items as $widgetSettings) { + $this->dashboardWidgetSettingsRepository->update($widgetSettings); } - return 'sent string was: ' . print_r($getVars['items'], true); + return 'Updated widget positions'; } /** @@ -192,8 +193,8 @@ public function createWidgetAction() $storagePid = $this->dashboardSettings['persistence']['storagePid']; $widgetType = $getVars['widgetType']; $widgetSettings = $this->getWidgetSettings($widgetType); - $width = (isset($widgetSettings['defaultWidth'])) ? $widgetSettings['defaultWidth'] : 3; - $height = (isset($widgetSettings['defaultHeight'])) ? $widgetSettings['defaultHeight'] : 5; + $width = $widgetSettings['defaultWidth'] ?? 3; + $height = $widgetSettings['defaultHeight'] ?? 5; $overrideVals = '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][dashboard]=' . $this->dashboard->getUid(); $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][widget_identifier]=' . $getVars['widgetType']; $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][width]=' . $width; @@ -254,14 +255,14 @@ public function renderWidgetAction() ->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:error.title'); if (!empty($widgetId) && (int)$widgetId > 0) { - $widget = $this->dashboardWidgetSettingsRepository->findByUid($widgetId); - if ($widget) { - $widgetConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widget->getWidgetIdentifier()]; + $widgetSettings = $this->dashboardWidgetSettingsRepository->findByUid($widgetId); + if ($widgetSettings) { + $widgetConfiguration = $widgetSettings->getSettings(); $widgetClassName = $widgetConfiguration['class']; if (class_exists($widgetClassName)) { $widgetClass = $this->objectManager->get($widgetClassName); try { - return $widgetClass->render($widget); + return $widgetClass->render($widgetSettings); } catch (\Exception $e) { $localizedError = $this ->getLanguageService() @@ -423,19 +424,14 @@ protected function getSelectableWidgets(): array /** * Returns array of item configured for widget_identifier * - * @param string widgetIdentifier + * @param string $widgetIdentifier * * @return array */ protected function getWidgetSettings(string $widgetIdentifier): array { - $widgetSettings = []; - - $selectableWidgets = $this->getSelectableWidgets(); - if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widgetIdentifier])) { - $widgetSettings = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widgetIdentifier]; - } - return $widgetSettings; + $widgetSettings = new DashboardWidgetSettings($widgetIdentifier); + return $widgetSettings->getSettings(); } /** diff --git a/Classes/DashboardWidgets/ActionWidget.php b/Classes/DashboardWidgets/ActionWidget.php index e09e168..7c11760 100644 --- a/Classes/DashboardWidgets/ActionWidget.php +++ b/Classes/DashboardWidgets/ActionWidget.php @@ -25,7 +25,7 @@ use TYPO3\CMS\Dashboard\DashboardWidgetInterface; use TYPO3\CMS\Fluid\View\StandaloneView; -class ActionWidget extends AbstractWidget implements DashboardWidgetInterface +class ActionWidget implements DashboardWidgetInterface { const IDENTIFIER = '1439441923'; @@ -55,9 +55,9 @@ public function render($dashboardWidgetSetting = null) */ private function initialize($dashboardWidgetSetting = null) { - $flexformSettings = $this->getFlexFormSettings($dashboardWidgetSetting); - $this->limit = (int)$flexformSettings['settings']['limit']; - $this->widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$dashboardWidgetSetting->getWidgetIdentifier()]; + $settings = $dashboardWidgetSetting->getSettings(); + $this->limit = (int)$settings['limit']; + $this->widget = $settings; } /** diff --git a/Classes/DashboardWidgets/IframeWidget.php b/Classes/DashboardWidgets/IframeWidget.php index 777e099..10a5ba8 100644 --- a/Classes/DashboardWidgets/IframeWidget.php +++ b/Classes/DashboardWidgets/IframeWidget.php @@ -18,7 +18,7 @@ use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Fluid\View\StandaloneView; -class IframeWidget extends AbstractWidget implements DashboardWidgetInterface +class IframeWidget implements DashboardWidgetInterface { const IDENTIFIER = '1487642496'; @@ -62,10 +62,10 @@ public function render($dashboardWidgetSetting = null) */ private function initialize($dashboardWidgetSetting = null) { - $flexformSettings = $this->getFlexFormSettings($dashboardWidgetSetting); - $this->url = $flexformSettings['settings']['url']; - $this->scrolling = $flexformSettings['settings']['scrolling']; - $this->widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$dashboardWidgetSetting->getWidgetIdentifier()]; + $settings = $dashboardWidgetSetting->getSettings(); + $this->url = $settings['url']; + $this->scrolling = $settings['scrolling']; + $this->widget = $settings; } /** diff --git a/Classes/DashboardWidgets/RssWidget.php b/Classes/DashboardWidgets/RssWidget.php index 17e2f1c..3f4038a 100644 --- a/Classes/DashboardWidgets/RssWidget.php +++ b/Classes/DashboardWidgets/RssWidget.php @@ -6,7 +6,7 @@ */ use TYPO3\CMS\Dashboard\DashboardWidgetInterface; -class RssWidget extends AbstractWidget implements DashboardWidgetInterface +class RssWidget implements DashboardWidgetInterface { const IDENTIFIER = '41385600'; @@ -30,7 +30,7 @@ class RssWidget extends AbstractWidget implements DashboardWidgetInterface * * @var int */ - protected $cacheLifetime = null; + protected $cacheLifetime = 0; /** * Widget settings @@ -47,9 +47,7 @@ class RssWidget extends AbstractWidget implements DashboardWidgetInterface public function render($dashboardWidgetSetting = null) { $this->initialize($dashboardWidgetSetting); - - $content = false; - if ($this->cacheLifetime == null) { + if ($this->cacheLifetime > 0) { $content = $this->generateContent(); } else { /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ @@ -74,11 +72,11 @@ public function render($dashboardWidgetSetting = null) */ private function initialize($dashboardWidgetSetting = null) { - $flexformSettings = $this->getFlexFormSettings($dashboardWidgetSetting); - $this->feedUrl = $flexformSettings['settings']['feedUrl']; - $this->feedLimit = (int)$flexformSettings['settings']['feedLimit']; - $this->cacheLifetime = (int)$flexformSettings['settings']['cacheLifetime'] * 60; - $this->widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$dashboardWidgetSetting->getWidgetIdentifier()]; + $settings = $dashboardWidgetSetting->getSettings(); + $this->feedUrl = $settings['feedUrl']; + $this->feedLimit = (int)$settings['feedLimit']; + $this->cacheLifetime = (int)$settings['cacheLifetime'] * 60; + $this->widget = $settings; } /** diff --git a/Classes/DashboardWidgets/SysNewsWidget.php b/Classes/DashboardWidgets/SysNewsWidget.php index d2779ab..def9c38 100644 --- a/Classes/DashboardWidgets/SysNewsWidget.php +++ b/Classes/DashboardWidgets/SysNewsWidget.php @@ -17,7 +17,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Dashboard\DashboardWidgetInterface; -class SysNewsWidget extends AbstractWidget implements DashboardWidgetInterface +class SysNewsWidget implements DashboardWidgetInterface { const IDENTIFIER = '1439446997'; @@ -28,6 +28,13 @@ class SysNewsWidget extends AbstractWidget implements DashboardWidgetInterface */ protected $limit = 0; + /** + * Widget settings + * + * @var array + */ + protected $widget = null; + /** * Renders content * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting @@ -36,8 +43,7 @@ class SysNewsWidget extends AbstractWidget implements DashboardWidgetInterface public function render($dashboardWidgetSetting = null) { $this->initialize($dashboardWidgetSetting); - $content = $this->generateContent(); - return $content; + return $this->generateContent(); } /** @@ -47,9 +53,9 @@ public function render($dashboardWidgetSetting = null) */ private function initialize($dashboardWidgetSetting = null) { - $flexformSettings = $this->getFlexFormSettings($dashboardWidgetSetting); - $this->limit = (int)$flexformSettings['settings']['limit']; - $this->widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$dashboardWidgetSetting->getWidgetIdentifier()]; + $settings = $dashboardWidgetSetting->getSettings(); + $this->limit = (int)$settings['limit']; + $this->widget = $settings; } /** diff --git a/Classes/Domain/Model/DashboardWidgetSettings.php b/Classes/Domain/Model/DashboardWidgetSettings.php index 532f3a2..5026cbd 100644 --- a/Classes/Domain/Model/DashboardWidgetSettings.php +++ b/Classes/Domain/Model/DashboardWidgetSettings.php @@ -39,21 +39,6 @@ class DashboardWidgetSettings extends \TYPO3\CMS\Extbase\DomainObject\AbstractEn */ private $flexFormService; - public function __construct(FlexFormService $flexFormService = null) - { - $this->flexFormService = $flexFormService ?: GeneralUtility::makeInstance(FlexFormService::class); - } - - /** - * Make sure a thawed object also gets this dependency injected - * - * @param FlexFormService $flexFormService - */ - public function injectFlexFormService(FlexFormService $flexFormService) - { - $this->flexFormService = $flexFormService; - } - /** * Title * @@ -111,24 +96,38 @@ public function injectFlexFormService(FlexFormService $flexFormService) protected $settingsFlexform = ''; /** - * Returns the title + * @param string $widgetIdentifier + * @param string $title + * @param string $settingsFlexform + * @param FlexFormService|null $flexFormService + */ + public function __construct( + $widgetIdentifier, + $title = '', + $settingsFlexform = '', + FlexFormService $flexFormService = null + ) { + $this->flexFormService = $flexFormService ?: GeneralUtility::makeInstance(FlexFormService::class); + } + + /** + * Make sure a thawed object also gets this dependency injected * - * @return string $title + * @param FlexFormService $flexFormService */ - public function getTitle() + public function injectFlexFormService(FlexFormService $flexFormService) { - return $this->title; + $this->flexFormService = $flexFormService; } /** - * Sets the title + * Returns the title * - * @param string $title - * @return void + * @return string $title */ - public function setTitle($title) + public function getTitle() { - $this->title = $title; + return $this->title; } /** @@ -141,17 +140,6 @@ public function getState() return $this->state; } - /** - * Sets the state - * - * @param string $state - * @return void - */ - public function setState($state) - { - $this->state = $state; - } - /** * Returns the x * @@ -236,34 +224,16 @@ public function setHeight($height) $this->height = $height; } - /** - * Returns the settingsFlexform - * - * @return string $settingsFlexform - * @deprecated - */ - public function getSettingsFlexform() - { - return $this->settingsFlexform; - } - public function getSettings(): array { + $widgetSettings = []; + if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$this->widgetIdentifier])) { + $widgetSettings = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$this->widgetIdentifier]; + } if (empty($this->settingsFlexform)) { - return []; + return $widgetSettings; } - return $this->flexFormService->convertFlexFormContentToArray($this->settingsFlexform)['settings'] ?? []; - } - - /** - * Sets the settingsFlexform - * - * @param string $settingsFlexform - * @return void - */ - public function setSettingsFlexform($settingsFlexform) - { - $this->settingsFlexform = $settingsFlexform; + return array_replace($widgetSettings, $this->flexFormService->convertFlexFormContentToArray($this->settingsFlexform)['settings'] ?? []); } /** @@ -275,15 +245,4 @@ public function getWidgetIdentifier() { return $this->widgetIdentifier; } - - /** - * Sets the widgetIdentifier - * - * @param string $widgetIdentifier - * @return string widgetIdentifier - */ - public function setWidgetIdentifier($widgetIdentifier) - { - $this->widgetIdentifier = $widgetIdentifier; - } } diff --git a/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php index 925c8fb..117121c 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php @@ -28,7 +28,7 @@ class GridAttributesViewHelper extends AbstractBackendViewHelper /** * Returns a widget drop and drop attributes * - * @param TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $widgetSetting + * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $widgetSetting * @param int $index * @param string $className * @@ -37,8 +37,7 @@ class GridAttributesViewHelper extends AbstractBackendViewHelper public function render($widgetSetting, $index, $className = 'grid-item') { $numberOfCols = 3; - $widgetIdentifier = $widgetSetting->getWidgetIdentifier(); - $widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widgetIdentifier]; + $widget = $widgetSetting->getSettings(); list($width, $height) = explode('x', $widget['size']); $width = $this->getItemWidth((int)$width, $numberOfCols); $height = $this->getItemHeight((int)$height); diff --git a/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php index ff7e92a..555550b 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php @@ -20,6 +20,8 @@ * * * The TYPO3 project - inspiring people to share! * * */ +use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; + class IconSrcViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { /** @@ -31,7 +33,8 @@ class IconSrcViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendV public function render($widgetIdentifier) { $fileName = 'EXT:dashboard/Resources/Public/Icons/dashboardWidget.png'; - $widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widgetIdentifier]; + $widgetSetting = new DashboardWidgetSettings($widgetIdentifier); + $widget = $widgetSetting->getSettings(); $widgetIconName = $widget['icon']; $absoluteFilename = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($widgetIconName, true); if (file_exists($absoluteFilename)) { diff --git a/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php index 5d90dc4..5d4bf14 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php @@ -20,6 +20,8 @@ * * * The TYPO3 project - inspiring people to share! * * */ +use TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings; + class SizeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { /** @@ -30,7 +32,8 @@ class SizeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendView */ public function render($widgetIdentifier) { - $widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$widgetIdentifier]; + $widgetSetting = new DashboardWidgetSettings($widgetIdentifier); + $widget = $widgetSetting->getSettings(); list($width, $height) = explode('x', $widget['size']); return $this->getColumnClassName((int)$width) . ' ' . $this->getHeightClassName((int)$height); } diff --git a/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php index 2d73e0e..369866d 100644 --- a/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php @@ -1,57 +1,8 @@ - * - * - * - * List of all "Website user" records stored in the configured storage PID. - * Records will be editable, if the current BE user has got edit rights for the table "fe_users". - * Only the title column (username) will be shown. - * Context menu is active. - * - * - * - * - * - * - * List of "Website user" records with a text property of "foo" stored on PID 1 and two levels down. - * Clicking on a username will open the TYPO3 info popup for the respective record - * - */ class DashboardWidgetViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { - /** - * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface - * @inject - */ - protected $configurationManager; - /** * Renders a record list as known from the TYPO3 list module * Note: This feature is experimental! @@ -62,17 +13,13 @@ class DashboardWidgetViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\Abstract */ public function render($dashboardWidgetSetting) { - $pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess( - \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'), - $GLOBALS['BE_USER']->getPagePermsClause(1) - ); - $widget = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard']['widgets'][$dashboardWidgetSetting->getWidgetIdentifier()]; + $widget = $dashboardWidgetSetting->getSettings(); $widgetClassName = $widget['class']; if (class_exists($widgetClassName)) { $widgetClass = $this->objectManager->get($widgetClassName); return $widgetClass->render($dashboardWidgetSetting); } - return 'Class : ' . $widgetClassName . ' could not be found!'; + return 'Class : ' . htmlspecialchars($widgetClassName) . ' could not be found!'; } } diff --git a/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js b/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js index 81c014e..87c1dc2 100644 --- a/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js +++ b/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js @@ -270,7 +270,7 @@ define(['jquery', var itemsData = []; $(items).each(function(index, item) { itemsData.push({ - uid: item.id, + __identity: item.id, x: item.x, y: item.y, width: item.width, From 181ebe0036ddfc29e6c951345c4f955ee767eabb Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:08:39 +0200 Subject: [PATCH 06/36] Fix TYPO3 dependency in composer.json --- composer.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1e1c9bb..ef8b100 100644 --- a/composer.json +++ b/composer.json @@ -4,11 +4,16 @@ "description": "Customizable dashboard which can display dashboard widgets.", "license": ["GPL-2.0+"], "keywords": ["TYPO3 CMS", "Dashboard"], + "require": { + "typo3/cms-core": "^8.7" + }, "replace": { "dashboard": "self.version" }, - "require": { - "typo3/cms": "~8.7" + "extra": { + "typo3/cms": { + "extension-key": "dashboard" + } }, "autoload": { "psr-4": { From 3ed1ebbb9e3466b6224ac480649933b0c9151044 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:11:52 +0200 Subject: [PATCH 07/36] Remove bogus tests --- .../Controller/DashboardControllerTest.php | 65 ------- Tests/Unit/Domain/Model/DashboardTest.php | 170 ----------------- .../Model/DashboardWidgetSettingsTest.php | 176 ------------------ .../Unit/Domain/Model/DashboardWidgetTest.php | 76 -------- .../Model/DashboardWidgetWelcomeTest.php | 76 -------- 5 files changed, 563 deletions(-) delete mode 100644 Tests/Unit/Controller/DashboardControllerTest.php delete mode 100644 Tests/Unit/Domain/Model/DashboardTest.php delete mode 100644 Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php delete mode 100644 Tests/Unit/Domain/Model/DashboardWidgetTest.php delete mode 100644 Tests/Unit/Domain/Model/DashboardWidgetWelcomeTest.php diff --git a/Tests/Unit/Controller/DashboardControllerTest.php b/Tests/Unit/Controller/DashboardControllerTest.php deleted file mode 100644 index 4540244..0000000 --- a/Tests/Unit/Controller/DashboardControllerTest.php +++ /dev/null @@ -1,65 +0,0 @@ -subject = $this->getMock('TYPO3\\CMS\\Dashboard\\Controller\\DashboardController', ['redirect', 'forward', 'addFlashMessage'], [], '', false); - } - - protected function tearDown() - { - unset($this->subject); - } - - /** - * @test - */ - public function listActionFetchesAllDashboardsFromRepositoryAndAssignsThemToView() - { - $allDashboards = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', [], [], '', false); - - $dashboardRepository = $this->getMock('TYPO3\\CMS\\Dashboard\\Domain\\Repository\\DashboardRepository', ['findAll'], [], '', false); - $dashboardRepository->expects($this->once())->method('findAll')->will($this->returnValue($allDashboards)); - $this->inject($this->subject, 'dashboardRepository', $dashboardRepository); - - $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface'); - $view->expects($this->once())->method('assign')->with('dashboards', $allDashboards); - $this->inject($this->subject, 'view', $view); - - $this->subject->listAction(); - } -} diff --git a/Tests/Unit/Domain/Model/DashboardTest.php b/Tests/Unit/Domain/Model/DashboardTest.php deleted file mode 100644 index 2facec7..0000000 --- a/Tests/Unit/Domain/Model/DashboardTest.php +++ /dev/null @@ -1,170 +0,0 @@ -subject = new \TYPO3\CMS\Dashboard\Domain\Model\Dashboard(); - } - - protected function tearDown() - { - unset($this->subject); - } - - /** - * @test - */ - public function getTitleReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getTitle() - ); - } - - /** - * @test - */ - public function setTitleForStringSetsTitle() - { - $this->subject->setTitle('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'title', - $this->subject - ); - } - - /** - * @test - */ - public function getDescriptionReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getDescription() - ); - } - - /** - * @test - */ - public function setDescriptionForStringSetsDescription() - { - $this->subject->setDescription('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'description', - $this->subject - ); - } - - /** - * @test - */ - public function getDashboardWidgetSettingsReturnsInitialValueForDashboardWidgetSettings() - { - $newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); - $this->assertEquals( - $newObjectStorage, - $this->subject->getDashboardWidgetSettings() - ); - } - - /** - * @test - */ - public function setDashboardWidgetSettingsForObjectStorageContainingDashboardWidgetSettingsSetsDashboardWidgetSettings() - { - $dashboardWidgetSetting = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings(); - $objectStorageHoldingExactlyOneDashboardWidgetSettings = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); - $objectStorageHoldingExactlyOneDashboardWidgetSettings->attach($dashboardWidgetSetting); - $this->subject->setDashboardWidgetSettings($objectStorageHoldingExactlyOneDashboardWidgetSettings); - - $this->assertAttributeEquals( - $objectStorageHoldingExactlyOneDashboardWidgetSettings, - 'dashboardWidgetSettings', - $this->subject - ); - } - - /** - * @test - */ - public function addDashboardWidgetSettingToObjectStorageHoldingDashboardWidgetSettings() - { - $dashboardWidgetSetting = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings(); - $dashboardWidgetSettingsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', ['attach'], [], '', false); - $dashboardWidgetSettingsObjectStorageMock->expects($this->once())->method('attach')->with($this->equalTo($dashboardWidgetSetting)); - $this->inject($this->subject, 'dashboardWidgetSettings', $dashboardWidgetSettingsObjectStorageMock); - - $this->subject->addDashboardWidgetSetting($dashboardWidgetSetting); - } - - /** - * @test - */ - public function removeDashboardWidgetSettingFromObjectStorageHoldingDashboardWidgetSettings() - { - $dashboardWidgetSetting = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings(); - $dashboardWidgetSettingsObjectStorageMock = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', ['detach'], [], '', false); - $dashboardWidgetSettingsObjectStorageMock->expects($this->once())->method('detach')->with($this->equalTo($dashboardWidgetSetting)); - $this->inject($this->subject, 'dashboardWidgetSettings', $dashboardWidgetSettingsObjectStorageMock); - - $this->subject->removeDashboardWidgetSetting($dashboardWidgetSetting); - } - - /** - * @test - */ - public function getBeuserReturnsInitialValueForBackendUser() - { - } - - /** - * @test - */ - public function setBeuserForBackendUserSetsBeuser() - { - } -} diff --git a/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php b/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php deleted file mode 100644 index b6e7c58..0000000 --- a/Tests/Unit/Domain/Model/DashboardWidgetSettingsTest.php +++ /dev/null @@ -1,176 +0,0 @@ -subject = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings(); - } - - protected function tearDown() - { - unset($this->subject); - } - - /** - * @test - */ - public function getTitleReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getTitle() - ); - } - - /** - * @test - */ - public function setTitleForStringSetsTitle() - { - $this->subject->setTitle('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'title', - $this->subject - ); - } - - /** - * @test - */ - public function getWidgetIdentifierReturnsInitialValueForInteger() - { - $this->assertSame( - 0, - $this->subject->getWidgetIdentifier() - ); - } - - /** - * @test - */ - public function setWidgetIdentifierForIntegerSetsWidgetIdentifier() - { - $this->subject->setWidgetIdentifier(12); - - $this->assertAttributeEquals( - 12, - 'widgetIdentifier', - $this->subject - ); - } - - /** - * @test - */ - public function getStateReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getState() - ); - } - - /** - * @test - */ - public function setStateForStringSetsState() - { - $this->subject->setState('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'state', - $this->subject - ); - } - - /** - * @test - */ - public function getPositionReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getPosition() - ); - } - - /** - * @test - */ - public function setPositionForStringSetsPosition() - { - $this->subject->setPosition('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'position', - $this->subject - ); - } - - /** - * @test - */ - public function getSettingsFlexformReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getSettingsFlexform() - ); - } - - /** - * @test - */ - public function setSettingsFlexformForStringSetsSettingsFlexform() - { - $this->subject->setSettingsFlexform('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'settingsFlexform', - $this->subject - ); - } -} diff --git a/Tests/Unit/Domain/Model/DashboardWidgetTest.php b/Tests/Unit/Domain/Model/DashboardWidgetTest.php deleted file mode 100644 index 0090aad..0000000 --- a/Tests/Unit/Domain/Model/DashboardWidgetTest.php +++ /dev/null @@ -1,76 +0,0 @@ -subject = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidget(); - } - - protected function tearDown() - { - unset($this->subject); - } - - /** - * @test - */ - public function getTitleReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getTitle() - ); - } - - /** - * @test - */ - public function setTitleForStringSetsTitle() - { - $this->subject->setTitle('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'title', - $this->subject - ); - } -} diff --git a/Tests/Unit/Domain/Model/DashboardWidgetWelcomeTest.php b/Tests/Unit/Domain/Model/DashboardWidgetWelcomeTest.php deleted file mode 100644 index 9c73f60..0000000 --- a/Tests/Unit/Domain/Model/DashboardWidgetWelcomeTest.php +++ /dev/null @@ -1,76 +0,0 @@ -subject = new \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetWelcome(); - } - - protected function tearDown() - { - unset($this->subject); - } - - /** - * @test - */ - public function getMessageReturnsInitialValueForString() - { - $this->assertSame( - '', - $this->subject->getMessage() - ); - } - - /** - * @test - */ - public function setMessageForStringSetsMessage() - { - $this->subject->setMessage('Conceived at T3CON10'); - - $this->assertAttributeEquals( - 'Conceived at T3CON10', - 'message', - $this->subject - ); - } -} From 67bba0f12a1b05550a08e493f7239db13a9e0448 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:12:07 +0200 Subject: [PATCH 08/36] Properly encode HTML output --- Classes/Controller/DashboardController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index c23a6a4..5f2b1fb 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -531,8 +531,8 @@ protected function getHtmlErrorMessage($title, $message) $content .= ' '; $content .= '
'; $content .= '
'; - $content .= '

' . $title . '

'; - $content .= '

' . $message . '

'; + $content .= '

' . htmlspecialchars($title) . '

'; + $content .= '

' . htmlspecialchars($message) . '

'; $content .= '
'; $content .= ' '; $content .= ' '; From 794a0f1314c7ed3c92ac3df5264ff2297596cbc9 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:22:09 +0200 Subject: [PATCH 09/36] Move repository logic to repository --- Classes/Controller/DashboardController.php | 34 +----------- .../DashboardWidgetSettingsRepository.php | 55 ++++++++++++++++++- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 5f2b1fb..1944bc3 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -199,7 +199,7 @@ public function createWidgetAction() $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][widget_identifier]=' . $getVars['widgetType']; $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][width]=' . $width; $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][height]=' . $height; - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][y]=' . $this->getNextRow($this->dashboard->getUid()); + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][y]=' . $this->dashboardWidgetSettingsRepository->findNextAvailableVerticalPositionOnDashboard($this->dashboard->getUid()); $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][x]=0'; $params = '&edit[tx_dashboard_domain_model_dashboardwidgetsettings][' . $storagePid . ']=new' . $overrideVals; @@ -434,38 +434,6 @@ protected function getWidgetSettings(string $widgetIdentifier): array return $widgetSettings->getSettings(); } - /** - * Returns next available "row" - * - * @param int $dasboardId - * - * @return int - */ - protected function getNextRow(int $dasboardId): int - { - $retval = 0; - - $queryBuilder = - GeneralUtility::makeInstance( - \TYPO3\CMS\Core\Database\ConnectionPool::class - )->getQueryBuilderForTable('tx_dashboard_domain_model_dashboardwidgetsettings'); - - $result = $queryBuilder - ->select('y', 'height') - ->from('tx_dashboard_domain_model_dashboardwidgetsettings') - ->where($queryBuilder->expr()->eq('dashboard', $dasboardId)) - ->andWhere($queryBuilder->expr()->eq('deleted', 0)) - ->orderBy('y', 'DESC') - ->addOrderBy('height', 'DESC') - ->execute() - ->fetch(); - - if ($result) { - $retval = $result['y'] + $result['height']; - } - return $retval; - } - /** * Returns edit url for this dashboard * diff --git a/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php b/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php index 5c54293..a279a8d 100644 --- a/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php +++ b/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php @@ -1,4 +1,5 @@ connectionPool = $connectionPool; + } + + /** + * @param int $dashBoardId + * @return int + */ + public function findNextAvailableVerticalPositionOnDashboard(int $dashBoardId): int + { + $availablePosition = 0; + + $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME); + + $result = $queryBuilder + ->select('y', 'height') + ->from(self::TABLE_NAME) + ->where( + $queryBuilder->expr()->eq( + 'dashboard', + $queryBuilder->createNamedParameter($dashBoardId, \PDO::PARAM_INT) + ) + ) + ->orderBy('y', 'DESC') + ->addOrderBy('height', 'DESC') + ->setMaxResults(1) + ->execute() + ->fetch(); + + if ($result) { + $availablePosition = $result['y'] + $result['height']; + } + return $availablePosition; + } } From 37ed5a758161831815b8aed6ca5bedd32f73b814 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:29:57 +0200 Subject: [PATCH 10/36] [!!!] Move away from reserved TYPO3 namespace --- Classes/Controller/DashboardController.php | 14 ++++++------ Classes/DashboardWidgets/AbstractWidget.php | 4 ++-- Classes/DashboardWidgets/ActionWidget.php | 8 +++---- Classes/DashboardWidgets/IframeWidget.php | 6 ++--- Classes/DashboardWidgets/RssWidget.php | 8 +++---- Classes/DashboardWidgets/SysNewsWidget.php | 8 +++---- Classes/Domain/Model/Dashboard.php | 22 +++++++++---------- .../Domain/Model/DashboardWidgetSettings.php | 2 +- .../Domain/Repository/DashboardRepository.php | 2 +- .../DashboardWidgetSettingsRepository.php | 2 +- .../DashboardWidget/EditOnClickViewHelper.php | 4 ++-- .../GridAttributesViewHelper.php | 4 ++-- .../Be/DashboardWidget/IconSrcViewHelper.php | 4 ++-- .../Be/DashboardWidget/SizeViewHelper.php | 4 ++-- .../Be/DashboardWidgetViewHelper.php | 4 ++-- ...d_domain_model_dashboardwidgetsettings.php | 16 +++++++------- .../Private/Templates/Dashboard/Index.html | 2 +- composer.json | 4 ++-- ext_tables.php | 16 +++++++------- 19 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 1944bc3..8c82b22 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -1,5 +1,5 @@ $items + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> $items * @return string */ public function changeAction($items) @@ -226,7 +226,7 @@ public function createAction() ); $beUser = $beUserRepository->findByUid($beUserUid); if ($beUser !== null) { - $newDashboard = $this->objectManager->get(\TYPO3\CMS\Dashboard\Domain\Model\Dashboard::class); + $newDashboard = $this->objectManager->get(\Pixelant\Dashboard\Domain\Model\Dashboard::class); $newDashboard->setTitle($getVars['dashboardName']); $newDashboard->setBeuser($beUser); $this->dashboardRepository->add($newDashboard); diff --git a/Classes/DashboardWidgets/AbstractWidget.php b/Classes/DashboardWidgets/AbstractWidget.php index ac96c94..0c1df4b 100644 --- a/Classes/DashboardWidgets/AbstractWidget.php +++ b/Classes/DashboardWidgets/AbstractWidget.php @@ -1,5 +1,5 @@ + * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> */ protected $dashboardWidgetSettings = null; @@ -127,10 +127,10 @@ public function setDescription($description) /** * Adds a DashboardWidget * - * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings + * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ - public function addDashboardWidgetSetting(\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting) + public function addDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting) { $this->dashboardWidgetSettings->attach($dashboardWidgetSetting); } @@ -138,10 +138,10 @@ public function addDashboardWidgetSetting(\TYPO3\CMS\Dashboard\Domain\Model\Dash /** * Removes a DashboardWidget * - * @param \TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove The DashboardWidgetSettings to be removed - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings + * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove The DashboardWidgetSettings to be removed + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ - public function removeDashboardWidgetSetting(\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove) + public function removeDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove) { $this->dashboardWidgetSettings->detach($dashboardWidgetSettingToRemove); } @@ -149,7 +149,7 @@ public function removeDashboardWidgetSetting(\TYPO3\CMS\Dashboard\Domain\Model\D /** * Returns the dashboardWidgetSettings * - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ public function getDashboardWidgetSettings() { @@ -159,8 +159,8 @@ public function getDashboardWidgetSettings() /** * Sets the dashboardWidgetSettings * - * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings> $dashboardWidgetSettings - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> $dashboardWidgetSettings + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ public function setDashboardWidgetSettings(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $dashboardWidgetSettings) { diff --git a/Classes/Domain/Model/DashboardWidgetSettings.php b/Classes/Domain/Model/DashboardWidgetSettings.php index 5026cbd..ddd54bf 100644 --- a/Classes/Domain/Model/DashboardWidgetSettings.php +++ b/Classes/Domain/Model/DashboardWidgetSettings.php @@ -1,5 +1,5 @@ 1, @@ -148,10 +148,10 @@ 'type' => 'flex', 'ds_pointerField' => 'widget_identifier', 'ds' => [ - \TYPO3\CMS\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_rsswidget.xml', - \TYPO3\CMS\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_actionwidget.xml', - \TYPO3\CMS\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_sysnewswidget.xml', - \TYPO3\CMS\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_iframewidget.xml', + \Pixelant\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_rsswidget.xml', + \Pixelant\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_actionwidget.xml', + \Pixelant\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_sysnewswidget.xml', + \Pixelant\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_iframewidget.xml', 'default' => 'arraynone', ], ], diff --git a/Resources/Private/Templates/Dashboard/Index.html b/Resources/Private/Templates/Dashboard/Index.html index 1dd61d3..1ab5023 100644 --- a/Resources/Private/Templates/Dashboard/Index.html +++ b/Resources/Private/Templates/Dashboard/Index.html @@ -1,4 +1,4 @@ -{namespace d=TYPO3\CMS\Dashboard\ViewHelpers} +{namespace d=Pixelant\Dashboard\ViewHelpers} diff --git a/composer.json b/composer.json index ef8b100..464a4fc 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ }, "autoload": { "psr-4": { - "TYPO3\\CMS\\Dashboard\\": "Classes/" + "Pixelant\\Dashboard\\": "Classes/" } }, "autoload-dev": { "psr-4": { - "TYPO3\\CMS\\Dashboard\\Tests\\": "Tests/" + "Pixelant\\Dashboard\\Tests\\": "Tests/" } } } diff --git a/ext_tables.php b/ext_tables.php index 339db04..6a3a56e 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -35,41 +35,41 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ 'widgets' => [ - \TYPO3\CMS\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => [ + \Pixelant\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png', - 'class' => 'TYPO3\\CMS\\Dashboard\\DashboardWidgets\\RssWidget', + 'class' => \Pixelant\Dashboard\DashboardWidgets\RssWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \TYPO3\CMS\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => [ + \Pixelant\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/ActionWidget.png', - 'class' => 'TYPO3\\CMS\\Dashboard\\DashboardWidgets\\ActionWidget', + 'class' => \Pixelant\Dashboard\DashboardWidgets\ActionWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \TYPO3\CMS\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => [ + \Pixelant\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/SysNewsWidget.png', - 'class' => 'TYPO3\\CMS\\Dashboard\\DashboardWidgets\\SysNewsWidget', + 'class' => \Pixelant\Dashboard\DashboardWidgets\SysNewsWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \TYPO3\CMS\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => [ + \Pixelant\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/frameWidget.png', - 'class' => 'TYPO3\\CMS\\Dashboard\\DashboardWidgets\\IframeWidget', + 'class' => \Pixelant\Dashboard\DashboardWidgets\IframeWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', 'defaultWidth' => '12', 'defaultHeight' => '6', From 39b5cf9b0872a417887afc6a3f0aef6f8a6ebdc5 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:40:00 +0200 Subject: [PATCH 11/36] Fix namespace of exception and interface --- Classes/DashboardWidgetInterface.php | 2 +- Classes/Exception.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/DashboardWidgetInterface.php b/Classes/DashboardWidgetInterface.php index 43e717d..34398c6 100644 --- a/Classes/DashboardWidgetInterface.php +++ b/Classes/DashboardWidgetInterface.php @@ -1,5 +1,5 @@ Date: Mon, 23 Oct 2017 15:42:25 +0200 Subject: [PATCH 12/36] Fix namespace of module --- ext_tables.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_tables.php b/ext_tables.php index 6a3a56e..07f2a4b 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -8,7 +8,7 @@ * Registers a Backend Module */ \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( - 'TYPO3\CMS.' . $_EXTKEY, + 'Pixelant.' . $_EXTKEY, 'user', // Make module a submodule of 'user' 'dashboardmod1', // Submodule key '', // Position From 4ef39cf25332906f69b5aa43eee7ef7b5739d7f3 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:48:12 +0200 Subject: [PATCH 13/36] [!!!] Remove AbstractWidget Since the namespace change removed every single bit of class compatibility anyway, we can safely remove the deprecated class. --- Classes/DashboardWidgets/AbstractWidget.php | 33 --------------------- 1 file changed, 33 deletions(-) delete mode 100644 Classes/DashboardWidgets/AbstractWidget.php diff --git a/Classes/DashboardWidgets/AbstractWidget.php b/Classes/DashboardWidgets/AbstractWidget.php deleted file mode 100644 index 0c1df4b..0000000 --- a/Classes/DashboardWidgets/AbstractWidget.php +++ /dev/null @@ -1,33 +0,0 @@ - $dashboardWidgetSetting->getSettings()]; - } -} From a8f517fec5b33b19173a1a209e1bdab6dde71442 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 15:53:30 +0200 Subject: [PATCH 14/36] [!!!] Rename and tighten WidgetInterface --- Classes/DashboardWidgetInterface.php | 15 --------------- Classes/DashboardWidgets/ActionWidget.php | 9 ++++----- Classes/DashboardWidgets/IframeWidget.php | 6 +++--- Classes/DashboardWidgets/RssWidget.php | 9 +++------ Classes/DashboardWidgets/SysNewsWidget.php | 6 +++--- Classes/Widget/WidgetInterface.php | 15 +++++++++++++++ 6 files changed, 28 insertions(+), 32 deletions(-) delete mode 100644 Classes/DashboardWidgetInterface.php create mode 100644 Classes/Widget/WidgetInterface.php diff --git a/Classes/DashboardWidgetInterface.php b/Classes/DashboardWidgetInterface.php deleted file mode 100644 index 34398c6..0000000 --- a/Classes/DashboardWidgetInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -initialize($dashboardWidgetSetting); - $content = $this->generateContent(); - return $content; + return $this->generateContent(); } /** diff --git a/Classes/DashboardWidgets/IframeWidget.php b/Classes/DashboardWidgets/IframeWidget.php index c3145d9..8fb1dde 100644 --- a/Classes/DashboardWidgets/IframeWidget.php +++ b/Classes/DashboardWidgets/IframeWidget.php @@ -14,11 +14,11 @@ * Public License for more details. * * */ -use Pixelant\Dashboard\DashboardWidgetInterface; +use Pixelant\Dashboard\Widget\WidgetInterface; use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Fluid\View\StandaloneView; -class IframeWidget implements DashboardWidgetInterface +class IframeWidget implements WidgetInterface { const IDENTIFIER = '1487642496'; @@ -48,7 +48,7 @@ class IframeWidget implements DashboardWidgetInterface * @param DashboardWidgetSettings $dashboardWidgetSetting * @return string the rendered content */ - public function render($dashboardWidgetSetting = null) + public function render($dashboardWidgetSetting = null): string { $this->initialize($dashboardWidgetSetting); $content = $this->generateContent(); diff --git a/Classes/DashboardWidgets/RssWidget.php b/Classes/DashboardWidgets/RssWidget.php index 31cc7fb..542f720 100644 --- a/Classes/DashboardWidgets/RssWidget.php +++ b/Classes/DashboardWidgets/RssWidget.php @@ -1,12 +1,9 @@ initialize($dashboardWidgetSetting); if ($this->cacheLifetime > 0) { diff --git a/Classes/DashboardWidgets/SysNewsWidget.php b/Classes/DashboardWidgets/SysNewsWidget.php index 8854b65..f99afc7 100644 --- a/Classes/DashboardWidgets/SysNewsWidget.php +++ b/Classes/DashboardWidgets/SysNewsWidget.php @@ -15,9 +15,9 @@ * */ use TYPO3\CMS\Backend\Utility\BackendUtility; -use Pixelant\Dashboard\DashboardWidgetInterface; +use Pixelant\Dashboard\Widget\WidgetInterface; -class SysNewsWidget implements DashboardWidgetInterface +class SysNewsWidget implements WidgetInterface { const IDENTIFIER = '1439446997'; @@ -40,7 +40,7 @@ class SysNewsWidget implements DashboardWidgetInterface * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting * @return string the rendered content */ - public function render($dashboardWidgetSetting = null) + public function render($dashboardWidgetSetting = null): string { $this->initialize($dashboardWidgetSetting); return $this->generateContent(); diff --git a/Classes/Widget/WidgetInterface.php b/Classes/Widget/WidgetInterface.php new file mode 100644 index 0000000..b13a813 --- /dev/null +++ b/Classes/Widget/WidgetInterface.php @@ -0,0 +1,15 @@ + Date: Mon, 23 Oct 2017 15:57:18 +0200 Subject: [PATCH 15/36] Move Widgets into Widget namespace --- .../ActionWidget.php | 3 +-- .../IframeWidget.php | 2 +- .../{DashboardWidgets => Widget}/RssWidget.php | 2 +- .../SysNewsWidget.php | 2 +- ...oard_domain_model_dashboardwidgetsettings.php | 16 ++++++++-------- ext_tables.php | 16 ++++++++-------- 6 files changed, 20 insertions(+), 21 deletions(-) rename Classes/{DashboardWidgets => Widget}/ActionWidget.php (98%) rename Classes/{DashboardWidgets => Widget}/IframeWidget.php (98%) rename Classes/{DashboardWidgets => Widget}/RssWidget.php (99%) rename Classes/{DashboardWidgets => Widget}/SysNewsWidget.php (98%) diff --git a/Classes/DashboardWidgets/ActionWidget.php b/Classes/Widget/ActionWidget.php similarity index 98% rename from Classes/DashboardWidgets/ActionWidget.php rename to Classes/Widget/ActionWidget.php index e669271..a1cb85d 100644 --- a/Classes/DashboardWidgets/ActionWidget.php +++ b/Classes/Widget/ActionWidget.php @@ -1,5 +1,5 @@ 1, @@ -148,10 +148,10 @@ 'type' => 'flex', 'ds_pointerField' => 'widget_identifier', 'ds' => [ - \Pixelant\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_rsswidget.xml', - \Pixelant\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_actionwidget.xml', - \Pixelant\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_sysnewswidget.xml', - \Pixelant\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_iframewidget.xml', + \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_rsswidget.xml', + \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_actionwidget.xml', + \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_sysnewswidget.xml', + \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_iframewidget.xml', 'default' => 'arraynone', ], ], diff --git a/ext_tables.php b/ext_tables.php index 07f2a4b..4dde00d 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -35,41 +35,41 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ 'widgets' => [ - \Pixelant\Dashboard\DashboardWidgets\RssWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png', - 'class' => \Pixelant\Dashboard\DashboardWidgets\RssWidget::class, + 'class' => \Pixelant\Dashboard\Widget\RssWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \Pixelant\Dashboard\DashboardWidgets\ActionWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/ActionWidget.png', - 'class' => \Pixelant\Dashboard\DashboardWidgets\ActionWidget::class, + 'class' => \Pixelant\Dashboard\Widget\ActionWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \Pixelant\Dashboard\DashboardWidgets\SysNewsWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/SysNewsWidget.png', - 'class' => \Pixelant\Dashboard\DashboardWidgets\SysNewsWidget::class, + 'class' => \Pixelant\Dashboard\Widget\SysNewsWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \Pixelant\Dashboard\DashboardWidgets\IframeWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', 'icon' => 'EXT:dashboard/Resources/Public/Icons/frameWidget.png', - 'class' => \Pixelant\Dashboard\DashboardWidgets\IframeWidget::class, + 'class' => \Pixelant\Dashboard\Widget\IframeWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', 'defaultWidth' => '12', 'defaultHeight' => '6', From 0b99551c90974e2981d48db3cc9a1161279da4be Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 16:03:08 +0200 Subject: [PATCH 16/36] Clean up ext_tables and ext_localconf --- Configuration/TCA/Overrides/sys_template.php | 2 + ...d_domain_model_dashboardwidgetsettings.php | 1 + ext_localconf.php | 45 ++++++++++ ext_tables.php | 85 ++++--------------- 4 files changed, 65 insertions(+), 68 deletions(-) create mode 100644 Configuration/TCA/Overrides/sys_template.php diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php new file mode 100644 index 0000000..68edb65 --- /dev/null +++ b/Configuration/TCA/Overrides/sys_template.php @@ -0,0 +1,2 @@ + 'l10n_diffsource', 'delete' => 'deleted', 'enablecolumns' => [], + 'requestUpdate' => 'widget_identifier', 'searchFields' => 'title,widget_identifier,position,settings_flexform,', 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboardwidgetsettings.gif', ], diff --git a/ext_localconf.php b/ext_localconf.php index 094314a..0aeaad7 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -6,3 +6,48 @@ if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'] = []; } + +$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ + 'widgets' => [ + \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', + 'icon' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png', + 'class' => \Pixelant\Dashboard\Widget\RssWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', + 'defaultWidth' => '3', + 'defaultHeight' => '5', + 'minWidth' => '3', + ], + \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', + 'icon' => 'EXT:dashboard/Resources/Public/Icons/ActionWidget.png', + 'class' => \Pixelant\Dashboard\Widget\ActionWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', + 'defaultWidth' => '3', + 'defaultHeight' => '5', + 'minWidth' => '3', + ], + \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', + 'icon' => 'EXT:dashboard/Resources/Public/Icons/SysNewsWidget.png', + 'class' => \Pixelant\Dashboard\Widget\SysNewsWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', + 'defaultWidth' => '3', + 'defaultHeight' => '5', + 'minWidth' => '3', + ], + \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', + 'icon' => 'EXT:dashboard/Resources/Public/Icons/frameWidget.png', + 'class' => \Pixelant\Dashboard\Widget\IframeWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', + 'defaultWidth' => '12', + 'defaultHeight' => '6', + 'minWidth' => '3', + ], + ], +]; diff --git a/ext_tables.php b/ext_tables.php index 4dde00d..6f51c55 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -3,77 +3,26 @@ die('Access denied.'); } -if (TYPO3_MODE === 'BE') { - /** - * Registers a Backend Module - */ - \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( - 'Pixelant.' . $_EXTKEY, - 'user', // Make module a submodule of 'user' - 'dashboardmod1', // Submodule key - '', // Position - [ - 'Dashboard' => 'index, change, create, createWidget, renderWidget', - ], - [ - 'access' => 'user,group', - 'icon' => 'EXT:' . $_EXTKEY . '/ext_icon.png', - 'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_dashboardmod1.xlf', - ] - ); -} - -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Dashboard'); +/** + * Registers a Backend Module + */ +\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( + 'Pixelant.Dashboard', + 'user', // Make module a submodule of 'user' + 'dashboardmod1', // Submodule key + '', // Position + [ + 'Dashboard' => 'index, change, create, createWidget, renderWidget', + ], + [ + 'access' => 'user,group', + 'icon' => 'EXT:dashboard/ext_icon.png', + 'labels' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_dashboardmod1.xlf', + ] +); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_dashboard_domain_model_dashboard', 'EXT:dashboard/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboard.xlf'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_dashboard_domain_model_dashboard'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_dashboard_domain_model_dashboardwidgetsettings', 'EXT:dashboard/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboardwidgetsettings.xlf'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_dashboard_domain_model_dashboardwidgetsettings'); - -$GLOBALS['TCA']['tx_dashboard_domain_model_dashboardwidgetsettings']['ctrl']['requestUpdate'] = 'widget_identifier'; - -$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ - 'widgets' => [ - \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png', - 'class' => \Pixelant\Dashboard\Widget\RssWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', - 'defaultWidth' => '3', - 'defaultHeight' => '5', - 'minWidth' => '3', - ], - \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/ActionWidget.png', - 'class' => \Pixelant\Dashboard\Widget\ActionWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', - 'defaultWidth' => '3', - 'defaultHeight' => '5', - 'minWidth' => '3', - ], - \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/SysNewsWidget.png', - 'class' => \Pixelant\Dashboard\Widget\SysNewsWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', - 'defaultWidth' => '3', - 'defaultHeight' => '5', - 'minWidth' => '3', - ], - \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/frameWidget.png', - 'class' => \Pixelant\Dashboard\Widget\IframeWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', - 'defaultWidth' => '12', - 'defaultHeight' => '6', - 'minWidth' => '3', - ], - ], -]; From d12f08d31c31643917ccd4cb81b1e940e5f09ae8 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 23 Oct 2017 16:32:30 +0200 Subject: [PATCH 17/36] [!!!] Use Icon API for wizard icons --- ...onSrcViewHelper.php => IconViewHelper.php} | 25 ++--- .../Private/Templates/Dashboard/Index.html | 2 +- ext_localconf.php | 103 ++++++++++-------- 3 files changed, 67 insertions(+), 63 deletions(-) rename Classes/ViewHelpers/Be/DashboardWidget/{IconSrcViewHelper.php => IconViewHelper.php} (65%) diff --git a/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php similarity index 65% rename from Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php rename to Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php index 2eb2bbe..978b3e5 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/IconSrcViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php @@ -20,28 +20,21 @@ * * * The TYPO3 project - inspiring people to share! * * */ + use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; -class IconSrcViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper +class IconViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { /** - * Returns path to widget icon + * Returns widget icon name, either defined one or default * - * @param string $widgetIdentifier - * @return string Path to icon if ok, else fallback + * @param DashboardWidgetSettings $widgetSettings + * @return string */ - public function render($widgetIdentifier) + public function render(DashboardWidgetSettings $widgetSettings) { - $fileName = 'EXT:dashboard/Resources/Public/Icons/dashboardWidget.png'; - $widgetSetting = new DashboardWidgetSettings($widgetIdentifier); - $widget = $widgetSetting->getSettings(); - $widgetIconName = $widget['icon']; - $absoluteFilename = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($widgetIconName, true); - if (file_exists($absoluteFilename)) { - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($absoluteFilename)) { - $fileName = $widgetIconName; - } - } - return $fileName; + $defaultIcon = 'dashboard-widget-default'; + $widget = $widgetSettings->getSettings(); + return $widget['icon'] ?? $defaultIcon; } } diff --git a/Resources/Private/Templates/Dashboard/Index.html b/Resources/Private/Templates/Dashboard/Index.html index 1ab5023..e385414 100644 --- a/Resources/Private/Templates/Dashboard/Index.html +++ b/Resources/Private/Templates/Dashboard/Index.html @@ -30,7 +30,7 @@ style="display: none;">
- + {dashboardWidgetSetting.title}
diff --git a/ext_localconf.php b/ext_localconf.php index 0aeaad7..105e951 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,51 +3,62 @@ die('Access denied.'); } -if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'] = []; -} +(function() { + if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'])) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'] = []; + } -$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ - 'widgets' => [ - \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png', - 'class' => \Pixelant\Dashboard\Widget\RssWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', - 'defaultWidth' => '3', - 'defaultHeight' => '5', - 'minWidth' => '3', - ], - \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/ActionWidget.png', - 'class' => \Pixelant\Dashboard\Widget\ActionWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', - 'defaultWidth' => '3', - 'defaultHeight' => '5', - 'minWidth' => '3', - ], - \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/SysNewsWidget.png', - 'class' => \Pixelant\Dashboard\Widget\SysNewsWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', - 'defaultWidth' => '3', - 'defaultHeight' => '5', - 'minWidth' => '3', + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ + 'widgets' => [ + \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', + 'icon' => 'widget-rss', + 'class' => \Pixelant\Dashboard\Widget\RssWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', + 'defaultWidth' => '3', + 'defaultHeight' => '5', + 'minWidth' => '3', + ], + \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', + 'class' => \Pixelant\Dashboard\Widget\ActionWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', + 'defaultWidth' => '3', + 'defaultHeight' => '5', + 'minWidth' => '3', + ], + \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', + 'class' => \Pixelant\Dashboard\Widget\SysNewsWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', + 'defaultWidth' => '3', + 'defaultHeight' => '5', + 'minWidth' => '3', + ], + \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => [ + 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', + 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', + 'class' => \Pixelant\Dashboard\Widget\IframeWidget::class, + 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', + 'defaultWidth' => '12', + 'defaultHeight' => '6', + 'minWidth' => '3', + ], ], - \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => [ - 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', - 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', - 'icon' => 'EXT:dashboard/Resources/Public/Icons/frameWidget.png', - 'class' => \Pixelant\Dashboard\Widget\IframeWidget::class, - 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', - 'defaultWidth' => '12', - 'defaultHeight' => '6', - 'minWidth' => '3', - ], - ], -]; + ]; + + $iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class); + $iconRegistry->registerIcon( + 'dashboard-widget-default', + \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class, + ['source' => 'EXT:dashboard/Resources/Public/Icons/dashboardWidget.png'] + ); + $iconRegistry->registerIcon( + 'widget-rss', + \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class, + ['source' => 'EXT:dashboard/Resources/Public/Icons/RssWidget.png'] + ); +})(); From c79e72fb539f9506ff683d80658d95222bcf3b84 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 10:53:43 +0200 Subject: [PATCH 18/36] [!!!] Add settings to the widget render contract --- Classes/Controller/DashboardController.php | 5 ++--- .../DashboardWidgetSettingsRepository.php | 10 ++++++++++ Classes/Widget/ActionWidget.php | 16 +++++++++++----- Classes/Widget/IframeWidget.php | 6 ++---- Classes/Widget/RssWidget.php | 8 ++++---- Classes/Widget/SysNewsWidget.php | 8 ++++---- Classes/Widget/WidgetInterface.php | 5 ++++- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 8c82b22..5742682 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -247,7 +247,6 @@ public function createAction() */ public function renderWidgetAction() { - $content = ''; $getVars = $this->request->getArguments(); $widgetId = $getVars['widgetId']; $errorTitle = $this @@ -260,9 +259,9 @@ public function renderWidgetAction() $widgetConfiguration = $widgetSettings->getSettings(); $widgetClassName = $widgetConfiguration['class']; if (class_exists($widgetClassName)) { - $widgetClass = $this->objectManager->get($widgetClassName); + $widget = $this->objectManager->get($widgetClassName); try { - return $widgetClass->render($widgetSettings); + return $widget->render($widgetSettings); } catch (\Exception $e) { $localizedError = $this ->getLanguageService() diff --git a/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php b/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php index 5d0f4d3..66532d6 100644 --- a/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php +++ b/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php @@ -27,6 +27,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Persistence\Repository; @@ -54,6 +55,15 @@ public function __construct(ObjectManagerInterface $objectManager, ConnectionPoo $this->connectionPool = $connectionPool; } + /** + * @param int $uid + * @return DashboardWidgetSettings + */ + public function findByUid($uid) + { + return parent::findByUid($uid); + } + /** * @param int $dashBoardId * @return int diff --git a/Classes/Widget/ActionWidget.php b/Classes/Widget/ActionWidget.php index a1cb85d..eea435b 100644 --- a/Classes/Widget/ActionWidget.php +++ b/Classes/Widget/ActionWidget.php @@ -14,14 +14,13 @@ * Public License for more details. * * */ +use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; use TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; - use TYPO3\CMS\Core\Utility\GeneralUtility; -use Pixelant\Dashboard\Widget\WidgetInterface; use TYPO3\CMS\Fluid\View\StandaloneView; class ActionWidget implements WidgetInterface @@ -35,12 +34,19 @@ class ActionWidget implements WidgetInterface */ protected $limit = 0; + /** + * Widget configuration + * + * @var array + */ + protected $widget = []; + /** * Renders content - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param DashboardWidgetSettings $dashboardWidgetSetting * @return string the rendered content */ - public function render($dashboardWidgetSetting = null): string + public function render(DashboardWidgetSettings $dashboardWidgetSetting): string { $this->initialize($dashboardWidgetSetting); return $this->generateContent(); @@ -48,7 +54,7 @@ public function render($dashboardWidgetSetting = null): string /** * Initializes settings from flexform - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param DashboardWidgetSettings $dashboardWidgetSetting * @return void */ private function initialize($dashboardWidgetSetting = null) diff --git a/Classes/Widget/IframeWidget.php b/Classes/Widget/IframeWidget.php index d8424e3..7897259 100644 --- a/Classes/Widget/IframeWidget.php +++ b/Classes/Widget/IframeWidget.php @@ -14,7 +14,6 @@ * Public License for more details. * * */ -use Pixelant\Dashboard\Widget\WidgetInterface; use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -48,11 +47,10 @@ class IframeWidget implements WidgetInterface * @param DashboardWidgetSettings $dashboardWidgetSetting * @return string the rendered content */ - public function render($dashboardWidgetSetting = null): string + public function render(DashboardWidgetSettings $dashboardWidgetSetting): string { $this->initialize($dashboardWidgetSetting); - $content = $this->generateContent(); - return $content; + return $this->generateContent(); } /** diff --git a/Classes/Widget/RssWidget.php b/Classes/Widget/RssWidget.php index be2c760..98812c6 100644 --- a/Classes/Widget/RssWidget.php +++ b/Classes/Widget/RssWidget.php @@ -1,7 +1,7 @@ initialize($dashboardWidgetSetting); if ($this->cacheLifetime > 0) { @@ -64,7 +64,7 @@ public function render($dashboardWidgetSetting = null): string /** * Initializes settings from flexform - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param DashboardWidgetSettings $dashboardWidgetSetting * @return void */ private function initialize($dashboardWidgetSetting = null) diff --git a/Classes/Widget/SysNewsWidget.php b/Classes/Widget/SysNewsWidget.php index f669ec6..6a8ee6b 100644 --- a/Classes/Widget/SysNewsWidget.php +++ b/Classes/Widget/SysNewsWidget.php @@ -14,8 +14,8 @@ * Public License for more details. * * */ +use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Backend\Utility\BackendUtility; -use Pixelant\Dashboard\Widget\WidgetInterface; class SysNewsWidget implements WidgetInterface { @@ -37,10 +37,10 @@ class SysNewsWidget implements WidgetInterface /** * Renders content - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param DashboardWidgetSettings $dashboardWidgetSetting * @return string the rendered content */ - public function render($dashboardWidgetSetting = null): string + public function render(DashboardWidgetSettings $dashboardWidgetSetting): string { $this->initialize($dashboardWidgetSetting); return $this->generateContent(); @@ -48,7 +48,7 @@ public function render($dashboardWidgetSetting = null): string /** * Initializes settings from flexform - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param DashboardWidgetSettings $dashboardWidgetSetting * @return void */ private function initialize($dashboardWidgetSetting = null) diff --git a/Classes/Widget/WidgetInterface.php b/Classes/Widget/WidgetInterface.php index b13a813..4686339 100644 --- a/Classes/Widget/WidgetInterface.php +++ b/Classes/Widget/WidgetInterface.php @@ -1,6 +1,8 @@ Date: Tue, 24 Oct 2017 10:54:25 +0200 Subject: [PATCH 19/36] Fix coding styles --- Classes/Controller/DashboardController.php | 2 +- Classes/Widget/ActionWidget.php | 1 - ext_localconf.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 5742682..9a8535f 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -26,6 +26,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\BackendTemplateView; @@ -35,7 +36,6 @@ use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter; diff --git a/Classes/Widget/ActionWidget.php b/Classes/Widget/ActionWidget.php index eea435b..95ca614 100644 --- a/Classes/Widget/ActionWidget.php +++ b/Classes/Widget/ActionWidget.php @@ -74,7 +74,6 @@ private function generateContent() if (!ExtensionManagementUtility::isLoaded('sys_action')) { throw new \Exception('Extension sys_actions is not enabled', 1910010001); } - $actionEntries = []; $widgetTemplateName = $this->widget['template']; $actionView = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class) ->get(StandaloneView::class); diff --git a/ext_localconf.php b/ext_localconf.php index 105e951..0c969a2 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,7 +3,7 @@ die('Access denied.'); } -(function() { +(function () { if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard'] = []; } From e4c9f3eb56b6849d92a549ac3855c85abfa30b83 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 10:55:31 +0200 Subject: [PATCH 20/36] Add missing import --- Classes/Widget/ActionWidget.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/Widget/ActionWidget.php b/Classes/Widget/ActionWidget.php index 95ca614..bb0c93e 100644 --- a/Classes/Widget/ActionWidget.php +++ b/Classes/Widget/ActionWidget.php @@ -14,6 +14,7 @@ * Public License for more details. * * */ +use Doctrine\DBAL\Connection; use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\ConnectionPool; @@ -66,7 +67,7 @@ private function initialize($dashboardWidgetSetting = null) /** * Generates the content - * @throws 1910010001 + * @throws \Exception * @return string */ private function generateContent() From 3a526f04ef32d6d8a1a98d360f2a95c6b045a69f Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 12:15:38 +0200 Subject: [PATCH 21/36] Minor cleanups --- Classes/Controller/DashboardController.php | 13 ++++--------- Classes/Domain/Model/Dashboard.php | 3 --- Configuration/TypoScript/setup.txt | 10 ---------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 9a8535f..0705483 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -230,14 +230,10 @@ public function createAction() $newDashboard->setTitle($getVars['dashboardName']); $newDashboard->setBeuser($beUser); $this->dashboardRepository->add($newDashboard); - $this->objectManager - ->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class) - ->persistAll(); + return $this->controllerContext->getUriBuilder()->uriFor('index', ['id' => $newDashboard->getUid()]); } - // return 'Would create dashboard with name: ' . $getVars['dashboardName']; - return $this->controllerContext->getUriBuilder()->uriFor('index', ['id' => $newDashboard->getUid()]); } - return false; //$this->controllerContext->getUriBuilder()->uriFor('index'); + return false; } /** @@ -252,7 +248,7 @@ public function renderWidgetAction() $errorTitle = $this ->getLanguageService() ->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:error.title'); - + $content = ''; if (!empty($widgetId) && (int)$widgetId > 0) { $widgetSettings = $this->dashboardWidgetSettingsRepository->findByUid($widgetId); if ($widgetSettings) { @@ -292,7 +288,7 @@ protected function registerDocheaderMenu() $dashboards = $this->dashboardRepository->findByBeuser((int)$GLOBALS['BE_USER']->user['uid']); if (!empty($dashboards)) { $dashboardMenu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); - $dashboardMenu->setIdentifier('_dsahboardSelector'); + $dashboardMenu->setIdentifier('_dashboardSelector'); foreach ($dashboards as $index => $dashboard) { $menuItem = $dashboardMenu->makeMenuItem() ->setTitle($dashboard->getTitle()) @@ -317,7 +313,6 @@ protected function registerDocheaderButtons() { /** @var ButtonBar $buttonBar */ $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar(); - $getVars = $this->request->getArguments(); // New dashboard button $newDashboardButton = $buttonBar->makeLinkButton() diff --git a/Classes/Domain/Model/Dashboard.php b/Classes/Domain/Model/Dashboard.php index 3f1a080..839824d 100644 --- a/Classes/Domain/Model/Dashboard.php +++ b/Classes/Domain/Model/Dashboard.php @@ -128,7 +128,6 @@ public function setDescription($description) * Adds a DashboardWidget * * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ public function addDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting) { @@ -139,7 +138,6 @@ public function addDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\Dashb * Removes a DashboardWidget * * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove The DashboardWidgetSettings to be removed - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ public function removeDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove) { @@ -160,7 +158,6 @@ public function getDashboardWidgetSettings() * Sets the dashboardWidgetSettings * * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> $dashboardWidgetSettings - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings */ public function setDashboardWidgetSettings(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $dashboardWidgetSettings) { diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 1e92990..14b0f1a 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -15,14 +15,4 @@ module.tx_dashboard { default = {$module.tx_dashboard.view.layoutRootPath} } } - - settings { - stylesheets { - #gridList = EXT:dashboard/Resources/Public/Css/jquery.gridList.css - } - includeJsFiles { - #gridList = EXT:dashboard/Resources/Public/JavaScript/jquery.gridList.js - #draggableGridList = EXT:dashboard/Resources/Public/JavaScript/jquery.draggableGridList.js - } - } } From be6d37ea40444345d34c3caa96d80ae1c560b198 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 12:21:54 +0200 Subject: [PATCH 22/36] [!!!] Rename widget classes to clarify they are controllers --- ...tionWidget.php => ActionWidgetController.php} | 2 +- ...rameWidget.php => IframeWidgetController.php} | 2 +- .../{RssWidget.php => RssWidgetController.php} | 2 +- ...ewsWidget.php => SysNewsWidgetController.php} | 2 +- ...terface.php => WidgetControllerInterface.php} | 5 +---- ...oard_domain_model_dashboardwidgetsettings.php | 16 ++++++++-------- ext_localconf.php | 16 ++++++++-------- 7 files changed, 21 insertions(+), 24 deletions(-) rename Classes/Widget/{ActionWidget.php => ActionWidgetController.php} (99%) rename Classes/Widget/{IframeWidget.php => IframeWidgetController.php} (97%) rename Classes/Widget/{RssWidget.php => RssWidgetController.php} (99%) rename Classes/Widget/{SysNewsWidget.php => SysNewsWidgetController.php} (98%) rename Classes/Widget/{WidgetInterface.php => WidgetControllerInterface.php} (79%) diff --git a/Classes/Widget/ActionWidget.php b/Classes/Widget/ActionWidgetController.php similarity index 99% rename from Classes/Widget/ActionWidget.php rename to Classes/Widget/ActionWidgetController.php index bb0c93e..6124e52 100644 --- a/Classes/Widget/ActionWidget.php +++ b/Classes/Widget/ActionWidgetController.php @@ -24,7 +24,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; -class ActionWidget implements WidgetInterface +class ActionWidgetController implements WidgetControllerInterface { const IDENTIFIER = '1439441923'; diff --git a/Classes/Widget/IframeWidget.php b/Classes/Widget/IframeWidgetController.php similarity index 97% rename from Classes/Widget/IframeWidget.php rename to Classes/Widget/IframeWidgetController.php index 7897259..f0353c3 100644 --- a/Classes/Widget/IframeWidget.php +++ b/Classes/Widget/IframeWidgetController.php @@ -17,7 +17,7 @@ use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Fluid\View\StandaloneView; -class IframeWidget implements WidgetInterface +class IframeWidgetController implements WidgetControllerInterface { const IDENTIFIER = '1487642496'; diff --git a/Classes/Widget/RssWidget.php b/Classes/Widget/RssWidgetController.php similarity index 99% rename from Classes/Widget/RssWidget.php rename to Classes/Widget/RssWidgetController.php index 98812c6..edb713c 100644 --- a/Classes/Widget/RssWidget.php +++ b/Classes/Widget/RssWidgetController.php @@ -3,7 +3,7 @@ use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; -class RssWidget implements WidgetInterface +class RssWidgetController implements WidgetControllerInterface { const IDENTIFIER = '41385600'; diff --git a/Classes/Widget/SysNewsWidget.php b/Classes/Widget/SysNewsWidgetController.php similarity index 98% rename from Classes/Widget/SysNewsWidget.php rename to Classes/Widget/SysNewsWidgetController.php index 6a8ee6b..29f5a3c 100644 --- a/Classes/Widget/SysNewsWidget.php +++ b/Classes/Widget/SysNewsWidgetController.php @@ -17,7 +17,7 @@ use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; use TYPO3\CMS\Backend\Utility\BackendUtility; -class SysNewsWidget implements WidgetInterface +class SysNewsWidgetController implements WidgetControllerInterface { const IDENTIFIER = '1439446997'; diff --git a/Classes/Widget/WidgetInterface.php b/Classes/Widget/WidgetControllerInterface.php similarity index 79% rename from Classes/Widget/WidgetInterface.php rename to Classes/Widget/WidgetControllerInterface.php index 4686339..131b489 100644 --- a/Classes/Widget/WidgetInterface.php +++ b/Classes/Widget/WidgetControllerInterface.php @@ -3,10 +3,7 @@ use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; -/** - * Interface for classes which provide a widget. - */ -interface WidgetInterface +interface WidgetControllerInterface { /** * Render widget content diff --git a/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php b/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php index bcca18b..4b0e442 100644 --- a/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php +++ b/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php @@ -81,19 +81,19 @@ ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', - \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER, + \Pixelant\Dashboard\Widget\RssWidgetController::IDENTIFIER, ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', - \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER, + \Pixelant\Dashboard\Widget\ActionWidgetController::IDENTIFIER, ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', - \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER, + \Pixelant\Dashboard\Widget\SysNewsWidgetController::IDENTIFIER, ], [ 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', - \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER, + \Pixelant\Dashboard\Widget\IframeWidgetController::IDENTIFIER, ], ], 'size' => 1, @@ -149,10 +149,10 @@ 'type' => 'flex', 'ds_pointerField' => 'widget_identifier', 'ds' => [ - \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_rsswidget.xml', - \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_actionwidget.xml', - \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_sysnewswidget.xml', - \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_iframewidget.xml', + \Pixelant\Dashboard\Widget\RssWidgetController::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_rsswidget.xml', + \Pixelant\Dashboard\Widget\ActionWidgetController::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_actionwidget.xml', + \Pixelant\Dashboard\Widget\SysNewsWidgetController::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_sysnewswidget.xml', + \Pixelant\Dashboard\Widget\IframeWidgetController::IDENTIFIER => 'FILE:EXT:dashboard/Configuration/FlexForms/flexform_iframewidget.xml', 'default' => 'arraynone', ], ], diff --git a/ext_localconf.php b/ext_localconf.php index 0c969a2..a018f91 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -10,39 +10,39 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dashboard'] = [ 'widgets' => [ - \Pixelant\Dashboard\Widget\RssWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\RssWidgetController::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.rsswidget.description', 'icon' => 'widget-rss', - 'class' => \Pixelant\Dashboard\Widget\RssWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/RssWidget.html', + 'class' => \Pixelant\Dashboard\Widget\RssWidgetController::class, 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \Pixelant\Dashboard\Widget\ActionWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\ActionWidgetController::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.actionwidget.description', - 'class' => \Pixelant\Dashboard\Widget\ActionWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/ActionWidget.html', + 'class' => \Pixelant\Dashboard\Widget\ActionWidgetController::class, 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \Pixelant\Dashboard\Widget\SysNewsWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\SysNewsWidgetController::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.sysnewswidget.description', - 'class' => \Pixelant\Dashboard\Widget\SysNewsWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/SysNewsWidget.html', + 'class' => \Pixelant\Dashboard\Widget\SysNewsWidgetController::class, 'defaultWidth' => '3', 'defaultHeight' => '5', 'minWidth' => '3', ], - \Pixelant\Dashboard\Widget\IframeWidget::IDENTIFIER => [ + \Pixelant\Dashboard\Widget\IframeWidgetController::IDENTIFIER => [ 'name' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.name', 'description' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:dashboardWidget.iframe.description', - 'class' => \Pixelant\Dashboard\Widget\IframeWidget::class, 'template' => 'EXT:dashboard/Resources/Private/Templates/DashboardWidgets/IframeWidget.html', + 'class' => \Pixelant\Dashboard\Widget\IframeWidgetController::class, 'defaultWidth' => '12', 'defaultHeight' => '6', 'minWidth' => '3', From 1e4b363abea3177bf96d589696bc3ce5c2ef8927 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 12:34:20 +0200 Subject: [PATCH 23/36] [!!!] Rename WidgetSettings to Widget While storing some settings as well, this class represents a concrete widget being used on a dashboard. Clarify this by renaming the class and variables --- Classes/Controller/DashboardController.php | 52 +++++++++--------- Classes/Domain/Model/Dashboard.php | 36 ++++++------ ...DashboardWidgetSettings.php => Widget.php} | 2 +- ...ngsRepository.php => WidgetRepository.php} | 8 +-- .../DashboardWidget/EditOnClickViewHelper.php | 6 +- .../GridAttributesViewHelper.php | 2 +- .../Be/DashboardWidget/IconViewHelper.php | 10 ++-- .../Be/DashboardWidget/SizeViewHelper.php | 4 +- .../Be/DashboardWidgetViewHelper.php | 12 ++-- Classes/Widget/ActionWidgetController.php | 16 +++--- Classes/Widget/IframeWidgetController.php | 16 +++--- Classes/Widget/RssWidgetController.php | 17 +++--- Classes/Widget/SysNewsWidgetController.php | 16 +++--- Classes/Widget/WidgetControllerInterface.php | 6 +- .../tx_dashboard_domain_model_dashboard.php | 12 ++-- ...p => tx_dashboard_domain_model_widget.php} | 17 +++--- Resources/Private/Language/locallang.xlf | 25 ++++----- ...sh_tx_dashboard_domain_model_dashboard.xlf | 4 +- Resources/Private/Language/locallang_db.xlf | 22 ++++---- .../Private/Templates/Dashboard/Index.html | 28 +++++----- ...f => tx_dashboard_domain_model_widget.gif} | Bin .../Backend/DashboardManager/ViewModel.js | 2 +- ext_tables.php | 4 +- ext_tables.sql | 21 ++----- 24 files changed, 163 insertions(+), 175 deletions(-) rename Classes/Domain/Model/{DashboardWidgetSettings.php => Widget.php} (98%) rename Classes/Domain/Repository/{DashboardWidgetSettingsRepository.php => WidgetRepository.php} (91%) rename Configuration/TCA/{tx_dashboard_domain_model_dashboardwidgetsettings.php => tx_dashboard_domain_model_widget.php} (89%) rename Resources/Public/Icons/{tx_dashboard_domain_model_dashboardwidgetsettings.gif => tx_dashboard_domain_model_widget.gif} (100%) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 0705483..9208e6e 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -26,7 +26,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\BackendTemplateView; @@ -73,12 +73,10 @@ class DashboardController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContro protected $dashboardRepository = null; /** - * dashboardWidgetSettingsRepository - * - * @var \Pixelant\Dashboard\Domain\Repository\DashboardWidgetSettingsRepository + * @var \Pixelant\Dashboard\Domain\Repository\WidgetRepository * @inject */ - protected $dashboardWidgetSettingsRepository = null; + protected $widgetRepository = null; /** * dashboard @@ -170,13 +168,13 @@ public function initializeChangeAction() /** * action change * - * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> $items + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\Widget> $items * @return string */ public function changeAction($items) { - foreach ($items as $widgetSettings) { - $this->dashboardWidgetSettingsRepository->update($widgetSettings); + foreach ($items as $widget) { + $this->widgetRepository->update($widget); } return 'Updated widget positions'; } @@ -195,13 +193,13 @@ public function createWidgetAction() $widgetSettings = $this->getWidgetSettings($widgetType); $width = $widgetSettings['defaultWidth'] ?? 3; $height = $widgetSettings['defaultHeight'] ?? 5; - $overrideVals = '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][dashboard]=' . $this->dashboard->getUid(); - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][widget_identifier]=' . $getVars['widgetType']; - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][width]=' . $width; - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][height]=' . $height; - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][y]=' . $this->dashboardWidgetSettingsRepository->findNextAvailableVerticalPositionOnDashboard($this->dashboard->getUid()); - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_dashboardwidgetsettings][x]=0'; - $params = '&edit[tx_dashboard_domain_model_dashboardwidgetsettings][' . $storagePid . ']=new' . $overrideVals; + $overrideVals = '&overrideVals[tx_dashboard_domain_model_widget][dashboard]=' . $this->dashboard->getUid(); + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][widget_identifier]=' . $getVars['widgetType']; + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][width]=' . $width; + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][height]=' . $height; + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][y]=' . $this->widgetRepository->findNextAvailableVerticalPositionOnDashboard($this->dashboard->getUid()); + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][x]=0'; + $params = '&edit[tx_dashboard_domain_model_widget][' . $storagePid . ']=new' . $overrideVals; $returnUrl = urlencode($this->controllerContext->getUriBuilder()->uriFor('index', ['id' => $this->dashboard->getUid()])); return BackendUtility::getModuleUrl('record_edit') . $params . '&returnUrl=' . $returnUrl; @@ -250,14 +248,14 @@ public function renderWidgetAction() ->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:error.title'); $content = ''; if (!empty($widgetId) && (int)$widgetId > 0) { - $widgetSettings = $this->dashboardWidgetSettingsRepository->findByUid($widgetId); - if ($widgetSettings) { - $widgetConfiguration = $widgetSettings->getSettings(); - $widgetClassName = $widgetConfiguration['class']; - if (class_exists($widgetClassName)) { - $widget = $this->objectManager->get($widgetClassName); + $widget = $this->widgetRepository->findByUid($widgetId); + if ($widget) { + $widgetSettings = $widget->getSettings(); + $widgetControllerClassName = $widgetSettings['class']; + if (class_exists($widgetControllerClassName)) { + $widgetController = $this->objectManager->get($widgetControllerClassName); try { - return $widget->render($widgetSettings); + return $widgetController->render($widget); } catch (\Exception $e) { $localizedError = $this ->getLanguageService() @@ -268,7 +266,7 @@ public function renderWidgetAction() $content = $this->getHtmlErrorMessage($errorTitle, $localizedError); } } else { - $content = $this->getHtmlErrorMessage($errorTitle, 'Class : ' . $widgetClassName . ' could not be found!'); + $content = $this->getHtmlErrorMessage($errorTitle, 'Class : ' . $widgetControllerClassName . ' could not be found!'); } } else { $content = $this->getHtmlErrorMessage($errorTitle, 'Widget [' . $widgetId . '] could not be found!'); @@ -337,7 +335,7 @@ protected function registerDocheaderButtons() $newWidgetButton = $buttonBar->makeLinkButton() ->setDataAttributes( [ - 'identifier' => 'newDashboardWidgetSetting', + 'identifier' => 'newWidget', 'dashboardid' => $this->dashboard->getUid(), ] ) @@ -405,7 +403,7 @@ protected function getDashboardAppInitialData(): string */ protected function getSelectableWidgets(): array { - $items = $GLOBALS['TCA']['tx_dashboard_domain_model_dashboardwidgetsettings']['columns']['widget_identifier']['config']['items']; + $items = $GLOBALS['TCA']['tx_dashboard_domain_model_widget']['columns']['widget_identifier']['config']['items']; unset($items['0']); if (!empty($items) && is_array($items)) { foreach ($items as $index => $values) { @@ -424,8 +422,8 @@ protected function getSelectableWidgets(): array */ protected function getWidgetSettings(string $widgetIdentifier): array { - $widgetSettings = new DashboardWidgetSettings($widgetIdentifier); - return $widgetSettings->getSettings(); + $widget = new Widget($widgetIdentifier); + return $widget->getSettings(); } /** diff --git a/Classes/Domain/Model/Dashboard.php b/Classes/Domain/Model/Dashboard.php index 839824d..780986e 100644 --- a/Classes/Domain/Model/Dashboard.php +++ b/Classes/Domain/Model/Dashboard.php @@ -49,13 +49,11 @@ class Dashboard extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity /** * Widgets Settings * - * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> + * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\Widget> */ - protected $dashboardWidgetSettings = null; + protected $widgets; /** - * Widgets - * * @var \TYPO3\CMS\Beuser\Domain\Model\BackendUser */ protected $beuser = null; @@ -79,7 +77,7 @@ public function __construct() */ protected function initStorageObjects() { - $this->dashboardWidgetSettings = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); + $this->widgets = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); } /** @@ -127,41 +125,41 @@ public function setDescription($description) /** * Adds a DashboardWidget * - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param \Pixelant\Dashboard\Domain\Model\Widget $widget */ - public function addDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting) + public function addWidget(\Pixelant\Dashboard\Domain\Model\Widget $widget) { - $this->dashboardWidgetSettings->attach($dashboardWidgetSetting); + $this->widgets->attach($widget); } /** * Removes a DashboardWidget * - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove The DashboardWidgetSettings to be removed + * @param \Pixelant\Dashboard\Domain\Model\Widget $widget The Widget to be removed */ - public function removeDashboardWidgetSetting(\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSettingToRemove) + public function removeWidget(\Pixelant\Dashboard\Domain\Model\Widget $widget) { - $this->dashboardWidgetSettings->detach($dashboardWidgetSettingToRemove); + $this->widgets->detach($widget); } /** - * Returns the dashboardWidgetSettings + * Returns the widget * - * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> dashboardWidgetSettings + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\Widget> */ - public function getDashboardWidgetSettings() + public function getWidgets() { - return $this->dashboardWidgetSettings; + return $this->widgets; } /** - * Sets the dashboardWidgetSettings + * Sets the widget * - * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings> $dashboardWidgetSettings + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\Dashboard\Domain\Model\Widget> $widgets */ - public function setDashboardWidgetSettings(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $dashboardWidgetSettings) + public function setWidgets(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $widgets) { - $this->dashboardWidgetSettings = $dashboardWidgetSettings; + $this->widgets = $widgets; } /** diff --git a/Classes/Domain/Model/DashboardWidgetSettings.php b/Classes/Domain/Model/Widget.php similarity index 98% rename from Classes/Domain/Model/DashboardWidgetSettings.php rename to Classes/Domain/Model/Widget.php index ddd54bf..02da017 100644 --- a/Classes/Domain/Model/DashboardWidgetSettings.php +++ b/Classes/Domain/Model/Widget.php @@ -32,7 +32,7 @@ /** * Represents dashboard widget Settings */ -class DashboardWidgetSettings extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity +class Widget extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { /** * @var FlexFormService diff --git a/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php b/Classes/Domain/Repository/WidgetRepository.php similarity index 91% rename from Classes/Domain/Repository/DashboardWidgetSettingsRepository.php rename to Classes/Domain/Repository/WidgetRepository.php index 66532d6..b51a7f2 100644 --- a/Classes/Domain/Repository/DashboardWidgetSettingsRepository.php +++ b/Classes/Domain/Repository/WidgetRepository.php @@ -27,7 +27,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Persistence\Repository; @@ -35,9 +35,9 @@ /** * The repository for Dashboards */ -class DashboardWidgetSettingsRepository extends Repository +class WidgetRepository extends Repository { - const TABLE_NAME = 'tx_dashboard_domain_model_dashboardwidgetsettings'; + const TABLE_NAME = 'tx_dashboard_domain_model_widget'; /** * @var ConnectionPool @@ -57,7 +57,7 @@ public function __construct(ObjectManagerInterface $objectManager, ConnectionPoo /** * @param int $uid - * @return DashboardWidgetSettings + * @return Widget */ public function findByUid($uid) { diff --git a/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php index 6404306..82b6764 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/EditOnClickViewHelper.php @@ -50,13 +50,13 @@ class EditOnClickViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBack * Renders a record list as known from the TYPO3 list module * Note: This feature is experimental! * - * @param Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param \Pixelant\Dashboard\Domain\Model\Widget $widget * @return string the rendered content * @see \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */ - public function render($dashboardWidgetSetting) + public function render(\Pixelant\Dashboard\Domain\Model\Widget $widget) { - $editOnClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[tx_dashboard_domain_model_dashboardwidgetsettings][' . $dashboardWidgetSetting->getUid() . ']=edit'); + $editOnClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[tx_dashboard_domain_model_widget][' . $widget->getUid() . ']=edit'); return $editOnClick; } } diff --git a/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php index d8111cb..b0d86f4 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/GridAttributesViewHelper.php @@ -28,7 +28,7 @@ class GridAttributesViewHelper extends AbstractBackendViewHelper /** * Returns a widget drop and drop attributes * - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $widgetSetting + * @param \Pixelant\Dashboard\Domain\Model\Widget $widgetSetting * @param int $index * @param string $className * diff --git a/Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php index 978b3e5..c347612 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/IconViewHelper.php @@ -21,20 +21,20 @@ * The TYPO3 project - inspiring people to share! * * */ -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; class IconViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { /** * Returns widget icon name, either defined one or default * - * @param DashboardWidgetSettings $widgetSettings + * @param Widget $widget * @return string */ - public function render(DashboardWidgetSettings $widgetSettings) + public function render(Widget $widget) { $defaultIcon = 'dashboard-widget-default'; - $widget = $widgetSettings->getSettings(); - return $widget['icon'] ?? $defaultIcon; + $widgetSettings = $widget->getSettings(); + return $widgetSettings['icon'] ?? $defaultIcon; } } diff --git a/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php index bb54d59..a13522e 100644 --- a/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidget/SizeViewHelper.php @@ -20,7 +20,7 @@ * * * The TYPO3 project - inspiring people to share! * * */ -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; class SizeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper { @@ -32,7 +32,7 @@ class SizeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendView */ public function render($widgetIdentifier) { - $widgetSetting = new DashboardWidgetSettings($widgetIdentifier); + $widgetSetting = new Widget($widgetIdentifier); $widget = $widgetSetting->getSettings(); list($width, $height) = explode('x', $widget['size']); return $this->getColumnClassName((int)$width) . ' ' . $this->getHeightClassName((int)$height); diff --git a/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php b/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php index b6d330b..6df225b 100644 --- a/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php +++ b/Classes/ViewHelpers/Be/DashboardWidgetViewHelper.php @@ -7,18 +7,18 @@ class DashboardWidgetViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\Abstract * Renders a record list as known from the TYPO3 list module * Note: This feature is experimental! * - * @param \Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings $dashboardWidgetSetting + * @param \Pixelant\Dashboard\Domain\Model\Widget $widget * @return string the rendered content * @see \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */ - public function render($dashboardWidgetSetting) + public function render($widget) { - $widget = $dashboardWidgetSetting->getSettings(); - $widgetClassName = $widget['class']; + $widgetSettings = $widget->getSettings(); + $widgetClassName = $widgetSettings['class']; if (class_exists($widgetClassName)) { - $widgetClass = $this->objectManager->get($widgetClassName); - return $widgetClass->render($dashboardWidgetSetting); + $widgetController = $this->objectManager->get($widgetClassName); + return $widgetController->render($widget); } return 'Class : ' . htmlspecialchars($widgetClassName) . ' could not be found!'; } diff --git a/Classes/Widget/ActionWidgetController.php b/Classes/Widget/ActionWidgetController.php index 6124e52..ee72df5 100644 --- a/Classes/Widget/ActionWidgetController.php +++ b/Classes/Widget/ActionWidgetController.php @@ -15,7 +15,7 @@ * */ use Doctrine\DBAL\Connection; -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; @@ -44,23 +44,25 @@ class ActionWidgetController implements WidgetControllerInterface /** * Renders content - * @param DashboardWidgetSettings $dashboardWidgetSetting + * + * @param Widget $widget * @return string the rendered content */ - public function render(DashboardWidgetSettings $dashboardWidgetSetting): string + public function render(Widget $widget): string { - $this->initialize($dashboardWidgetSetting); + $this->initialize($widget); return $this->generateContent(); } /** * Initializes settings from flexform - * @param DashboardWidgetSettings $dashboardWidgetSetting + * + * @param Widget $widget * @return void */ - private function initialize($dashboardWidgetSetting = null) + private function initialize($widget = null) { - $settings = $dashboardWidgetSetting->getSettings(); + $settings = $widget->getSettings(); $this->limit = (int)$settings['limit']; $this->widget = $settings; } diff --git a/Classes/Widget/IframeWidgetController.php b/Classes/Widget/IframeWidgetController.php index f0353c3..6d06953 100644 --- a/Classes/Widget/IframeWidgetController.php +++ b/Classes/Widget/IframeWidgetController.php @@ -14,7 +14,7 @@ * Public License for more details. * * */ -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; use TYPO3\CMS\Fluid\View\StandaloneView; class IframeWidgetController implements WidgetControllerInterface @@ -44,23 +44,25 @@ class IframeWidgetController implements WidgetControllerInterface /** * Renders content - * @param DashboardWidgetSettings $dashboardWidgetSetting + * + * @param Widget $widget * @return string the rendered content */ - public function render(DashboardWidgetSettings $dashboardWidgetSetting): string + public function render(Widget $widget): string { - $this->initialize($dashboardWidgetSetting); + $this->initialize($widget); return $this->generateContent(); } /** * Initializes settings from flexform - * @param DashboardWidgetSettings $dashboardWidgetSetting + * + * @param Widget $widget * @return void */ - private function initialize($dashboardWidgetSetting = null) + private function initialize($widget = null) { - $settings = $dashboardWidgetSetting->getSettings(); + $settings = $widget->getSettings(); $this->url = $settings['url']; $this->scrolling = $settings['scrolling']; $this->widget = $settings; diff --git a/Classes/Widget/RssWidgetController.php b/Classes/Widget/RssWidgetController.php index edb713c..29a747c 100644 --- a/Classes/Widget/RssWidgetController.php +++ b/Classes/Widget/RssWidgetController.php @@ -1,7 +1,7 @@ initialize($dashboardWidgetSetting); + $this->initialize($widget); if ($this->cacheLifetime > 0) { $content = $this->generateContent(); } else { /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Core\\Cache\\CacheManager'); - $cacheIdentifier = 'dashboardWidget_' . (int)$dashboardWidgetSetting->getUid(); + $cacheIdentifier = 'dashboardWidget_' . (int)$widget->getUid(); if (true === $cacheManager->hasCache('dashboard') && true === $cacheManager->getCache('dashboard')->has($cacheIdentifier)) { $content = $cacheManager->getCache('dashboard')->get($cacheIdentifier); @@ -64,12 +65,12 @@ public function render(DashboardWidgetSettings $dashboardWidgetSetting): string /** * Initializes settings from flexform - * @param DashboardWidgetSettings $dashboardWidgetSetting + * @param Widget $widget * @return void */ - private function initialize($dashboardWidgetSetting = null) + private function initialize($widget = null) { - $settings = $dashboardWidgetSetting->getSettings(); + $settings = $widget->getSettings(); $this->feedUrl = $settings['feedUrl']; $this->feedLimit = (int)$settings['feedLimit']; $this->cacheLifetime = (int)$settings['cacheLifetime'] * 60; diff --git a/Classes/Widget/SysNewsWidgetController.php b/Classes/Widget/SysNewsWidgetController.php index 29f5a3c..3903828 100644 --- a/Classes/Widget/SysNewsWidgetController.php +++ b/Classes/Widget/SysNewsWidgetController.php @@ -14,7 +14,7 @@ * Public License for more details. * * */ -use Pixelant\Dashboard\Domain\Model\DashboardWidgetSettings; +use Pixelant\Dashboard\Domain\Model\Widget; use TYPO3\CMS\Backend\Utility\BackendUtility; class SysNewsWidgetController implements WidgetControllerInterface @@ -37,23 +37,25 @@ class SysNewsWidgetController implements WidgetControllerInterface /** * Renders content - * @param DashboardWidgetSettings $dashboardWidgetSetting + * + * @param Widget $widget * @return string the rendered content */ - public function render(DashboardWidgetSettings $dashboardWidgetSetting): string + public function render(Widget $widget): string { - $this->initialize($dashboardWidgetSetting); + $this->initialize($widget); return $this->generateContent(); } /** * Initializes settings from flexform - * @param DashboardWidgetSettings $dashboardWidgetSetting + * + * @param Widget $widget * @return void */ - private function initialize($dashboardWidgetSetting = null) + private function initialize($widget = null) { - $settings = $dashboardWidgetSetting->getSettings(); + $settings = $widget->getSettings(); $this->limit = (int)$settings['limit']; $this->widget = $settings; } diff --git a/Classes/Widget/WidgetControllerInterface.php b/Classes/Widget/WidgetControllerInterface.php index 131b489..8cec8cc 100644 --- a/Classes/Widget/WidgetControllerInterface.php +++ b/Classes/Widget/WidgetControllerInterface.php @@ -1,15 +1,15 @@ 'starttime', 'endtime' => 'endtime', ], - 'searchFields' => 'title,description,dashboard_widget_settings,beuser,', + 'searchFields' => 'title,description,widgets,beuser,', 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboard.gif', ], 'interface' => [ - 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title, description, dashboard_widget_settings, beuser', + 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title, description, widgets, beuser', ], 'types' => [ - '1' => ['showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1, title, description, dashboard_widget_settings, beuser, --div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, starttime, endtime'], + '1' => ['showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1, title, description, widgets, beuser, --div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, starttime, endtime'], ], 'palettes' => [ '1' => ['showitem' => ''], @@ -118,12 +118,12 @@ 'eval' => 'trim', ], ], - 'dashboard_widget_settings' => [ + 'widgets' => [ 'exclude' => 1, - 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboard.dashboard_widget_settings', + 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboard.widgets', 'config' => [ 'type' => 'inline', - 'foreign_table' => 'tx_dashboard_domain_model_dashboardwidgetsettings', + 'foreign_table' => 'tx_dashboard_domain_model_widget', 'foreign_field' => 'dashboard', 'foreign_sortby' => 'sorting', 'MM_opposite_field' => 'dashboard', diff --git a/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php b/Configuration/TCA/tx_dashboard_domain_model_widget.php similarity index 89% rename from Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php rename to Configuration/TCA/tx_dashboard_domain_model_widget.php index 4b0e442..f37dbb9 100644 --- a/Configuration/TCA/tx_dashboard_domain_model_dashboardwidgetsettings.php +++ b/Configuration/TCA/tx_dashboard_domain_model_widget.php @@ -1,7 +1,7 @@ [ - 'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboardwidgetsettings', + 'title' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_widget', 'label' => 'title', 'tstamp' => 'tstamp', 'crdate' => 'crdate', @@ -15,14 +15,14 @@ 'enablecolumns' => [], 'requestUpdate' => 'widget_identifier', 'searchFields' => 'title,widget_identifier,position,settings_flexform,', - 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_dashboardwidgetsettings.gif', + 'iconfile' => 'EXT:dashboard/Resources/Public/Icons/tx_dashboard_domain_model_widget.gif', ], 'interface' => [ 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, title, widget_identifier, position, settings_flexform, dashboard, x, y, width, height', ], 'types' => [ '1' => [ - 'showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, title, widget_identifier, position, settings_flexform, dashboard, x, y, width, height, ', + 'showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, widget_identifier, title, position, settings_flexform, dashboard', ], ], 'palettes' => [ @@ -48,8 +48,8 @@ 'items' => [ ['', 0], ], - 'foreign_table' => 'tx_dashboard_domain_model_dashboardwidgetsettings', - 'foreign_table_where' => 'AND tx_dashboard_domain_model_dashboardwidgetsettings.pid=###CURRENT_PID### AND tx_dashboard_domain_model_dashboardwidgetsettings.sys_language_uid IN (-1,0)', + 'foreign_table' => 'tx_dashboard_domain_model_widget', + 'foreign_table_where' => 'AND tx_dashboard_domain_model_widget.pid=###CURRENT_PID### AND tx_dashboard_domain_model_widget.sys_language_uid IN (-1,0)', ], ], 'l10n_diffsource' => [ @@ -60,7 +60,7 @@ 'title' => [ 'exclude' => 1, - 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboardwidgetsettings.title', + 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_widget.title', 'config' => [ 'type' => 'input', 'size' => 30, @@ -69,7 +69,7 @@ ], 'widget_identifier' => [ 'exclude' => 1, - 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboardwidgetsettings.widget_identifier', + 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_widget.widget_identifier', 'config' => [ 'type' => 'select', 'readOnly' => 1, @@ -144,7 +144,7 @@ ], 'settings_flexform' => [ 'exclude' => 1, - 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboardwidgetsettings.settings_flexform', + 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_widget.settings_flexform', 'config' => [ 'type' => 'flex', 'ds_pointerField' => 'widget_identifier', @@ -158,6 +158,7 @@ ], ], 'dashboard' => [ + 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboard', 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 90dfdbf..4eda979 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -24,29 +24,29 @@ Description - - Dashboard Widget Settings + + Widgets Beuser - - Dashboard Widget Settings + + Widget - + Title - + Widget Identifier - + State - + Position - - Settings Flexform + + Widget Settings Dashboard Widgets @@ -63,7 +63,7 @@ Message - + Add new widget @@ -90,9 +90,6 @@ An iframe module - - Dashboard Settings - No actions found diff --git a/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboard.xlf b/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboard.xlf index 20f1fb9..26f6572 100644 --- a/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboard.xlf +++ b/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboard.xlf @@ -9,8 +9,8 @@ Description - - Widgets Settings + + Widgets Widgets diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index d0ea3d5..891bad2 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -12,29 +12,29 @@ Description - - Dashboard Widget Settings + + Widgets Beuser - - Dashboard Widget Settings + + Widget - + Title - - Widget Identifier + + Widget Type - + State - + Position - - Settings Flexform + + Widget Settings Dashboard Widgets diff --git a/Resources/Private/Templates/Dashboard/Index.html b/Resources/Private/Templates/Dashboard/Index.html index e385414..797a1a2 100644 --- a/Resources/Private/Templates/Dashboard/Index.html +++ b/Resources/Private/Templates/Dashboard/Index.html @@ -15,37 +15,37 @@ - +
- + @@ -61,7 +61,7 @@

- +
diff --git a/Resources/Public/Icons/tx_dashboard_domain_model_dashboardwidgetsettings.gif b/Resources/Public/Icons/tx_dashboard_domain_model_widget.gif similarity index 100% rename from Resources/Public/Icons/tx_dashboard_domain_model_dashboardwidgetsettings.gif rename to Resources/Public/Icons/tx_dashboard_domain_model_widget.gif diff --git a/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js b/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js index 87c1dc2..cb1d424 100644 --- a/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js +++ b/Resources/Public/JavaScript/Backend/DashboardManager/ViewModel.js @@ -53,7 +53,7 @@ define(['jquery', newDashboardModalTrigger: {identifier: '[data-identifier="newDashboard"]' }, newDashboardName: { identifier: '[data-identifier="newDashboardName"]' }, editDashboardTrigger: { identifier: '[data-identifier="editDashboard"]' }, - newWidgetModalTrigger: {identifier: '[data-identifier="newDashboardWidgetSetting"]' }, + newWidgetModalTrigger: {identifier: '[data-identifier="newWidget"]' }, newWidgetType: { identifier: '[data-identifier="newWidgetType"]'}, refreshWidgetTrigger: { identifier: '[data-identifier="refreshWidget"]'}, } diff --git a/ext_tables.php b/ext_tables.php index 6f51c55..09015a8 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -24,5 +24,5 @@ \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_dashboard_domain_model_dashboard', 'EXT:dashboard/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboard.xlf'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_dashboard_domain_model_dashboard'); -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_dashboard_domain_model_dashboardwidgetsettings', 'EXT:dashboard/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_dashboardwidgetsettings.xlf'); -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_dashboard_domain_model_dashboardwidgetsettings'); +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_dashboard_domain_model_widget', 'EXT:dashboard/Resources/Private/Language/locallang_csh_tx_dashboard_domain_model_widget.xlf'); +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_dashboard_domain_model_widget'); diff --git a/ext_tables.sql b/ext_tables.sql index a6424f6..4cfa7c7 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -8,7 +8,7 @@ CREATE TABLE tx_dashboard_domain_model_dashboard ( title varchar(255) DEFAULT '' NOT NULL, description varchar(255) DEFAULT '' NOT NULL, - dashboard_widget_settings int(11) unsigned DEFAULT '0' NOT NULL, + widgets int(11) unsigned DEFAULT '0' NOT NULL, beuser int(11) unsigned DEFAULT '0', tstamp int(11) unsigned DEFAULT '0' NOT NULL, @@ -32,9 +32,9 @@ CREATE TABLE tx_dashboard_domain_model_dashboard ( ); # -# Table structure for table 'tx_dashboard_domain_model_dashboardwidgetsettings' +# Table structure for table 'tx_dashboard_domain_model_widget' # -CREATE TABLE tx_dashboard_domain_model_dashboardwidgetsettings ( +CREATE TABLE tx_dashboard_domain_model_widget ( uid int(11) NOT NULL auto_increment, pid int(11) DEFAULT '0' NOT NULL, @@ -61,18 +61,5 @@ CREATE TABLE tx_dashboard_domain_model_dashboardwidgetsettings ( PRIMARY KEY (uid), KEY parent (pid), - - KEY language (l10n_parent,sys_language_uid) - -); - -# -# Table structure for table 'tx_dashboard_domain_model_dashboardwidgetsettings' -# -CREATE TABLE tx_dashboard_domain_model_dashboardwidgetsettings ( - - dashboard int(11) unsigned DEFAULT '0' NOT NULL, - + KEY language (l10n_parent,sys_language_uid) ); - -## EXTENSION BUILDER DEFAULTS END TOKEN - Everything BEFORE this line is overwritten with the defaults of the extension builder \ No newline at end of file From ce259cf2954e2a8086476d8d5af1be00fea07f7c Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 15:24:14 +0200 Subject: [PATCH 24/36] Move vertical position finding to dashboard Since it is in the domain of the dashboard to know, which the next available vertical position is available, we put this logic into the dashboard model and on the go fix a bug here. --- Classes/Controller/DashboardController.php | 2 +- Classes/Domain/Model/Dashboard.php | 16 ++++++++++ .../Domain/Repository/WidgetRepository.php | 31 ------------------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 9208e6e..484720f 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -197,7 +197,7 @@ public function createWidgetAction() $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][widget_identifier]=' . $getVars['widgetType']; $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][width]=' . $width; $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][height]=' . $height; - $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][y]=' . $this->widgetRepository->findNextAvailableVerticalPositionOnDashboard($this->dashboard->getUid()); + $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][y]=' . $this->dashboard->findNextAvailableWidgetPosition(); $overrideVals .= '&overrideVals[tx_dashboard_domain_model_widget][x]=0'; $params = '&edit[tx_dashboard_domain_model_widget][' . $storagePid . ']=new' . $overrideVals; diff --git a/Classes/Domain/Model/Dashboard.php b/Classes/Domain/Model/Dashboard.php index 780986e..1aee0d1 100644 --- a/Classes/Domain/Model/Dashboard.php +++ b/Classes/Domain/Model/Dashboard.php @@ -80,6 +80,22 @@ protected function initStorageObjects() $this->widgets = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); } + /** + * @return int + */ + public function findNextAvailableWidgetPosition(): int + { + if (!$this->widgets || $this->widgets->count() === 0) { + return 0; + } + $orderedWidgets = iterator_to_array($this->widgets); + usort($orderedWidgets, function($widgetOne, $widgetTwo) { + return $widgetOne->getY() + $widgetOne->getHeight() < $widgetTwo->getY() + $widgetTwo->getHeight(); + }); + + return $orderedWidgets[0]->getY() + $orderedWidgets[0]->getHeight(); + } + /** * Returns the title * diff --git a/Classes/Domain/Repository/WidgetRepository.php b/Classes/Domain/Repository/WidgetRepository.php index b51a7f2..e108b0b 100644 --- a/Classes/Domain/Repository/WidgetRepository.php +++ b/Classes/Domain/Repository/WidgetRepository.php @@ -63,35 +63,4 @@ public function findByUid($uid) { return parent::findByUid($uid); } - - /** - * @param int $dashBoardId - * @return int - */ - public function findNextAvailableVerticalPositionOnDashboard(int $dashBoardId): int - { - $availablePosition = 0; - - $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME); - - $result = $queryBuilder - ->select('y', 'height') - ->from(self::TABLE_NAME) - ->where( - $queryBuilder->expr()->eq( - 'dashboard', - $queryBuilder->createNamedParameter($dashBoardId, \PDO::PARAM_INT) - ) - ) - ->orderBy('y', 'DESC') - ->addOrderBy('height', 'DESC') - ->setMaxResults(1) - ->execute() - ->fetch(); - - if ($result) { - $availablePosition = $result['y'] + $result['height']; - } - return $availablePosition; - } } From d455bcef7248f9404833a662705ec0623ff0d293 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 16:57:37 +0200 Subject: [PATCH 25/36] [!!!] Remove widget repository Widgets are only valid when attached to a dashboard and are not aggregate root objects. Thus the repository is removed and widgets are now only fetched from the current dashboard --- Classes/Controller/DashboardController.php | 43 ++++++------ Classes/Domain/Model/Dashboard.php | 24 +++++++ .../Domain/Repository/WidgetRepository.php | 66 ------------------- .../tx_dashboard_domain_model_dashboard.php | 11 +--- 4 files changed, 45 insertions(+), 99 deletions(-) delete mode 100644 Classes/Domain/Repository/WidgetRepository.php diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 484720f..20a9f0c 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -72,12 +72,6 @@ class DashboardController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContro */ protected $dashboardRepository = null; - /** - * @var \Pixelant\Dashboard\Domain\Repository\WidgetRepository - * @inject - */ - protected $widgetRepository = null; - /** * dashboard * @@ -174,8 +168,9 @@ public function initializeChangeAction() public function changeAction($items) { foreach ($items as $widget) { - $this->widgetRepository->update($widget); + $this->dashboard->updateWidget($widget); } + $this->dashboardRepository->update($this->dashboard); return 'Updated widget positions'; } @@ -187,7 +182,7 @@ public function changeAction($items) public function createWidgetAction() { $getVars = $this->request->getArguments(); - if (is_object($this->dashboard)) { + if ($this->dashboard) { $storagePid = $this->dashboardSettings['persistence']['storagePid']; $widgetType = $getVars['widgetType']; $widgetSettings = $this->getWidgetSettings($widgetType); @@ -237,18 +232,17 @@ public function createAction() /** * action renderWidget * + * @param int $widgetId * @return string */ - public function renderWidgetAction() + public function renderWidgetAction(int $widgetId) { - $getVars = $this->request->getArguments(); - $widgetId = $getVars['widgetId']; $errorTitle = $this ->getLanguageService() ->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:error.title'); $content = ''; if (!empty($widgetId) && (int)$widgetId > 0) { - $widget = $this->widgetRepository->findByUid($widgetId); + $widget = $this->dashboard->getWidgetById($widgetId); if ($widget) { $widgetSettings = $widget->getSettings(); $widgetControllerClassName = $widgetSettings['class']; @@ -287,11 +281,13 @@ protected function registerDocheaderMenu() if (!empty($dashboards)) { $dashboardMenu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); $dashboardMenu->setIdentifier('_dashboardSelector'); + $uriBuilder = $this->controllerContext->getUriBuilder(); foreach ($dashboards as $index => $dashboard) { + $uriBuilder->reset(); $menuItem = $dashboardMenu->makeMenuItem() ->setTitle($dashboard->getTitle()) ->setHref( - $this->controllerContext->getUriBuilder()->uriFor('index', ['id' => $dashboard->getUid()]) + $uriBuilder->uriFor('index', ['id' => $dashboard->getUid()]) ); if ($dashboard->getUid() === $this->dashboard->getUid()) { $menuItem->setActive(true); @@ -364,27 +360,26 @@ protected function registerDocheaderButtons() */ protected function getDashboardAppInitialData(): string { + $uriBuilder = $this->controllerContext->getUriBuilder(); + $uriBuilder->reset(); + $uriArguments = $this->dashboard ? ['id' => $this->dashboard->getUid()] : []; $dashboardAppInitialData = [ 'selectableWidgetTypesConfiguration' => $this->getSelectableWidgets(), 'endpoints' => [ - 'create' => $this->controllerContext->getUriBuilder()->uriFor('create'), - 'createWidget' => $this->controllerContext->getUriBuilder()->uriFor('createWidget'), - 'change' => $this->controllerContext->getUriBuilder()->uriFor('change'), - 'index' => $this->controllerContext->getUriBuilder()->uriFor('index'), - 'renderWidget' => $this->controllerContext->getUriBuilder()->uriFor('renderWidget'), + 'create' => $uriBuilder->uriFor('create'), + 'createWidget' => $uriBuilder->uriFor('createWidget', $uriArguments), + 'change' => $uriBuilder->uriFor('change', $uriArguments), + 'index' => $uriBuilder->uriFor('index', $uriArguments), + 'renderWidget' => $uriBuilder->uriFor('renderWidget', $uriArguments), 'editDashboard' => $this->getEditDashboardEndpoint(), ], ]; - if (is_object($this->dashboard)) { + if ($this->dashboard) { $dashboardAppInitialData['dashboard'] = [ 'id' => $this->dashboard->getUid(), 'title' => $this->dashboard->getTitle(), ]; - $dashboardAppInitialData['endpoints']['index'] = - $this->controllerContext->getUriBuilder()->uriFor( - 'index', ['id' => $this->dashboard->getUid()] - ); } $dashboardAppInitialData = ArrayUtility::reIndexNumericArrayKeysRecursive($dashboardAppInitialData); @@ -434,7 +429,7 @@ protected function getWidgetSettings(string $widgetIdentifier): array protected function getEditDashboardEndpoint() { $editDashboardEndpoint = ''; - if (is_object($this->dashboard)) { + if ($this->dashboard) { $params = '&edit[tx_dashboard_domain_model_dashboard][' . $this->dashboard->getUid() . ']=edit'; $returnUrl = urlencode($this->controllerContext->getUriBuilder()->uriFor('index', ['id' => $this->dashboard->getUid()])); $editDashboardEndpoint = BackendUtility::getModuleUrl('record_edit') . $params . '&returnUrl=' . $returnUrl; diff --git a/Classes/Domain/Model/Dashboard.php b/Classes/Domain/Model/Dashboard.php index 1aee0d1..a578625 100644 --- a/Classes/Domain/Model/Dashboard.php +++ b/Classes/Domain/Model/Dashboard.php @@ -1,4 +1,5 @@ getY() + $orderedWidgets[0]->getHeight(); } + public function updateWidget(Widget $updatedWidget) + { + $widget = $this->getWidgetById($updatedWidget->getUid()); + if ($widget) { + $this->widgets->detach($widget); + $this->widgets->attach($updatedWidget); + } + } + + /** + * @param int $uid + * @return Widget|null + */ + public function getWidgetById(int $uid) + { + foreach ($this->widgets as $widget) { + if ($widget->getUid() === $uid) { + return $widget; + } + } + return null; + } + /** * Returns the title * diff --git a/Classes/Domain/Repository/WidgetRepository.php b/Classes/Domain/Repository/WidgetRepository.php deleted file mode 100644 index e108b0b..0000000 --- a/Classes/Domain/Repository/WidgetRepository.php +++ /dev/null @@ -1,66 +0,0 @@ -connectionPool = $connectionPool; - } - - /** - * @param int $uid - * @return Widget - */ - public function findByUid($uid) - { - return parent::findByUid($uid); - } -} diff --git a/Configuration/TCA/tx_dashboard_domain_model_dashboard.php b/Configuration/TCA/tx_dashboard_domain_model_dashboard.php index f8ea7d9..c1e02bd 100644 --- a/Configuration/TCA/tx_dashboard_domain_model_dashboard.php +++ b/Configuration/TCA/tx_dashboard_domain_model_dashboard.php @@ -122,19 +122,12 @@ 'exclude' => 1, 'label' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_db.xlf:tx_dashboard_domain_model_dashboard.widgets', 'config' => [ - 'type' => 'inline', + 'type' => 'select', + 'renderType' => 'selectMultipleSideBySide', 'foreign_table' => 'tx_dashboard_domain_model_widget', 'foreign_field' => 'dashboard', 'foreign_sortby' => 'sorting', - 'MM_opposite_field' => 'dashboard', 'maxitems' => 9999, - 'appearance' => [ - 'collapseAll' => 1, - 'levelLinksPosition' => 'top', - 'showSynchronizationLink' => 1, - 'showPossibleLocalizationRecords' => 1, - 'showAllLocalizationLink' => 1, - ], ], ], 'beuser' => [ From eb0df29c979dc9bec38bc6b884c6fe6a5912d12e Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 24 Oct 2017 17:12:38 +0200 Subject: [PATCH 26/36] Remove Fluid variables from JS context --- Classes/Controller/DashboardController.php | 6 +++--- Resources/Private/Templates/Dashboard/Index.html | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Classes/Controller/DashboardController.php b/Classes/Controller/DashboardController.php index 20a9f0c..e13bff7 100644 --- a/Classes/Controller/DashboardController.php +++ b/Classes/Controller/DashboardController.php @@ -356,9 +356,9 @@ protected function registerDocheaderButtons() * Returns the json encoded data which is used by the dashboard * JavaScript app. * - * @return string + * @return array */ - protected function getDashboardAppInitialData(): string + protected function getDashboardAppInitialData(): array { $uriBuilder = $this->controllerContext->getUriBuilder(); $uriBuilder->reset(); @@ -388,7 +388,7 @@ protected function getDashboardAppInitialData(): string $this->dashboardSettings['settings']['translationFile'] ); - return json_encode($dashboardAppInitialData); + return $dashboardAppInitialData; } /** diff --git a/Resources/Private/Templates/Dashboard/Index.html b/Resources/Private/Templates/Dashboard/Index.html index 797a1a2..f24de1c 100644 --- a/Resources/Private/Templates/Dashboard/Index.html +++ b/Resources/Private/Templates/Dashboard/Index.html @@ -3,11 +3,12 @@ - +