@@ -20,84 +20,84 @@ |
||
20 | 20 | class UserPreferencesViewHelper extends AbstractViewHelper |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var AbstractFrontend |
|
25 | - */ |
|
26 | - protected $cacheInstance; |
|
23 | + /** |
|
24 | + * @var AbstractFrontend |
|
25 | + */ |
|
26 | + protected $cacheInstance; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function initializeArguments() |
|
32 | - { |
|
33 | - $this->registerArgument('key', 'string', '', true); |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function initializeArguments() |
|
32 | + { |
|
33 | + $this->registerArgument('key', 'string', '', true); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Interface with the BE user data. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function render() |
|
42 | - { |
|
43 | - $this->initializeCache(); |
|
44 | - $key = $this->getModuleLoader()->getDataType() . '_' . $this->getBackendUserIdentifier() . '_' . $this->arguments['key']; |
|
36 | + /** |
|
37 | + * Interface with the BE user data. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function render() |
|
42 | + { |
|
43 | + $this->initializeCache(); |
|
44 | + $key = $this->getModuleLoader()->getDataType() . '_' . $this->getBackendUserIdentifier() . '_' . $this->arguments['key']; |
|
45 | 45 | |
46 | - $value = $this->cacheInstance->get($key); |
|
47 | - if ($value) { |
|
48 | - $value = addslashes($value); |
|
49 | - } else { |
|
50 | - $value = ''; |
|
51 | - } |
|
52 | - return $value; |
|
53 | - } |
|
46 | + $value = $this->cacheInstance->get($key); |
|
47 | + if ($value) { |
|
48 | + $value = addslashes($value); |
|
49 | + } else { |
|
50 | + $value = ''; |
|
51 | + } |
|
52 | + return $value; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return int |
|
57 | - */ |
|
58 | - protected function getBackendUserIdentifier() |
|
59 | - { |
|
60 | - return $this->getBackendUser()->user['uid']; |
|
61 | - } |
|
55 | + /** |
|
56 | + * @return int |
|
57 | + */ |
|
58 | + protected function getBackendUserIdentifier() |
|
59 | + { |
|
60 | + return $this->getBackendUser()->user['uid']; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Returns an instance of the current Backend User. |
|
65 | - * |
|
66 | - * @return BackendUserAuthentication |
|
67 | - */ |
|
68 | - protected function getBackendUser() |
|
69 | - { |
|
70 | - return $GLOBALS['BE_USER']; |
|
71 | - } |
|
63 | + /** |
|
64 | + * Returns an instance of the current Backend User. |
|
65 | + * |
|
66 | + * @return BackendUserAuthentication |
|
67 | + */ |
|
68 | + protected function getBackendUser() |
|
69 | + { |
|
70 | + return $GLOBALS['BE_USER']; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Get the Vidi Module Loader. |
|
75 | - * |
|
76 | - * @return ModuleLoader|object |
|
77 | - */ |
|
78 | - protected function getModuleLoader() |
|
79 | - { |
|
80 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
81 | - } |
|
73 | + /** |
|
74 | + * Get the Vidi Module Loader. |
|
75 | + * |
|
76 | + * @return ModuleLoader|object |
|
77 | + */ |
|
78 | + protected function getModuleLoader() |
|
79 | + { |
|
80 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Initialize cache instance to be ready to use |
|
85 | - * |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - protected function initializeCache() |
|
89 | - { |
|
90 | - $this->cacheInstance = $this->getCacheManager()->getCache('vidi'); |
|
91 | - } |
|
83 | + /** |
|
84 | + * Initialize cache instance to be ready to use |
|
85 | + * |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + protected function initializeCache() |
|
89 | + { |
|
90 | + $this->cacheInstance = $this->getCacheManager()->getCache('vidi'); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Return the Cache Manager |
|
95 | - * |
|
96 | - * @return CacheManager|object |
|
97 | - */ |
|
98 | - protected function getCacheManager() |
|
99 | - { |
|
100 | - return GeneralUtility::makeInstance(CacheManager::class); |
|
101 | - } |
|
93 | + /** |
|
94 | + * Return the Cache Manager |
|
95 | + * |
|
96 | + * @return CacheManager|object |
|
97 | + */ |
|
98 | + protected function getCacheManager() |
|
99 | + { |
|
100 | + return GeneralUtility::makeInstance(CacheManager::class); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -19,88 +19,88 @@ |
||
19 | 19 | class RelationAnalyserTool extends AbstractTool |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Display the title of the tool on the welcome screen. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function getTitle(): string |
|
28 | - { |
|
29 | - return LocalizationUtility::translate( |
|
30 | - 'analyse_relations', |
|
31 | - 'vidi' |
|
32 | - ); |
|
33 | - } |
|
22 | + /** |
|
23 | + * Display the title of the tool on the welcome screen. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function getTitle(): string |
|
28 | + { |
|
29 | + return LocalizationUtility::translate( |
|
30 | + 'analyse_relations', |
|
31 | + 'vidi' |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Display the description of the tool in the welcome screen. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getDescription(): string |
|
41 | - { |
|
42 | - $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/RelationAnalyser/Launcher.html'; |
|
43 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
45 | - $view->assign('dataType', $this->getModuleLoader()->getDataType()); |
|
46 | - return $view->render(); |
|
47 | - } |
|
35 | + /** |
|
36 | + * Display the description of the tool in the welcome screen. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getDescription(): string |
|
41 | + { |
|
42 | + $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/RelationAnalyser/Launcher.html'; |
|
43 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
44 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
45 | + $view->assign('dataType', $this->getModuleLoader()->getDataType()); |
|
46 | + return $view->render(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Do the job |
|
51 | - * |
|
52 | - * @param array $arguments |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function work(array $arguments = array()): string |
|
56 | - { |
|
49 | + /** |
|
50 | + * Do the job |
|
51 | + * |
|
52 | + * @param array $arguments |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function work(array $arguments = array()): string |
|
56 | + { |
|
57 | 57 | |
58 | - $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/RelationAnalyser/WorkResult.html'; |
|
59 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
58 | + $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/RelationAnalyser/WorkResult.html'; |
|
59 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
60 | 60 | |
61 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
62 | - $analyse = $this->getGridAnalyserService()->checkRelationForTable($dataType); |
|
61 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
62 | + $analyse = $this->getGridAnalyserService()->checkRelationForTable($dataType); |
|
63 | 63 | |
64 | - if (empty($analyse)) { |
|
65 | - $result = 'No relation involved in this Grid.'; |
|
66 | - } else { |
|
67 | - $result = implode("\n", $analyse); |
|
68 | - } |
|
64 | + if (empty($analyse)) { |
|
65 | + $result = 'No relation involved in this Grid.'; |
|
66 | + } else { |
|
67 | + $result = implode("\n", $analyse); |
|
68 | + } |
|
69 | 69 | |
70 | - $view->assign('result', $result); |
|
71 | - $view->assign('dataType', $dataType); |
|
70 | + $view->assign('result', $result); |
|
71 | + $view->assign('dataType', $dataType); |
|
72 | 72 | |
73 | - return $view->render(); |
|
74 | - } |
|
73 | + return $view->render(); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Tell whether the tools should be displayed according to the context. |
|
78 | - * |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function isShown(): bool |
|
82 | - { |
|
83 | - return $this->getBackendUser()->isAdmin(); |
|
84 | - } |
|
76 | + /** |
|
77 | + * Tell whether the tools should be displayed according to the context. |
|
78 | + * |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function isShown(): bool |
|
82 | + { |
|
83 | + return $this->getBackendUser()->isAdmin(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get the Vidi Module Loader. |
|
88 | - * |
|
89 | - * @return ModuleLoader|object |
|
90 | - */ |
|
91 | - protected function getModuleLoader(): ModuleLoader |
|
92 | - { |
|
93 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
94 | - } |
|
86 | + /** |
|
87 | + * Get the Vidi Module Loader. |
|
88 | + * |
|
89 | + * @return ModuleLoader|object |
|
90 | + */ |
|
91 | + protected function getModuleLoader(): ModuleLoader |
|
92 | + { |
|
93 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Get the Vidi Module Loader. |
|
98 | - * |
|
99 | - * @return GridAnalyserService|object |
|
100 | - */ |
|
101 | - protected function getGridAnalyserService() |
|
102 | - { |
|
103 | - return GeneralUtility::makeInstance(GridAnalyserService::class); |
|
104 | - } |
|
96 | + /** |
|
97 | + * Get the Vidi Module Loader. |
|
98 | + * |
|
99 | + * @return GridAnalyserService|object |
|
100 | + */ |
|
101 | + protected function getGridAnalyserService() |
|
102 | + { |
|
103 | + return GeneralUtility::makeInstance(GridAnalyserService::class); |
|
104 | + } |
|
105 | 105 | } |
106 | 106 |
@@ -19,51 +19,51 @@ |
||
19 | 19 | abstract class AbstractTool implements ToolInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $templateNameAndPath |
|
24 | - * @return StandaloneView |
|
25 | - * @throws \InvalidArgumentException |
|
26 | - */ |
|
27 | - protected function initializeStandaloneView($templateNameAndPath) |
|
28 | - { |
|
22 | + /** |
|
23 | + * @param string $templateNameAndPath |
|
24 | + * @return StandaloneView |
|
25 | + * @throws \InvalidArgumentException |
|
26 | + */ |
|
27 | + protected function initializeStandaloneView($templateNameAndPath) |
|
28 | + { |
|
29 | 29 | |
30 | - $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath); |
|
30 | + $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath); |
|
31 | 31 | |
32 | - /** @var StandaloneView $view */ |
|
33 | - $view = $this->getObjectManager()->get(StandaloneView::class); |
|
32 | + /** @var StandaloneView $view */ |
|
33 | + $view = $this->getObjectManager()->get(StandaloneView::class); |
|
34 | 34 | |
35 | - $view->setTemplatePathAndFilename($templateNameAndPath); |
|
36 | - return $view; |
|
37 | - } |
|
35 | + $view->setTemplatePathAndFilename($templateNameAndPath); |
|
36 | + return $view; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns an instance of the current Backend User. |
|
41 | - * |
|
42 | - * @return BackendUserAuthentication |
|
43 | - */ |
|
44 | - protected function getBackendUser() |
|
45 | - { |
|
46 | - return $GLOBALS['BE_USER']; |
|
47 | - } |
|
39 | + /** |
|
40 | + * Returns an instance of the current Backend User. |
|
41 | + * |
|
42 | + * @return BackendUserAuthentication |
|
43 | + */ |
|
44 | + protected function getBackendUser() |
|
45 | + { |
|
46 | + return $GLOBALS['BE_USER']; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return ObjectManager |
|
51 | - * @throws \InvalidArgumentException |
|
52 | - */ |
|
53 | - protected function getObjectManager() |
|
54 | - { |
|
55 | - return GeneralUtility::makeInstance(ObjectManager::class); |
|
56 | - } |
|
49 | + /** |
|
50 | + * @return ObjectManager |
|
51 | + * @throws \InvalidArgumentException |
|
52 | + */ |
|
53 | + protected function getObjectManager() |
|
54 | + { |
|
55 | + return GeneralUtility::makeInstance(ObjectManager::class); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get the Vidi Module Loader. |
|
60 | - * |
|
61 | - * @return ModuleLoader |
|
62 | - * @throws \InvalidArgumentException |
|
63 | - */ |
|
64 | - protected function getModuleLoader() |
|
65 | - { |
|
66 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
67 | - } |
|
58 | + /** |
|
59 | + * Get the Vidi Module Loader. |
|
60 | + * |
|
61 | + * @return ModuleLoader |
|
62 | + * @throws \InvalidArgumentException |
|
63 | + */ |
|
64 | + protected function getModuleLoader() |
|
65 | + { |
|
66 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
@@ -22,125 +22,125 @@ |
||
22 | 22 | class ModulePreferencesTool extends AbstractTool |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Display the title of the tool on the welcome screen. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function getTitle() |
|
31 | - { |
|
32 | - return LocalizationUtility::translate( |
|
33 | - 'module_preferences_for', |
|
34 | - 'vidi', |
|
35 | - array(Tca::table($this->getModuleLoader()->getDataType())->getTitle()) |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Display the description of the tool in the welcome screen. |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function getDescription() |
|
45 | - { |
|
46 | - $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/Launcher.html'; |
|
47 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
48 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
49 | - return $view->render(); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Do the job! |
|
54 | - * |
|
55 | - * @param array $arguments |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function work(array $arguments = array()) |
|
59 | - { |
|
60 | - |
|
61 | - |
|
62 | - if (isset($arguments['save'])) { |
|
63 | - |
|
64 | - // Revert visible <-> excluded |
|
65 | - $excludedFields = array_diff( |
|
66 | - Tca::grid()->getAllFieldNames(), |
|
67 | - $arguments['excluded_fields'], |
|
68 | - $this->getExcludedFieldsFromTca() |
|
69 | - ); |
|
70 | - $arguments['excluded_fields'] = $excludedFields; |
|
71 | - $this->getModulePreferences()->save($arguments); |
|
72 | - } |
|
73 | - |
|
74 | - $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/WorkResult.html'; |
|
75 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
76 | - |
|
77 | - $view->assign('title', Tca::table($this->getModuleLoader()->getDataType())->getTitle()); |
|
78 | - |
|
79 | - // Fetch the menu of visible items. |
|
80 | - $menuVisibleItems = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS); |
|
81 | - $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS, $menuVisibleItems); |
|
82 | - |
|
83 | - // Fetch the default number of menu visible items. |
|
84 | - $menuDefaultVisible = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT); |
|
85 | - $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT, $menuDefaultVisible); |
|
86 | - |
|
87 | - // Get the visible columns |
|
88 | - $view->assign('columns', Tca::grid()->getAllFieldNames()); |
|
89 | - |
|
90 | - return $view->render(); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - protected function getExcludedFieldsFromTca() |
|
97 | - { |
|
98 | - $tca = Tca::grid()->getTca(); |
|
99 | - $excludedFields = []; |
|
100 | - if (!empty($tca['excluded_fields'])) { |
|
101 | - $excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], true); |
|
102 | - } elseif (!empty($tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
103 | - $excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], true); |
|
104 | - } |
|
105 | - return $excludedFields; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Tell whether the tools should be displayed according to the context. |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isShown() |
|
114 | - { |
|
115 | - return $this->getBackendUser()->isAdmin(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Get the Vidi Module Loader. |
|
120 | - * |
|
121 | - * @return ModuleLoader|object |
|
122 | - */ |
|
123 | - protected function getModuleLoader() |
|
124 | - { |
|
125 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @return ModulePreferences|object |
|
130 | - */ |
|
131 | - protected function getModulePreferences() |
|
132 | - { |
|
133 | - return GeneralUtility::makeInstance(ModulePreferences::class); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Get the Vidi Module Loader. |
|
138 | - * |
|
139 | - * @return GridAnalyserService|object |
|
140 | - */ |
|
141 | - protected function getGridAnalyserService() |
|
142 | - { |
|
143 | - return GeneralUtility::makeInstance(GridAnalyserService::class); |
|
144 | - } |
|
25 | + /** |
|
26 | + * Display the title of the tool on the welcome screen. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function getTitle() |
|
31 | + { |
|
32 | + return LocalizationUtility::translate( |
|
33 | + 'module_preferences_for', |
|
34 | + 'vidi', |
|
35 | + array(Tca::table($this->getModuleLoader()->getDataType())->getTitle()) |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Display the description of the tool in the welcome screen. |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function getDescription() |
|
45 | + { |
|
46 | + $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/Launcher.html'; |
|
47 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
48 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
49 | + return $view->render(); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Do the job! |
|
54 | + * |
|
55 | + * @param array $arguments |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function work(array $arguments = array()) |
|
59 | + { |
|
60 | + |
|
61 | + |
|
62 | + if (isset($arguments['save'])) { |
|
63 | + |
|
64 | + // Revert visible <-> excluded |
|
65 | + $excludedFields = array_diff( |
|
66 | + Tca::grid()->getAllFieldNames(), |
|
67 | + $arguments['excluded_fields'], |
|
68 | + $this->getExcludedFieldsFromTca() |
|
69 | + ); |
|
70 | + $arguments['excluded_fields'] = $excludedFields; |
|
71 | + $this->getModulePreferences()->save($arguments); |
|
72 | + } |
|
73 | + |
|
74 | + $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/WorkResult.html'; |
|
75 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
76 | + |
|
77 | + $view->assign('title', Tca::table($this->getModuleLoader()->getDataType())->getTitle()); |
|
78 | + |
|
79 | + // Fetch the menu of visible items. |
|
80 | + $menuVisibleItems = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS); |
|
81 | + $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS, $menuVisibleItems); |
|
82 | + |
|
83 | + // Fetch the default number of menu visible items. |
|
84 | + $menuDefaultVisible = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT); |
|
85 | + $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT, $menuDefaultVisible); |
|
86 | + |
|
87 | + // Get the visible columns |
|
88 | + $view->assign('columns', Tca::grid()->getAllFieldNames()); |
|
89 | + |
|
90 | + return $view->render(); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + protected function getExcludedFieldsFromTca() |
|
97 | + { |
|
98 | + $tca = Tca::grid()->getTca(); |
|
99 | + $excludedFields = []; |
|
100 | + if (!empty($tca['excluded_fields'])) { |
|
101 | + $excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], true); |
|
102 | + } elseif (!empty($tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
103 | + $excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], true); |
|
104 | + } |
|
105 | + return $excludedFields; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Tell whether the tools should be displayed according to the context. |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isShown() |
|
114 | + { |
|
115 | + return $this->getBackendUser()->isAdmin(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Get the Vidi Module Loader. |
|
120 | + * |
|
121 | + * @return ModuleLoader|object |
|
122 | + */ |
|
123 | + protected function getModuleLoader() |
|
124 | + { |
|
125 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @return ModulePreferences|object |
|
130 | + */ |
|
131 | + protected function getModulePreferences() |
|
132 | + { |
|
133 | + return GeneralUtility::makeInstance(ModulePreferences::class); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Get the Vidi Module Loader. |
|
138 | + * |
|
139 | + * @return GridAnalyserService|object |
|
140 | + */ |
|
141 | + protected function getGridAnalyserService() |
|
142 | + { |
|
143 | + return GeneralUtility::makeInstance(GridAnalyserService::class); |
|
144 | + } |
|
145 | 145 | } |
146 | 146 |
@@ -19,77 +19,77 @@ |
||
19 | 19 | class ConfiguredPidTool extends AbstractTool |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Display the title of the tool on the welcome screen. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function getTitle(): string |
|
28 | - { |
|
29 | - return sprintf('%s (%s)', |
|
30 | - LocalizationUtility::translate('tool.configured_pid', 'vidi'), |
|
31 | - $this->getModulePidService()->getConfiguredNewRecordPid() |
|
32 | - ); |
|
33 | - } |
|
22 | + /** |
|
23 | + * Display the title of the tool on the welcome screen. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function getTitle(): string |
|
28 | + { |
|
29 | + return sprintf('%s (%s)', |
|
30 | + LocalizationUtility::translate('tool.configured_pid', 'vidi'), |
|
31 | + $this->getModulePidService()->getConfiguredNewRecordPid() |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Display the description of the tool in the welcome screen. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getDescription(): string |
|
41 | - { |
|
42 | - $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ConfiguredPid/Launcher.html'; |
|
43 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
44 | - $view->assignMultiple([ |
|
45 | - 'sitePath' => Environment::getPublicPath() . '/', |
|
46 | - 'dataType' => $this->getModuleLoader()->getDataType(), |
|
47 | - 'configuredPid' => $this->getModulePidService()->getConfiguredNewRecordPid(), |
|
48 | - 'errors' => $this->getModulePidService()->validateConfiguredPid(), |
|
49 | - ]); |
|
35 | + /** |
|
36 | + * Display the description of the tool in the welcome screen. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getDescription(): string |
|
41 | + { |
|
42 | + $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ConfiguredPid/Launcher.html'; |
|
43 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
44 | + $view->assignMultiple([ |
|
45 | + 'sitePath' => Environment::getPublicPath() . '/', |
|
46 | + 'dataType' => $this->getModuleLoader()->getDataType(), |
|
47 | + 'configuredPid' => $this->getModulePidService()->getConfiguredNewRecordPid(), |
|
48 | + 'errors' => $this->getModulePidService()->validateConfiguredPid(), |
|
49 | + ]); |
|
50 | 50 | |
51 | - return $view->render(); |
|
52 | - } |
|
51 | + return $view->render(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Do the job |
|
56 | - * |
|
57 | - * @param array $arguments |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function work(array $arguments = array()): string |
|
61 | - { |
|
62 | - return ''; |
|
63 | - } |
|
54 | + /** |
|
55 | + * Do the job |
|
56 | + * |
|
57 | + * @param array $arguments |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function work(array $arguments = array()): string |
|
61 | + { |
|
62 | + return ''; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Tell whether the tools should be displayed according to the context. |
|
67 | - * |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function isShown(): bool |
|
71 | - { |
|
72 | - return $this->getBackendUser()->isAdmin(); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Tell whether the tools should be displayed according to the context. |
|
67 | + * |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function isShown(): bool |
|
71 | + { |
|
72 | + return $this->getBackendUser()->isAdmin(); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get the Vidi Module Loader. |
|
77 | - * |
|
78 | - * @return ModuleLoader|object |
|
79 | - */ |
|
80 | - protected function getModuleLoader(): ModuleLoader |
|
81 | - { |
|
82 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
83 | - } |
|
75 | + /** |
|
76 | + * Get the Vidi Module Loader. |
|
77 | + * |
|
78 | + * @return ModuleLoader|object |
|
79 | + */ |
|
80 | + protected function getModuleLoader(): ModuleLoader |
|
81 | + { |
|
82 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return ModulePidService|object |
|
87 | - */ |
|
88 | - public function getModulePidService() |
|
89 | - { |
|
90 | - /** @var ModulePidService $modulePidService */ |
|
91 | - return GeneralUtility::makeInstance(ModulePidService::class); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @return ModulePidService|object |
|
87 | + */ |
|
88 | + public function getModulePidService() |
|
89 | + { |
|
90 | + /** @var ModulePidService $modulePidService */ |
|
91 | + return GeneralUtility::makeInstance(ModulePidService::class); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
95 | 95 |
@@ -24,708 +24,708 @@ |
||
24 | 24 | class GridService extends AbstractTca |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $tca; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $tableName; |
|
36 | - |
|
37 | - /** |
|
38 | - * All fields available in the Grid. |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected $fields; |
|
43 | - |
|
44 | - /** |
|
45 | - * All fields regardless whether they have been excluded or not. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $allFields; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $instances; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $facets; |
|
60 | - |
|
61 | - /** |
|
62 | - * __construct |
|
63 | - * |
|
64 | - * @param string $tableName |
|
65 | - */ |
|
66 | - public function __construct($tableName) |
|
67 | - { |
|
68 | - |
|
69 | - $this->tableName = $tableName; |
|
70 | - |
|
71 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
72 | - throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
73 | - } |
|
74 | - |
|
75 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns an array containing column names. |
|
80 | - * |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - public function getFieldNames(): array |
|
84 | - { |
|
85 | - $fields = $this->getFields(); |
|
86 | - return array_keys($fields) ?: []; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Returns an array containing column names. |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getAllFieldNames(): array |
|
95 | - { |
|
96 | - $allFields = $this->getAllFields(); |
|
97 | - return array_keys($allFields); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Get the label key. |
|
102 | - * |
|
103 | - * @param string $fieldNameAndPath |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function getLabelKey($fieldNameAndPath): string |
|
107 | - { |
|
108 | - |
|
109 | - $field = $this->getField($fieldNameAndPath); |
|
110 | - |
|
111 | - // First option is to get the label from the Grid TCA. |
|
112 | - $rawLabel = ''; |
|
113 | - if (isset($field['label'])) { |
|
114 | - $rawLabel = $field['label']; |
|
115 | - } |
|
116 | - |
|
117 | - // Second option is to fetch the label from the Column Renderer object. |
|
118 | - if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
119 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
120 | - /** @var $renderer ColumnRendererInterface */ |
|
121 | - foreach ($renderers as $renderer) { |
|
122 | - if (isset($renderer['label'])) { |
|
123 | - $rawLabel = $renderer['label']; |
|
124 | - break; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - return $rawLabel; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get the translation of a label given a column name. |
|
133 | - * |
|
134 | - * @param string $fieldNameAndPath |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function getLabel($fieldNameAndPath) |
|
138 | - { |
|
139 | - $label = ''; |
|
140 | - if ($this->hasLabel($fieldNameAndPath)) { |
|
141 | - $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
142 | - try { |
|
143 | - $label = $this->getLanguageService()->sL($labelKey); |
|
144 | - } catch (\InvalidArgumentException $e) { |
|
145 | - } |
|
146 | - if (empty($label)) { |
|
147 | - $label = $labelKey; |
|
148 | - } |
|
149 | - } else { |
|
150 | - |
|
151 | - // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
152 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
153 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
154 | - $table = Tca::table($dataType); |
|
155 | - |
|
156 | - if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
157 | - $label = $table->field($fieldName)->getLabel(); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - return $label; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Returns the field name given its position. |
|
166 | - * |
|
167 | - * @param string $position the position of the field in the grid |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function getFieldNameByPosition($position): string |
|
171 | - { |
|
172 | - $fields = array_keys($this->getFields()); |
|
173 | - if (empty($fields[$position])) { |
|
174 | - throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
175 | - } |
|
176 | - |
|
177 | - return (string)$fields[$position]; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns a field name. |
|
182 | - * |
|
183 | - * @param string $fieldName |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function getField($fieldName): array |
|
187 | - { |
|
188 | - $fields = $this->getFields(); |
|
189 | - return $fields[$fieldName] ?: []; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Returns an array containing column names for the Grid. |
|
194 | - * |
|
195 | - * @return array |
|
196 | - */ |
|
197 | - public function getFields(): array |
|
198 | - { |
|
199 | - // Cache this operation since it can take some time. |
|
200 | - if ($this->fields === null) { |
|
201 | - |
|
202 | - // Fetch all available fields first. |
|
203 | - $fields = $this->getAllFields(); |
|
204 | - |
|
205 | - if ($this->isBackendMode()) { |
|
206 | - |
|
207 | - // Then remove the not allowed. |
|
208 | - $fields = $this->filterByIncludedFields($fields); |
|
209 | - $fields = $this->filterByBackendUser($fields); |
|
210 | - $fields = $this->filterByExcludedFields($fields); |
|
211 | - } |
|
212 | - |
|
213 | - $this->fields = $fields; |
|
214 | - } |
|
215 | - |
|
216 | - return $this->fields; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Remove fields according to Grid configuration. |
|
221 | - * |
|
222 | - * @param $fields |
|
223 | - * @return array |
|
224 | - */ |
|
225 | - protected function filterByIncludedFields($fields): array |
|
226 | - { |
|
227 | - |
|
228 | - $filteredFields = $fields; |
|
229 | - $includedFields = $this->getIncludedFields(); |
|
230 | - if (count($includedFields) > 0) { |
|
231 | - $filteredFields = []; |
|
232 | - foreach ($fields as $fieldNameAndPath => $configuration) { |
|
233 | - if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
234 | - $filteredFields[$fieldNameAndPath] = $configuration; |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - return $filteredFields; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Remove fields according to BE User permission. |
|
243 | - * |
|
244 | - * @param $fields |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - protected function filterByBackendUser($fields): array |
|
248 | - { |
|
249 | - if (!$this->getBackendUser()->isAdmin()) { |
|
250 | - foreach ($fields as $fieldName => $field) { |
|
251 | - if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
252 | - unset($fields[$fieldName]); |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - return $fields; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Remove fields according to Grid configuration. |
|
261 | - * |
|
262 | - * @param $fields |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - protected function filterByExcludedFields($fields): array |
|
266 | - { |
|
267 | - |
|
268 | - // Unset excluded fields. |
|
269 | - foreach ($this->getExcludedFields() as $excludedField) { |
|
270 | - if (isset($fields[$excludedField])) { |
|
271 | - unset($fields[$excludedField]); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - return $fields; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns an array containing column names for the Grid. |
|
280 | - * |
|
281 | - * @return array |
|
282 | - */ |
|
283 | - public function getAllFields(): array |
|
284 | - { |
|
285 | - |
|
286 | - // Cache this operation since it can take some time. |
|
287 | - if ($this->allFields === null) { |
|
288 | - |
|
289 | - $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
290 | - $gridFieldNames = array_keys($fields); |
|
291 | - |
|
292 | - // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
293 | - $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
294 | - |
|
295 | - // Just remove system fields from the Grid. |
|
296 | - foreach ($tableFieldNames as $key => $fieldName) { |
|
297 | - if (in_array($fieldName, Tca::getSystemFields())) { |
|
298 | - unset($tableFieldNames[$key]); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
303 | - |
|
304 | - if (!empty($additionalFields)) { |
|
305 | - |
|
306 | - // Pop out last element of the key |
|
307 | - // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
308 | - end($fields); |
|
309 | - $lastColumnKey = key($fields); |
|
310 | - $lastColumn = array_pop($fields); |
|
311 | - |
|
312 | - // Feed up the grid fields with un configured elements |
|
313 | - foreach ($additionalFields as $additionalField) { |
|
314 | - $fields[$additionalField] = array( |
|
315 | - 'visible' => false |
|
316 | - ); |
|
317 | - |
|
318 | - // Try to guess the format of the field. |
|
319 | - $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
320 | - if ($fieldType === FieldType::DATE) { |
|
321 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
322 | - } elseif ($fieldType === FieldType::DATETIME) { |
|
323 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
324 | - } |
|
325 | - } |
|
326 | - $fields[$lastColumnKey] = $lastColumn; |
|
327 | - } |
|
328 | - |
|
329 | - $this->allFields = $fields; |
|
330 | - } |
|
331 | - |
|
332 | - return $this->allFields; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Tell whether the field exists in the grid or not. |
|
337 | - * |
|
338 | - * @param string $fieldName |
|
339 | - * @return bool |
|
340 | - */ |
|
341 | - public function hasField($fieldName): bool |
|
342 | - { |
|
343 | - $fields = $this->getFields(); |
|
344 | - return isset($fields[$fieldName]); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Tell whether the facet exists in the grid or not. |
|
349 | - * |
|
350 | - * @param string $facetName |
|
351 | - * @return bool |
|
352 | - */ |
|
353 | - public function hasFacet($facetName): bool |
|
354 | - { |
|
355 | - $facets = $this->getFacets(); |
|
356 | - return isset($facets[$facetName]); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Returns an array containing facets fields. |
|
361 | - * |
|
362 | - * @return FacetInterface[] |
|
363 | - */ |
|
364 | - public function getFacets(): array |
|
365 | - { |
|
366 | - if ($this->facets === null) { |
|
367 | - $this->facets = []; |
|
368 | - |
|
369 | - if (is_array($this->tca['facets'])) { |
|
370 | - foreach ($this->tca['facets'] as $key => $facetNameOrArray) { |
|
371 | - if (is_array($facetNameOrArray)) { |
|
372 | - |
|
373 | - $name = $facetNameOrArray['name'] ?? ''; |
|
374 | - |
|
375 | - $label = isset($facetNameOrArray['label']) |
|
376 | - ? $this->getLanguageService()->sL($facetNameOrArray['label']) |
|
377 | - : ''; |
|
378 | - |
|
379 | - $suggestions = $facetNameOrArray['suggestions'] ?? []; |
|
380 | - $configuration = $facetNameOrArray['configuration'] ?? []; |
|
381 | - |
|
382 | - /** @var FacetInterface $facetObject */ |
|
383 | - $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration); |
|
384 | - $this->facets[$facetObject->getName()] = $facetObject; |
|
385 | - } else { |
|
386 | - $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray); |
|
387 | - } |
|
388 | - } |
|
389 | - } |
|
390 | - } |
|
391 | - return $this->facets; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Returns the "sortable" value of the column. |
|
396 | - * |
|
397 | - * @param string $fieldName |
|
398 | - * @return int|string |
|
399 | - */ |
|
400 | - public function isSortable($fieldName) |
|
401 | - { |
|
402 | - $defaultValue = true; |
|
403 | - $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
404 | - if ($hasSortableField) { |
|
405 | - $isSortable = false; |
|
406 | - } else { |
|
407 | - $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
408 | - } |
|
409 | - return $isSortable; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Returns the "canBeHidden" value of the column. |
|
414 | - * |
|
415 | - * @param string $fieldName |
|
416 | - * @return bool |
|
417 | - */ |
|
418 | - public function canBeHidden($fieldName): bool |
|
419 | - { |
|
420 | - $defaultValue = true; |
|
421 | - return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Returns the "width" value of the column. |
|
426 | - * |
|
427 | - * @param string $fieldName |
|
428 | - * @return int|string |
|
429 | - */ |
|
430 | - public function getWidth($fieldName) |
|
431 | - { |
|
432 | - $defaultValue = 'auto'; |
|
433 | - return $this->get($fieldName, 'width', $defaultValue); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Returns the "visible" value of the column. |
|
438 | - * |
|
439 | - * @param string $fieldName |
|
440 | - * @return bool |
|
441 | - */ |
|
442 | - public function isVisible($fieldName): bool |
|
443 | - { |
|
444 | - $defaultValue = true; |
|
445 | - return $this->get($fieldName, 'visible', $defaultValue); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Returns the "editable" value of the column. |
|
450 | - * |
|
451 | - * @param string $columnName |
|
452 | - * @return bool |
|
453 | - */ |
|
454 | - public function isEditable($columnName): bool |
|
455 | - { |
|
456 | - $defaultValue = false; |
|
457 | - return $this->get($columnName, 'editable', $defaultValue); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Returns the "localized" value of the column. |
|
462 | - * |
|
463 | - * @param string $columnName |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function isLocalized($columnName): bool |
|
467 | - { |
|
468 | - $defaultValue = true; |
|
469 | - return $this->get($columnName, 'localized', $defaultValue); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * |
|
474 | - * Returns the "html" value of the column. |
|
475 | - * |
|
476 | - * @param string $fieldName |
|
477 | - * @return string |
|
478 | - */ |
|
479 | - public function getHeader($fieldName): string |
|
480 | - { |
|
481 | - $defaultValue = ''; |
|
482 | - return $this->get($fieldName, 'html', $defaultValue); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
487 | - * |
|
488 | - * @param string $fieldName |
|
489 | - * @param string $key |
|
490 | - * @param mixed $defaultValue |
|
491 | - * @return null|mixed |
|
492 | - */ |
|
493 | - public function get($fieldName, $key, $defaultValue = null) |
|
494 | - { |
|
495 | - $value = $defaultValue; |
|
496 | - |
|
497 | - $field = $this->getField($fieldName); |
|
498 | - if (isset($field[$key])) { |
|
499 | - $value = $field[$key]; |
|
500 | - } elseif ($this->hasRenderers($fieldName)) { |
|
501 | - $renderers = $this->getRenderers($fieldName); |
|
502 | - foreach ($renderers as $rendererConfiguration) { |
|
503 | - if (isset($rendererConfiguration[$key])) { |
|
504 | - $value = $rendererConfiguration[$key]; |
|
505 | - } |
|
506 | - } |
|
507 | - } |
|
508 | - return $value; |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns whether the column has a renderer. |
|
513 | - * |
|
514 | - * @param string $fieldName |
|
515 | - * @return bool |
|
516 | - */ |
|
517 | - public function hasRenderers($fieldName): bool |
|
518 | - { |
|
519 | - $field = $this->getField($fieldName); |
|
520 | - return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Returns a renderer. |
|
525 | - * |
|
526 | - * @param string $fieldName |
|
527 | - * @return array |
|
528 | - */ |
|
529 | - public function getRenderers($fieldName): array |
|
530 | - { |
|
531 | - $field = $this->getField($fieldName); |
|
532 | - $renderers = []; |
|
533 | - if (!empty($field['renderer'])) { |
|
534 | - $renderers = $this->convertRendererToArray($field['renderer'], $field); |
|
535 | - } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
536 | - foreach ($field['renderers'] as $renderer) { |
|
537 | - $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field); |
|
538 | - $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
539 | - } |
|
540 | - } |
|
541 | - |
|
542 | - return $renderers; |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * @param string $renderer |
|
547 | - * @return array |
|
548 | - */ |
|
549 | - protected function convertRendererToArray($renderer, array $field): array |
|
550 | - { |
|
551 | - $result = []; |
|
552 | - if (is_string($renderer)) { |
|
553 | - $configuration = empty($field['rendererConfiguration']) |
|
554 | - ? [] |
|
555 | - : $field['rendererConfiguration']; |
|
556 | - |
|
557 | - /** @var ColumnRendererInterface $rendererObject */ |
|
558 | - $rendererObject = GeneralUtility::makeInstance($renderer); |
|
559 | - |
|
560 | - $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration); |
|
561 | - // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7 |
|
562 | - } elseif ($renderer instanceof ColumnRendererInterface) { |
|
563 | - /** @var ColumnRendererInterface $renderer */ |
|
564 | - $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
565 | - } |
|
566 | - return $result; |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Returns the class names applied to a cell |
|
571 | - * |
|
572 | - * @param string $fieldName |
|
573 | - * @return bool |
|
574 | - */ |
|
575 | - public function getClass($fieldName): bool |
|
576 | - { |
|
577 | - $field = $this->getField($fieldName); |
|
578 | - return isset($field['class']) ? $field['class'] : ''; |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Returns whether the column has a label. |
|
583 | - * |
|
584 | - * @param string $fieldNameAndPath |
|
585 | - * @return bool |
|
586 | - */ |
|
587 | - public function hasLabel($fieldNameAndPath): bool |
|
588 | - { |
|
589 | - $field = $this->getField($fieldNameAndPath); |
|
590 | - |
|
591 | - $hasLabel = empty($field['label']) ? false : true; |
|
592 | - |
|
593 | - if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
594 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
595 | - /** @var $renderer ColumnRendererInterface */ |
|
596 | - foreach ($renderers as $renderer) { |
|
597 | - if (isset($renderer['label'])) { |
|
598 | - $hasLabel = true; |
|
599 | - break; |
|
600 | - } |
|
601 | - } |
|
602 | - } |
|
603 | - return $hasLabel; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * @return array |
|
608 | - */ |
|
609 | - public function getTca(): array |
|
610 | - { |
|
611 | - return $this->tca; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * @return array |
|
616 | - */ |
|
617 | - public function getIncludedFields(): array |
|
618 | - { |
|
619 | - return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Return excluded fields from configuration + preferences. |
|
624 | - * |
|
625 | - * @return array |
|
626 | - */ |
|
627 | - public function getExcludedFields(): array |
|
628 | - { |
|
629 | - $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
630 | - $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
631 | - |
|
632 | - return array_merge($configurationFields, $preferencesFields); |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Fetch excluded fields from configuration. |
|
637 | - * |
|
638 | - * @return array |
|
639 | - */ |
|
640 | - protected function getExcludedFieldsFromConfiguration(): array |
|
641 | - { |
|
642 | - $excludedFields = []; |
|
643 | - if (!empty($this->tca['excluded_fields'])) { |
|
644 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
645 | - } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
646 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
647 | - } |
|
648 | - return $excludedFields; |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Fetch excluded fields from preferences. |
|
654 | - * |
|
655 | - * @return array |
|
656 | - */ |
|
657 | - protected function getExcludedFieldsFromPreferences(): array |
|
658 | - { |
|
659 | - $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
660 | - return is_array($excludedFields) ? $excludedFields : []; |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * @return bool |
|
665 | - */ |
|
666 | - public function areFilesIncludedInExport(): bool |
|
667 | - { |
|
668 | - $isIncluded = true; |
|
669 | - |
|
670 | - if (isset($this->tca['export']['include_files'])) { |
|
671 | - $isIncluded = (bool)$this->tca['export']['include_files']; |
|
672 | - } |
|
673 | - return $isIncluded; |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Returns a "facet" service instance. |
|
678 | - * |
|
679 | - * @param string|FacetInterface $facetName |
|
680 | - * @return StandardFacet |
|
681 | - */ |
|
682 | - protected function instantiateStandardFacet($facetName): StandardFacet |
|
683 | - { |
|
684 | - $label = $this->getLabel($facetName); |
|
685 | - |
|
686 | - /** @var StandardFacet $facetName */ |
|
687 | - $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
|
688 | - |
|
689 | - if (!$facet instanceof StandardFacet) { |
|
690 | - throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
691 | - } |
|
692 | - return $facet; |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * Returns a "facet" service instance. |
|
697 | - * |
|
698 | - * @param string|FacetInterface $facetName |
|
699 | - * @return FacetInterface |
|
700 | - */ |
|
701 | - public function facet($facetName = ''): FacetInterface |
|
702 | - { |
|
703 | - $facets = $this->getFacets(); |
|
704 | - return $facets[$facetName]; |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * @return FieldPathResolver|object |
|
709 | - */ |
|
710 | - protected function getFieldPathResolver() |
|
711 | - { |
|
712 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * @return ModulePreferences|object |
|
717 | - */ |
|
718 | - protected function getModulePreferences() |
|
719 | - { |
|
720 | - return GeneralUtility::makeInstance(ModulePreferences::class); |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * @return LanguageService|object |
|
725 | - */ |
|
726 | - protected function getLanguageService() |
|
727 | - { |
|
728 | - return GeneralUtility::makeInstance(LanguageService::class); |
|
729 | - } |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $tca; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $tableName; |
|
36 | + |
|
37 | + /** |
|
38 | + * All fields available in the Grid. |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected $fields; |
|
43 | + |
|
44 | + /** |
|
45 | + * All fields regardless whether they have been excluded or not. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $allFields; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $instances; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $facets; |
|
60 | + |
|
61 | + /** |
|
62 | + * __construct |
|
63 | + * |
|
64 | + * @param string $tableName |
|
65 | + */ |
|
66 | + public function __construct($tableName) |
|
67 | + { |
|
68 | + |
|
69 | + $this->tableName = $tableName; |
|
70 | + |
|
71 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
72 | + throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
73 | + } |
|
74 | + |
|
75 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns an array containing column names. |
|
80 | + * |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + public function getFieldNames(): array |
|
84 | + { |
|
85 | + $fields = $this->getFields(); |
|
86 | + return array_keys($fields) ?: []; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Returns an array containing column names. |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getAllFieldNames(): array |
|
95 | + { |
|
96 | + $allFields = $this->getAllFields(); |
|
97 | + return array_keys($allFields); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Get the label key. |
|
102 | + * |
|
103 | + * @param string $fieldNameAndPath |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function getLabelKey($fieldNameAndPath): string |
|
107 | + { |
|
108 | + |
|
109 | + $field = $this->getField($fieldNameAndPath); |
|
110 | + |
|
111 | + // First option is to get the label from the Grid TCA. |
|
112 | + $rawLabel = ''; |
|
113 | + if (isset($field['label'])) { |
|
114 | + $rawLabel = $field['label']; |
|
115 | + } |
|
116 | + |
|
117 | + // Second option is to fetch the label from the Column Renderer object. |
|
118 | + if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
119 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
120 | + /** @var $renderer ColumnRendererInterface */ |
|
121 | + foreach ($renderers as $renderer) { |
|
122 | + if (isset($renderer['label'])) { |
|
123 | + $rawLabel = $renderer['label']; |
|
124 | + break; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + return $rawLabel; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get the translation of a label given a column name. |
|
133 | + * |
|
134 | + * @param string $fieldNameAndPath |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function getLabel($fieldNameAndPath) |
|
138 | + { |
|
139 | + $label = ''; |
|
140 | + if ($this->hasLabel($fieldNameAndPath)) { |
|
141 | + $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
142 | + try { |
|
143 | + $label = $this->getLanguageService()->sL($labelKey); |
|
144 | + } catch (\InvalidArgumentException $e) { |
|
145 | + } |
|
146 | + if (empty($label)) { |
|
147 | + $label = $labelKey; |
|
148 | + } |
|
149 | + } else { |
|
150 | + |
|
151 | + // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
152 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
153 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
154 | + $table = Tca::table($dataType); |
|
155 | + |
|
156 | + if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
157 | + $label = $table->field($fieldName)->getLabel(); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + return $label; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Returns the field name given its position. |
|
166 | + * |
|
167 | + * @param string $position the position of the field in the grid |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function getFieldNameByPosition($position): string |
|
171 | + { |
|
172 | + $fields = array_keys($this->getFields()); |
|
173 | + if (empty($fields[$position])) { |
|
174 | + throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
175 | + } |
|
176 | + |
|
177 | + return (string)$fields[$position]; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns a field name. |
|
182 | + * |
|
183 | + * @param string $fieldName |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function getField($fieldName): array |
|
187 | + { |
|
188 | + $fields = $this->getFields(); |
|
189 | + return $fields[$fieldName] ?: []; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Returns an array containing column names for the Grid. |
|
194 | + * |
|
195 | + * @return array |
|
196 | + */ |
|
197 | + public function getFields(): array |
|
198 | + { |
|
199 | + // Cache this operation since it can take some time. |
|
200 | + if ($this->fields === null) { |
|
201 | + |
|
202 | + // Fetch all available fields first. |
|
203 | + $fields = $this->getAllFields(); |
|
204 | + |
|
205 | + if ($this->isBackendMode()) { |
|
206 | + |
|
207 | + // Then remove the not allowed. |
|
208 | + $fields = $this->filterByIncludedFields($fields); |
|
209 | + $fields = $this->filterByBackendUser($fields); |
|
210 | + $fields = $this->filterByExcludedFields($fields); |
|
211 | + } |
|
212 | + |
|
213 | + $this->fields = $fields; |
|
214 | + } |
|
215 | + |
|
216 | + return $this->fields; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Remove fields according to Grid configuration. |
|
221 | + * |
|
222 | + * @param $fields |
|
223 | + * @return array |
|
224 | + */ |
|
225 | + protected function filterByIncludedFields($fields): array |
|
226 | + { |
|
227 | + |
|
228 | + $filteredFields = $fields; |
|
229 | + $includedFields = $this->getIncludedFields(); |
|
230 | + if (count($includedFields) > 0) { |
|
231 | + $filteredFields = []; |
|
232 | + foreach ($fields as $fieldNameAndPath => $configuration) { |
|
233 | + if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
234 | + $filteredFields[$fieldNameAndPath] = $configuration; |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + return $filteredFields; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Remove fields according to BE User permission. |
|
243 | + * |
|
244 | + * @param $fields |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + protected function filterByBackendUser($fields): array |
|
248 | + { |
|
249 | + if (!$this->getBackendUser()->isAdmin()) { |
|
250 | + foreach ($fields as $fieldName => $field) { |
|
251 | + if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
252 | + unset($fields[$fieldName]); |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + return $fields; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Remove fields according to Grid configuration. |
|
261 | + * |
|
262 | + * @param $fields |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + protected function filterByExcludedFields($fields): array |
|
266 | + { |
|
267 | + |
|
268 | + // Unset excluded fields. |
|
269 | + foreach ($this->getExcludedFields() as $excludedField) { |
|
270 | + if (isset($fields[$excludedField])) { |
|
271 | + unset($fields[$excludedField]); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + return $fields; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns an array containing column names for the Grid. |
|
280 | + * |
|
281 | + * @return array |
|
282 | + */ |
|
283 | + public function getAllFields(): array |
|
284 | + { |
|
285 | + |
|
286 | + // Cache this operation since it can take some time. |
|
287 | + if ($this->allFields === null) { |
|
288 | + |
|
289 | + $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
290 | + $gridFieldNames = array_keys($fields); |
|
291 | + |
|
292 | + // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
293 | + $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
294 | + |
|
295 | + // Just remove system fields from the Grid. |
|
296 | + foreach ($tableFieldNames as $key => $fieldName) { |
|
297 | + if (in_array($fieldName, Tca::getSystemFields())) { |
|
298 | + unset($tableFieldNames[$key]); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
303 | + |
|
304 | + if (!empty($additionalFields)) { |
|
305 | + |
|
306 | + // Pop out last element of the key |
|
307 | + // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
308 | + end($fields); |
|
309 | + $lastColumnKey = key($fields); |
|
310 | + $lastColumn = array_pop($fields); |
|
311 | + |
|
312 | + // Feed up the grid fields with un configured elements |
|
313 | + foreach ($additionalFields as $additionalField) { |
|
314 | + $fields[$additionalField] = array( |
|
315 | + 'visible' => false |
|
316 | + ); |
|
317 | + |
|
318 | + // Try to guess the format of the field. |
|
319 | + $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
320 | + if ($fieldType === FieldType::DATE) { |
|
321 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
322 | + } elseif ($fieldType === FieldType::DATETIME) { |
|
323 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
324 | + } |
|
325 | + } |
|
326 | + $fields[$lastColumnKey] = $lastColumn; |
|
327 | + } |
|
328 | + |
|
329 | + $this->allFields = $fields; |
|
330 | + } |
|
331 | + |
|
332 | + return $this->allFields; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Tell whether the field exists in the grid or not. |
|
337 | + * |
|
338 | + * @param string $fieldName |
|
339 | + * @return bool |
|
340 | + */ |
|
341 | + public function hasField($fieldName): bool |
|
342 | + { |
|
343 | + $fields = $this->getFields(); |
|
344 | + return isset($fields[$fieldName]); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Tell whether the facet exists in the grid or not. |
|
349 | + * |
|
350 | + * @param string $facetName |
|
351 | + * @return bool |
|
352 | + */ |
|
353 | + public function hasFacet($facetName): bool |
|
354 | + { |
|
355 | + $facets = $this->getFacets(); |
|
356 | + return isset($facets[$facetName]); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Returns an array containing facets fields. |
|
361 | + * |
|
362 | + * @return FacetInterface[] |
|
363 | + */ |
|
364 | + public function getFacets(): array |
|
365 | + { |
|
366 | + if ($this->facets === null) { |
|
367 | + $this->facets = []; |
|
368 | + |
|
369 | + if (is_array($this->tca['facets'])) { |
|
370 | + foreach ($this->tca['facets'] as $key => $facetNameOrArray) { |
|
371 | + if (is_array($facetNameOrArray)) { |
|
372 | + |
|
373 | + $name = $facetNameOrArray['name'] ?? ''; |
|
374 | + |
|
375 | + $label = isset($facetNameOrArray['label']) |
|
376 | + ? $this->getLanguageService()->sL($facetNameOrArray['label']) |
|
377 | + : ''; |
|
378 | + |
|
379 | + $suggestions = $facetNameOrArray['suggestions'] ?? []; |
|
380 | + $configuration = $facetNameOrArray['configuration'] ?? []; |
|
381 | + |
|
382 | + /** @var FacetInterface $facetObject */ |
|
383 | + $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration); |
|
384 | + $this->facets[$facetObject->getName()] = $facetObject; |
|
385 | + } else { |
|
386 | + $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray); |
|
387 | + } |
|
388 | + } |
|
389 | + } |
|
390 | + } |
|
391 | + return $this->facets; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Returns the "sortable" value of the column. |
|
396 | + * |
|
397 | + * @param string $fieldName |
|
398 | + * @return int|string |
|
399 | + */ |
|
400 | + public function isSortable($fieldName) |
|
401 | + { |
|
402 | + $defaultValue = true; |
|
403 | + $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
404 | + if ($hasSortableField) { |
|
405 | + $isSortable = false; |
|
406 | + } else { |
|
407 | + $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
408 | + } |
|
409 | + return $isSortable; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Returns the "canBeHidden" value of the column. |
|
414 | + * |
|
415 | + * @param string $fieldName |
|
416 | + * @return bool |
|
417 | + */ |
|
418 | + public function canBeHidden($fieldName): bool |
|
419 | + { |
|
420 | + $defaultValue = true; |
|
421 | + return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Returns the "width" value of the column. |
|
426 | + * |
|
427 | + * @param string $fieldName |
|
428 | + * @return int|string |
|
429 | + */ |
|
430 | + public function getWidth($fieldName) |
|
431 | + { |
|
432 | + $defaultValue = 'auto'; |
|
433 | + return $this->get($fieldName, 'width', $defaultValue); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Returns the "visible" value of the column. |
|
438 | + * |
|
439 | + * @param string $fieldName |
|
440 | + * @return bool |
|
441 | + */ |
|
442 | + public function isVisible($fieldName): bool |
|
443 | + { |
|
444 | + $defaultValue = true; |
|
445 | + return $this->get($fieldName, 'visible', $defaultValue); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Returns the "editable" value of the column. |
|
450 | + * |
|
451 | + * @param string $columnName |
|
452 | + * @return bool |
|
453 | + */ |
|
454 | + public function isEditable($columnName): bool |
|
455 | + { |
|
456 | + $defaultValue = false; |
|
457 | + return $this->get($columnName, 'editable', $defaultValue); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Returns the "localized" value of the column. |
|
462 | + * |
|
463 | + * @param string $columnName |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function isLocalized($columnName): bool |
|
467 | + { |
|
468 | + $defaultValue = true; |
|
469 | + return $this->get($columnName, 'localized', $defaultValue); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * |
|
474 | + * Returns the "html" value of the column. |
|
475 | + * |
|
476 | + * @param string $fieldName |
|
477 | + * @return string |
|
478 | + */ |
|
479 | + public function getHeader($fieldName): string |
|
480 | + { |
|
481 | + $defaultValue = ''; |
|
482 | + return $this->get($fieldName, 'html', $defaultValue); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
487 | + * |
|
488 | + * @param string $fieldName |
|
489 | + * @param string $key |
|
490 | + * @param mixed $defaultValue |
|
491 | + * @return null|mixed |
|
492 | + */ |
|
493 | + public function get($fieldName, $key, $defaultValue = null) |
|
494 | + { |
|
495 | + $value = $defaultValue; |
|
496 | + |
|
497 | + $field = $this->getField($fieldName); |
|
498 | + if (isset($field[$key])) { |
|
499 | + $value = $field[$key]; |
|
500 | + } elseif ($this->hasRenderers($fieldName)) { |
|
501 | + $renderers = $this->getRenderers($fieldName); |
|
502 | + foreach ($renderers as $rendererConfiguration) { |
|
503 | + if (isset($rendererConfiguration[$key])) { |
|
504 | + $value = $rendererConfiguration[$key]; |
|
505 | + } |
|
506 | + } |
|
507 | + } |
|
508 | + return $value; |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns whether the column has a renderer. |
|
513 | + * |
|
514 | + * @param string $fieldName |
|
515 | + * @return bool |
|
516 | + */ |
|
517 | + public function hasRenderers($fieldName): bool |
|
518 | + { |
|
519 | + $field = $this->getField($fieldName); |
|
520 | + return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Returns a renderer. |
|
525 | + * |
|
526 | + * @param string $fieldName |
|
527 | + * @return array |
|
528 | + */ |
|
529 | + public function getRenderers($fieldName): array |
|
530 | + { |
|
531 | + $field = $this->getField($fieldName); |
|
532 | + $renderers = []; |
|
533 | + if (!empty($field['renderer'])) { |
|
534 | + $renderers = $this->convertRendererToArray($field['renderer'], $field); |
|
535 | + } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
536 | + foreach ($field['renderers'] as $renderer) { |
|
537 | + $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field); |
|
538 | + $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
539 | + } |
|
540 | + } |
|
541 | + |
|
542 | + return $renderers; |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * @param string $renderer |
|
547 | + * @return array |
|
548 | + */ |
|
549 | + protected function convertRendererToArray($renderer, array $field): array |
|
550 | + { |
|
551 | + $result = []; |
|
552 | + if (is_string($renderer)) { |
|
553 | + $configuration = empty($field['rendererConfiguration']) |
|
554 | + ? [] |
|
555 | + : $field['rendererConfiguration']; |
|
556 | + |
|
557 | + /** @var ColumnRendererInterface $rendererObject */ |
|
558 | + $rendererObject = GeneralUtility::makeInstance($renderer); |
|
559 | + |
|
560 | + $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration); |
|
561 | + // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7 |
|
562 | + } elseif ($renderer instanceof ColumnRendererInterface) { |
|
563 | + /** @var ColumnRendererInterface $renderer */ |
|
564 | + $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
565 | + } |
|
566 | + return $result; |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Returns the class names applied to a cell |
|
571 | + * |
|
572 | + * @param string $fieldName |
|
573 | + * @return bool |
|
574 | + */ |
|
575 | + public function getClass($fieldName): bool |
|
576 | + { |
|
577 | + $field = $this->getField($fieldName); |
|
578 | + return isset($field['class']) ? $field['class'] : ''; |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Returns whether the column has a label. |
|
583 | + * |
|
584 | + * @param string $fieldNameAndPath |
|
585 | + * @return bool |
|
586 | + */ |
|
587 | + public function hasLabel($fieldNameAndPath): bool |
|
588 | + { |
|
589 | + $field = $this->getField($fieldNameAndPath); |
|
590 | + |
|
591 | + $hasLabel = empty($field['label']) ? false : true; |
|
592 | + |
|
593 | + if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
594 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
595 | + /** @var $renderer ColumnRendererInterface */ |
|
596 | + foreach ($renderers as $renderer) { |
|
597 | + if (isset($renderer['label'])) { |
|
598 | + $hasLabel = true; |
|
599 | + break; |
|
600 | + } |
|
601 | + } |
|
602 | + } |
|
603 | + return $hasLabel; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * @return array |
|
608 | + */ |
|
609 | + public function getTca(): array |
|
610 | + { |
|
611 | + return $this->tca; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * @return array |
|
616 | + */ |
|
617 | + public function getIncludedFields(): array |
|
618 | + { |
|
619 | + return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * Return excluded fields from configuration + preferences. |
|
624 | + * |
|
625 | + * @return array |
|
626 | + */ |
|
627 | + public function getExcludedFields(): array |
|
628 | + { |
|
629 | + $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
630 | + $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
631 | + |
|
632 | + return array_merge($configurationFields, $preferencesFields); |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Fetch excluded fields from configuration. |
|
637 | + * |
|
638 | + * @return array |
|
639 | + */ |
|
640 | + protected function getExcludedFieldsFromConfiguration(): array |
|
641 | + { |
|
642 | + $excludedFields = []; |
|
643 | + if (!empty($this->tca['excluded_fields'])) { |
|
644 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
645 | + } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
646 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
647 | + } |
|
648 | + return $excludedFields; |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Fetch excluded fields from preferences. |
|
654 | + * |
|
655 | + * @return array |
|
656 | + */ |
|
657 | + protected function getExcludedFieldsFromPreferences(): array |
|
658 | + { |
|
659 | + $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
660 | + return is_array($excludedFields) ? $excludedFields : []; |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * @return bool |
|
665 | + */ |
|
666 | + public function areFilesIncludedInExport(): bool |
|
667 | + { |
|
668 | + $isIncluded = true; |
|
669 | + |
|
670 | + if (isset($this->tca['export']['include_files'])) { |
|
671 | + $isIncluded = (bool)$this->tca['export']['include_files']; |
|
672 | + } |
|
673 | + return $isIncluded; |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Returns a "facet" service instance. |
|
678 | + * |
|
679 | + * @param string|FacetInterface $facetName |
|
680 | + * @return StandardFacet |
|
681 | + */ |
|
682 | + protected function instantiateStandardFacet($facetName): StandardFacet |
|
683 | + { |
|
684 | + $label = $this->getLabel($facetName); |
|
685 | + |
|
686 | + /** @var StandardFacet $facetName */ |
|
687 | + $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
|
688 | + |
|
689 | + if (!$facet instanceof StandardFacet) { |
|
690 | + throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
691 | + } |
|
692 | + return $facet; |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * Returns a "facet" service instance. |
|
697 | + * |
|
698 | + * @param string|FacetInterface $facetName |
|
699 | + * @return FacetInterface |
|
700 | + */ |
|
701 | + public function facet($facetName = ''): FacetInterface |
|
702 | + { |
|
703 | + $facets = $this->getFacets(); |
|
704 | + return $facets[$facetName]; |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * @return FieldPathResolver|object |
|
709 | + */ |
|
710 | + protected function getFieldPathResolver() |
|
711 | + { |
|
712 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * @return ModulePreferences|object |
|
717 | + */ |
|
718 | + protected function getModulePreferences() |
|
719 | + { |
|
720 | + return GeneralUtility::makeInstance(ModulePreferences::class); |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * @return LanguageService|object |
|
725 | + */ |
|
726 | + protected function getLanguageService() |
|
727 | + { |
|
728 | + return GeneralUtility::makeInstance(LanguageService::class); |
|
729 | + } |
|
730 | 730 | |
731 | 731 | } |
@@ -17,777 +17,777 @@ |
||
17 | 17 | class FieldService extends AbstractTca |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $fieldName; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $compositeField; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $tableName; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $tca; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param string $fieldName |
|
42 | - * @param array $tca |
|
43 | - * @param string $tableName |
|
44 | - * @param string $compositeField |
|
45 | - * @return \Fab\Vidi\Tca\FieldService |
|
46 | - */ |
|
47 | - public function __construct($fieldName, array $tca, $tableName, $compositeField = '') |
|
48 | - { |
|
49 | - $this->fieldName = $fieldName; |
|
50 | - $this->tca = $tca; |
|
51 | - $this->tableName = $tableName; |
|
52 | - $this->compositeField = $compositeField; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc... |
|
57 | - * |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function isSystem() |
|
61 | - { |
|
62 | - return in_array($this->fieldName, Tca::getSystemFields()); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Tells the opposition of isSystem() |
|
67 | - * |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function isNotSystem() |
|
71 | - { |
|
72 | - return !$this->isSystem(); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Returns the configuration for a $field |
|
77 | - * |
|
78 | - * @throws \Exception |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function getConfiguration() |
|
82 | - { |
|
83 | - return empty($this->tca['config']) ? [] : $this->tca['config']; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Returns a key of the configuration. |
|
88 | - * If the key can not to be found, returns null. |
|
89 | - * |
|
90 | - * @param string $key |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - public function get($key) |
|
94 | - { |
|
95 | - $configuration = $this->getConfiguration(); |
|
96 | - return empty($configuration[$key]) ? null : $configuration[$key]; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns the foreign field of a given field (opposite relational field). |
|
101 | - * If no relation exists, returns null. |
|
102 | - * |
|
103 | - * @return string|null |
|
104 | - */ |
|
105 | - public function getForeignField() |
|
106 | - { |
|
107 | - $result = null; |
|
108 | - $configuration = $this->getConfiguration(); |
|
109 | - |
|
110 | - if (!empty($configuration['foreign_field'])) { |
|
111 | - $result = $configuration['foreign_field']; |
|
112 | - } elseif ($this->hasRelationManyToMany()) { |
|
113 | - |
|
114 | - $foreignTable = $this->getForeignTable(); |
|
115 | - $manyToManyTable = $this->getManyToManyTable(); |
|
116 | - |
|
117 | - // Load TCA service of foreign field. |
|
118 | - $tcaForeignTableService = Tca::table($foreignTable); |
|
119 | - |
|
120 | - // Look into the MM relations checking for the opposite field |
|
121 | - foreach ($tcaForeignTableService->getFields() as $fieldName) { |
|
122 | - if ($manyToManyTable == $tcaForeignTableService->field($fieldName)->getManyToManyTable()) { |
|
123 | - $result = $fieldName; |
|
124 | - break; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - return $result; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Returns the foreign table of a given field (opposite relational table). |
|
133 | - * If no relation exists, returns null. |
|
134 | - * |
|
135 | - * @return string|null |
|
136 | - */ |
|
137 | - public function getForeignTable() |
|
138 | - { |
|
139 | - $result = null; |
|
140 | - $configuration = $this->getConfiguration(); |
|
141 | - |
|
142 | - if (!empty($configuration['foreign_table'])) { |
|
143 | - $result = $configuration['foreign_table']; |
|
144 | - } elseif ($this->isGroup()) { |
|
145 | - $fieldParts = explode('.', $this->compositeField, 2); |
|
146 | - $result = $fieldParts[1]; |
|
147 | - } |
|
148 | - return $result; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Returns the foreign clause. |
|
153 | - * If no foreign order exists, returns empty string. |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function getForeignClause() |
|
158 | - { |
|
159 | - $result = ''; |
|
160 | - $configuration = $this->getConfiguration(); |
|
161 | - |
|
162 | - if (!empty($configuration['foreign_table_where'])) { |
|
163 | - $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
164 | - if (!empty($parts[0])) { |
|
165 | - $result = $parts[0]; |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - // Substitute some variables |
|
170 | - return $this->substituteKnownMarkers($result); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Substitute some known markers from the where clause in the Frontend Context. |
|
175 | - * |
|
176 | - * @param string $clause |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - protected function substituteKnownMarkers($clause) |
|
180 | - { |
|
181 | - if ($clause && $this->isFrontendMode()) { |
|
182 | - |
|
183 | - $searches = array( |
|
184 | - '###CURRENT_PID###', |
|
185 | - '###REC_FIELD_sys_language_uid###' |
|
186 | - ); |
|
187 | - |
|
188 | - $replaces = array( |
|
189 | - $this->getFrontendObject()->id, |
|
190 | - $this->getFrontendObject()->sys_language_uid, |
|
191 | - ); |
|
192 | - |
|
193 | - $clause = str_replace($searches, $replaces, $clause); |
|
194 | - } |
|
195 | - return $clause; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Returns the foreign order of the current field. |
|
200 | - * If no foreign order exists, returns empty string. |
|
201 | - * |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function getForeignOrder() |
|
205 | - { |
|
206 | - $result = ''; |
|
207 | - $configuration = $this->getConfiguration(); |
|
208 | - |
|
209 | - if (!empty($configuration['foreign_table_where'])) { |
|
210 | - $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
211 | - if (!empty($parts[1])) { |
|
212 | - $result = $parts[1]; |
|
213 | - } |
|
214 | - } |
|
215 | - return $result; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Returns the MM table of a field. |
|
220 | - * If no relation exists, returns null. |
|
221 | - * |
|
222 | - * @return string|null |
|
223 | - */ |
|
224 | - public function getManyToManyTable() |
|
225 | - { |
|
226 | - $configuration = $this->getConfiguration(); |
|
227 | - return empty($configuration['MM']) ? null : $configuration['MM']; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Returns a possible additional table name used in MM relations. |
|
232 | - * If no table name exists, returns null. |
|
233 | - * |
|
234 | - * @return string|null |
|
235 | - */ |
|
236 | - public function getAdditionalTableNameCondition() |
|
237 | - { |
|
238 | - $result = null; |
|
239 | - $configuration = $this->getConfiguration(); |
|
240 | - |
|
241 | - if (!empty($configuration['MM_match_fields']['tablenames'])) { |
|
242 | - $result = $configuration['MM_match_fields']['tablenames']; |
|
243 | - } elseif ($this->isGroup()) { |
|
244 | - |
|
245 | - // @todo check if $this->fieldName could be simply used as $result |
|
246 | - $fieldParts = explode('.', $this->compositeField, 2); |
|
247 | - $result = $fieldParts[1]; |
|
248 | - } |
|
249 | - |
|
250 | - return $result; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Returns a possible additional conditions for MM tables such as "tablenames", "fieldname", etc... |
|
255 | - * |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - public function getAdditionalMMCondition() |
|
259 | - { |
|
260 | - $additionalMMConditions = []; |
|
261 | - $configuration = $this->getConfiguration(); |
|
262 | - |
|
263 | - if (!empty($configuration['MM_match_fields'])) { |
|
264 | - $additionalMMConditions = $configuration['MM_match_fields']; |
|
265 | - } |
|
266 | - |
|
267 | - // Add in any case a table name for "group" |
|
268 | - if ($this->isGroup()) { |
|
269 | - |
|
270 | - // @todo check if $this->fieldName could be simply used as $result |
|
271 | - $fieldParts = explode('.', $this->compositeField, 2); |
|
272 | - $additionalMMConditions = array( |
|
273 | - 'tablenames' => $fieldParts[1], |
|
274 | - ); |
|
275 | - } |
|
276 | - return $additionalMMConditions; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Returns whether the field name is the opposite in MM relation. |
|
281 | - * |
|
282 | - * @return bool |
|
283 | - */ |
|
284 | - public function isOppositeRelation() |
|
285 | - { |
|
286 | - $configuration = $this->getConfiguration(); |
|
287 | - return isset($configuration['MM_opposite_field']); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Returns the configuration for a $field. |
|
292 | - * |
|
293 | - * @throws \Exception |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function getType() |
|
297 | - { |
|
298 | - |
|
299 | - if ($this->isSystem()) { |
|
300 | - $fieldType = FieldType::NUMBER; |
|
301 | - } else { |
|
302 | - $configuration = $this->getConfiguration(); |
|
303 | - |
|
304 | - if (empty($configuration['type'])) { |
|
305 | - throw new \Exception(sprintf('No field type found for "%s" in table "%s"', $this->fieldName, $this->tableName), 1385556627); |
|
306 | - } |
|
307 | - |
|
308 | - $fieldType = $configuration['type']; |
|
309 | - |
|
310 | - if ($configuration['type'] === FieldType::SELECT && !empty($configuration['size']) && $configuration['size'] > 1) { |
|
311 | - $fieldType = FieldType::MULTISELECT; |
|
312 | - } elseif (!empty($configuration['foreign_table']) |
|
313 | - && ($configuration['foreign_table'] == 'sys_file_reference' || $configuration['foreign_table'] == 'sys_file') |
|
314 | - ) { |
|
315 | - $fieldType = FieldType::FILE; |
|
316 | - } elseif (!empty($configuration['eval'])) { |
|
317 | - $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
318 | - if (in_array('datetime', $parts)) { |
|
319 | - $fieldType = FieldType::DATETIME; |
|
320 | - } elseif (in_array('date', $parts)) { |
|
321 | - $fieldType = FieldType::DATE; |
|
322 | - } elseif (in_array('email', $parts)) { |
|
323 | - $fieldType = FieldType::EMAIL; |
|
324 | - } elseif (in_array('int', $parts) || in_array('double2', $parts)) { |
|
325 | - $fieldType = FieldType::NUMBER; |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - // Do some legacy conversion |
|
330 | - if ($fieldType === 'input') { |
|
331 | - $fieldType = FieldType::TEXT; |
|
332 | - } elseif ($fieldType === 'text') { |
|
333 | - $fieldType = FieldType::TEXTAREA; |
|
334 | - } |
|
335 | - } |
|
336 | - return $fieldType; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Return the default value. |
|
341 | - * |
|
342 | - * @return bool |
|
343 | - */ |
|
344 | - public function getDefaultValue() |
|
345 | - { |
|
346 | - $configuration = $this->getConfiguration(); |
|
347 | - return isset($configuration['default']) ? $configuration['default'] : null; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Get the translation of a label given a column. |
|
352 | - * |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function getLabel() |
|
356 | - { |
|
357 | - $label = ''; |
|
358 | - if ($this->hasLabel()) { |
|
359 | - try { |
|
360 | - $label = LocalizationUtility::translate($this->tca['label'], ''); |
|
361 | - } catch (\InvalidArgumentException $e) { |
|
362 | - } |
|
363 | - if (empty($label)) { |
|
364 | - $label = $this->tca['label']; |
|
365 | - } |
|
366 | - } |
|
367 | - return $label; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Get the translation of a label given a column. |
|
372 | - * |
|
373 | - * @param string $itemValue the item value to search for. |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - public function getLabelForItem($itemValue) |
|
377 | - { |
|
378 | - |
|
379 | - // Early return whether there is nothing to be translated as label. |
|
380 | - if (is_null($itemValue)) { |
|
381 | - return ''; |
|
382 | - } elseif (is_string($itemValue) && $itemValue === '') { |
|
383 | - return $itemValue; |
|
384 | - } |
|
385 | - |
|
386 | - $configuration = $this->getConfiguration(); |
|
387 | - if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
388 | - foreach ($configuration['items'] as $item) { |
|
389 | - if ($item[1] == $itemValue) { |
|
390 | - try { |
|
391 | - $label = LocalizationUtility::translate($item[0], ''); |
|
392 | - } catch (\InvalidArgumentException $e) { |
|
393 | - } |
|
394 | - if (empty($label)) { |
|
395 | - $label = $item[0]; |
|
396 | - } |
|
397 | - break; |
|
398 | - } |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - // Try fetching a label from a possible itemsProcFunc |
|
403 | - if (!isset($label) && is_scalar($itemValue)) { |
|
404 | - $items = $this->fetchItemsFromUserFunction(); |
|
405 | - if (!empty($items[$itemValue])) { |
|
406 | - $label = $items[$itemValue]; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - // Returns a label if it has been found, otherwise returns the item value as fallback. |
|
411 | - return isset($label) ? $label : $itemValue; |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Retrieve items from User Function. |
|
416 | - * |
|
417 | - * @return array |
|
418 | - */ |
|
419 | - protected function fetchItemsFromUserFunction() |
|
420 | - { |
|
421 | - $values = []; |
|
422 | - |
|
423 | - $configuration = $this->getConfiguration(); |
|
424 | - if (!empty($configuration['itemsProcFunc'])) { |
|
425 | - $parts = explode('php:', $configuration['itemsProcFunc']); |
|
426 | - if (!empty($parts[1])) { |
|
427 | - |
|
428 | - list($class, $method) = explode('->', $parts[1]); |
|
429 | - |
|
430 | - $parameters['items'] = []; |
|
431 | - $object = GeneralUtility::makeInstance($class); |
|
432 | - $object->$method($parameters); |
|
433 | - |
|
434 | - foreach ($parameters['items'] as $items) { |
|
435 | - $values[$items[1]] = $items[0]; |
|
436 | - } |
|
437 | - } |
|
438 | - } |
|
439 | - return $values; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Get a possible icon given a field name an an item. |
|
444 | - * |
|
445 | - * @param string $itemValue the item value to search for. |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public function getIconForItem($itemValue) |
|
449 | - { |
|
450 | - $result = ''; |
|
451 | - $configuration = $this->getConfiguration(); |
|
452 | - if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
453 | - foreach ($configuration['items'] as $item) { |
|
454 | - if ($item[1] == $itemValue) { |
|
455 | - $result = empty($item[2]) ? '' : $item[2]; |
|
456 | - break; |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - return $result; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Returns whether the field has a label. |
|
465 | - * |
|
466 | - * @return bool |
|
467 | - */ |
|
468 | - public function hasLabel() |
|
469 | - { |
|
470 | - return empty($this->tca['label']) ? false : true; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Tell whether the current BE User has access to this field. |
|
475 | - * |
|
476 | - * @return bool |
|
477 | - */ |
|
478 | - public function hasAccess() |
|
479 | - { |
|
480 | - $hasAccess = true; |
|
481 | - if ($this->isBackendMode() |
|
482 | - && Tca::table($this->tableName)->hasAccess() |
|
483 | - && isset($this->tca['exclude']) |
|
484 | - && $this->tca['exclude'] |
|
485 | - ) { |
|
486 | - $hasAccess = $this->getBackendUser()->check('non_exclude_fields', $this->tableName . ':' . $this->fieldName); |
|
487 | - } |
|
488 | - return $hasAccess; |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Returns whether the field is numerical. |
|
493 | - * |
|
494 | - * @return bool |
|
495 | - */ |
|
496 | - public function isNumerical() |
|
497 | - { |
|
498 | - $result = $this->isSystem(); |
|
499 | - if ($result === false) { |
|
500 | - $configuration = $this->getConfiguration(); |
|
501 | - $parts = []; |
|
502 | - if (!empty($configuration['eval'])) { |
|
503 | - $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
504 | - } |
|
505 | - $result = in_array('int', $parts) || in_array('float', $parts); |
|
506 | - } |
|
507 | - return $result; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Returns whether the field is of type text area. |
|
512 | - * |
|
513 | - * @return bool |
|
514 | - */ |
|
515 | - public function isTextArea() |
|
516 | - { |
|
517 | - return $this->getType() === FieldType::TEXTAREA; |
|
518 | - } |
|
519 | - /** |
|
520 | - * Returns whether the field is of type text area. |
|
521 | - * |
|
522 | - * @return bool |
|
523 | - */ |
|
524 | - public function isText() |
|
525 | - { |
|
526 | - return $this->getType() === FieldType::TEXT; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Returns whether the field is displayed as a tree. |
|
531 | - * |
|
532 | - * @return bool |
|
533 | - */ |
|
534 | - public function isRenderModeTree() |
|
535 | - { |
|
536 | - $configuration = $this->getConfiguration(); |
|
537 | - return isset($configuration['renderMode']) && $configuration['renderMode'] == FieldType::TREE; |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * Returns whether the field is of type select. |
|
542 | - * |
|
543 | - * @return bool |
|
544 | - */ |
|
545 | - public function isSelect() |
|
546 | - { |
|
547 | - return $this->getType() === FieldType::SELECT; |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * Returns whether the field is of type select. |
|
552 | - * |
|
553 | - * @return bool |
|
554 | - */ |
|
555 | - public function isMultipleSelect() |
|
556 | - { |
|
557 | - return $this->getType() === FieldType::MULTISELECT; |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Returns whether the field is of type select. |
|
562 | - * |
|
563 | - * @return bool |
|
564 | - */ |
|
565 | - public function isCheckBox() |
|
566 | - { |
|
567 | - return $this->getType() === FieldType::CHECKBOX; |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Returns whether the field is of type db. |
|
572 | - * |
|
573 | - * @return bool |
|
574 | - */ |
|
575 | - public function isGroup() |
|
576 | - { |
|
577 | - return $this->getType() === 'group'; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Returns whether the field is language aware. |
|
582 | - * |
|
583 | - * @return bool |
|
584 | - */ |
|
585 | - public function isLocalized() |
|
586 | - { |
|
587 | - $isLocalized = false; |
|
588 | - if (isset($this->tca['l10n_mode'])) { |
|
589 | - |
|
590 | - if ($this->tca['l10n_mode'] == 'prefixLangTitle' || $this->tca['l10n_mode'] == 'mergeIfNotBlank') { |
|
591 | - $isLocalized = true; |
|
592 | - } |
|
593 | - } |
|
594 | - return $isLocalized; |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Returns whether the field is required. |
|
599 | - * |
|
600 | - * @return bool |
|
601 | - */ |
|
602 | - public function isRequired() |
|
603 | - { |
|
604 | - $configuration = $this->getConfiguration(); |
|
605 | - |
|
606 | - $isRequired = false; |
|
607 | - if (isset($configuration['minitems'])) { |
|
608 | - // is required of a select? |
|
609 | - $isRequired = $configuration['minitems'] == 1 ? true : false; |
|
610 | - } elseif (isset($configuration['eval'])) { |
|
611 | - $parts = GeneralUtility::trimExplode(',', $configuration['eval'], true); |
|
612 | - $isRequired = in_array('required', $parts); |
|
613 | - } |
|
614 | - return $isRequired; |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Returns an array containing the configuration of a column. |
|
619 | - * |
|
620 | - * @return array |
|
621 | - */ |
|
622 | - public function getField() |
|
623 | - { |
|
624 | - return $this->tca; |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Returns the relation type |
|
629 | - * |
|
630 | - * @return string |
|
631 | - */ |
|
632 | - public function relationDataType() |
|
633 | - { |
|
634 | - $configuration = $this->getConfiguration(); |
|
635 | - return empty($configuration['foreign_table']) ? '' : $configuration['foreign_table']; |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Returns whether the field has relation (one to many, many to many) |
|
640 | - * |
|
641 | - * @return bool |
|
642 | - */ |
|
643 | - public function hasRelation() |
|
644 | - { |
|
645 | - return null !== $this->getForeignTable(); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Returns whether the field has no relation (one to many, many to many) |
|
650 | - * |
|
651 | - * @return bool |
|
652 | - */ |
|
653 | - public function hasNoRelation() |
|
654 | - { |
|
655 | - return !$this->hasRelation(); |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Returns whether the field has a "many" objects connected including "many-to-many" or "one-to-many". |
|
660 | - * |
|
661 | - * @return bool |
|
662 | - */ |
|
663 | - public function hasMany() |
|
664 | - { |
|
665 | - $configuration = $this->getConfiguration(); |
|
666 | - return $this->hasRelation() && ($configuration['maxitems'] > 1 || isset($configuration['foreign_table_field'])); |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Returns whether the field has relation "one" object connected including of "one-to-one" or "many-to-one". |
|
671 | - * |
|
672 | - * @return bool |
|
673 | - */ |
|
674 | - public function hasOne() |
|
675 | - { |
|
676 | - $configuration = $this->getConfiguration(); |
|
677 | - return !isset($configuration['MM']) && $this->hasRelation() && ($configuration['maxitems'] == 1 || !isset($configuration['maxitems'])); |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Returns whether the field has many-to-one relation. |
|
682 | - * |
|
683 | - * @return bool |
|
684 | - */ |
|
685 | - public function hasRelationManyToOne() |
|
686 | - { |
|
687 | - $result = false; |
|
688 | - |
|
689 | - $foreignField = $this->getForeignField(); |
|
690 | - if (!empty($foreignField)) { |
|
691 | - |
|
692 | - // Load TCA service of the foreign field. |
|
693 | - $foreignTable = $this->getForeignTable(); |
|
694 | - $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasMany(); |
|
695 | - } |
|
696 | - return $result; |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Returns whether the field has one-to-many relation. |
|
701 | - * |
|
702 | - * @return bool |
|
703 | - */ |
|
704 | - public function hasRelationOneToMany() |
|
705 | - { |
|
706 | - $result = false; |
|
707 | - |
|
708 | - $foreignField = $this->getForeignField(); |
|
709 | - if (!empty($foreignField)) { |
|
710 | - |
|
711 | - // Load TCA service of the foreign field. |
|
712 | - $foreignTable = $this->getForeignTable(); |
|
713 | - $result = $this->hasMany() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
714 | - } |
|
715 | - return $result; |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Returns whether the field has one-to-one relation. |
|
720 | - * |
|
721 | - * @return bool |
|
722 | - */ |
|
723 | - public function hasRelationOneToOne() |
|
724 | - { |
|
725 | - $result = false; |
|
726 | - |
|
727 | - $foreignField = $this->getForeignField(); |
|
728 | - if (!empty($foreignField)) { |
|
729 | - |
|
730 | - // Load TCA service of foreign field. |
|
731 | - $foreignTable = $this->getForeignTable(); |
|
732 | - $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
733 | - } |
|
734 | - return $result; |
|
735 | - } |
|
736 | - |
|
737 | - /** |
|
738 | - * Returns whether the field has many to many relation. |
|
739 | - * |
|
740 | - * @return bool |
|
741 | - */ |
|
742 | - public function hasRelationManyToMany() |
|
743 | - { |
|
744 | - $configuration = $this->getConfiguration(); |
|
745 | - return $this->hasRelation() && (isset($configuration['MM']) || isset($configuration['foreign_table_field'])); |
|
746 | - } |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns whether the field has many to many relation using comma separated values (legacy). |
|
750 | - * |
|
751 | - * @return bool |
|
752 | - */ |
|
753 | - public function hasRelationWithCommaSeparatedValues() |
|
754 | - { |
|
755 | - $configuration = $this->getConfiguration(); |
|
756 | - return $this->hasRelation() && !isset($configuration['MM']) && !isset($configuration['foreign_field']) && $configuration['maxitems'] > 1; |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * @return array |
|
761 | - */ |
|
762 | - public function getTca() |
|
763 | - { |
|
764 | - return $this->tca['columns']; |
|
765 | - } |
|
766 | - |
|
767 | - /** |
|
768 | - * @return string |
|
769 | - */ |
|
770 | - public function getCompositeField() |
|
771 | - { |
|
772 | - return $this->compositeField; |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * @param string $compositeField |
|
777 | - */ |
|
778 | - public function setCompositeField($compositeField) |
|
779 | - { |
|
780 | - $this->compositeField = $compositeField; |
|
781 | - } |
|
782 | - |
|
783 | - /** |
|
784 | - * Returns an instance of the Frontend object. |
|
785 | - * |
|
786 | - * @return TypoScriptFrontendController |
|
787 | - */ |
|
788 | - protected function getFrontendObject() |
|
789 | - { |
|
790 | - return $GLOBALS['TSFE']; |
|
791 | - } |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $fieldName; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $compositeField; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $tableName; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $tca; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param string $fieldName |
|
42 | + * @param array $tca |
|
43 | + * @param string $tableName |
|
44 | + * @param string $compositeField |
|
45 | + * @return \Fab\Vidi\Tca\FieldService |
|
46 | + */ |
|
47 | + public function __construct($fieldName, array $tca, $tableName, $compositeField = '') |
|
48 | + { |
|
49 | + $this->fieldName = $fieldName; |
|
50 | + $this->tca = $tca; |
|
51 | + $this->tableName = $tableName; |
|
52 | + $this->compositeField = $compositeField; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc... |
|
57 | + * |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function isSystem() |
|
61 | + { |
|
62 | + return in_array($this->fieldName, Tca::getSystemFields()); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Tells the opposition of isSystem() |
|
67 | + * |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function isNotSystem() |
|
71 | + { |
|
72 | + return !$this->isSystem(); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Returns the configuration for a $field |
|
77 | + * |
|
78 | + * @throws \Exception |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function getConfiguration() |
|
82 | + { |
|
83 | + return empty($this->tca['config']) ? [] : $this->tca['config']; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Returns a key of the configuration. |
|
88 | + * If the key can not to be found, returns null. |
|
89 | + * |
|
90 | + * @param string $key |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function get($key) |
|
94 | + { |
|
95 | + $configuration = $this->getConfiguration(); |
|
96 | + return empty($configuration[$key]) ? null : $configuration[$key]; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns the foreign field of a given field (opposite relational field). |
|
101 | + * If no relation exists, returns null. |
|
102 | + * |
|
103 | + * @return string|null |
|
104 | + */ |
|
105 | + public function getForeignField() |
|
106 | + { |
|
107 | + $result = null; |
|
108 | + $configuration = $this->getConfiguration(); |
|
109 | + |
|
110 | + if (!empty($configuration['foreign_field'])) { |
|
111 | + $result = $configuration['foreign_field']; |
|
112 | + } elseif ($this->hasRelationManyToMany()) { |
|
113 | + |
|
114 | + $foreignTable = $this->getForeignTable(); |
|
115 | + $manyToManyTable = $this->getManyToManyTable(); |
|
116 | + |
|
117 | + // Load TCA service of foreign field. |
|
118 | + $tcaForeignTableService = Tca::table($foreignTable); |
|
119 | + |
|
120 | + // Look into the MM relations checking for the opposite field |
|
121 | + foreach ($tcaForeignTableService->getFields() as $fieldName) { |
|
122 | + if ($manyToManyTable == $tcaForeignTableService->field($fieldName)->getManyToManyTable()) { |
|
123 | + $result = $fieldName; |
|
124 | + break; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + return $result; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Returns the foreign table of a given field (opposite relational table). |
|
133 | + * If no relation exists, returns null. |
|
134 | + * |
|
135 | + * @return string|null |
|
136 | + */ |
|
137 | + public function getForeignTable() |
|
138 | + { |
|
139 | + $result = null; |
|
140 | + $configuration = $this->getConfiguration(); |
|
141 | + |
|
142 | + if (!empty($configuration['foreign_table'])) { |
|
143 | + $result = $configuration['foreign_table']; |
|
144 | + } elseif ($this->isGroup()) { |
|
145 | + $fieldParts = explode('.', $this->compositeField, 2); |
|
146 | + $result = $fieldParts[1]; |
|
147 | + } |
|
148 | + return $result; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Returns the foreign clause. |
|
153 | + * If no foreign order exists, returns empty string. |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function getForeignClause() |
|
158 | + { |
|
159 | + $result = ''; |
|
160 | + $configuration = $this->getConfiguration(); |
|
161 | + |
|
162 | + if (!empty($configuration['foreign_table_where'])) { |
|
163 | + $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
164 | + if (!empty($parts[0])) { |
|
165 | + $result = $parts[0]; |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + // Substitute some variables |
|
170 | + return $this->substituteKnownMarkers($result); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Substitute some known markers from the where clause in the Frontend Context. |
|
175 | + * |
|
176 | + * @param string $clause |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + protected function substituteKnownMarkers($clause) |
|
180 | + { |
|
181 | + if ($clause && $this->isFrontendMode()) { |
|
182 | + |
|
183 | + $searches = array( |
|
184 | + '###CURRENT_PID###', |
|
185 | + '###REC_FIELD_sys_language_uid###' |
|
186 | + ); |
|
187 | + |
|
188 | + $replaces = array( |
|
189 | + $this->getFrontendObject()->id, |
|
190 | + $this->getFrontendObject()->sys_language_uid, |
|
191 | + ); |
|
192 | + |
|
193 | + $clause = str_replace($searches, $replaces, $clause); |
|
194 | + } |
|
195 | + return $clause; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Returns the foreign order of the current field. |
|
200 | + * If no foreign order exists, returns empty string. |
|
201 | + * |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function getForeignOrder() |
|
205 | + { |
|
206 | + $result = ''; |
|
207 | + $configuration = $this->getConfiguration(); |
|
208 | + |
|
209 | + if (!empty($configuration['foreign_table_where'])) { |
|
210 | + $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
211 | + if (!empty($parts[1])) { |
|
212 | + $result = $parts[1]; |
|
213 | + } |
|
214 | + } |
|
215 | + return $result; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Returns the MM table of a field. |
|
220 | + * If no relation exists, returns null. |
|
221 | + * |
|
222 | + * @return string|null |
|
223 | + */ |
|
224 | + public function getManyToManyTable() |
|
225 | + { |
|
226 | + $configuration = $this->getConfiguration(); |
|
227 | + return empty($configuration['MM']) ? null : $configuration['MM']; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Returns a possible additional table name used in MM relations. |
|
232 | + * If no table name exists, returns null. |
|
233 | + * |
|
234 | + * @return string|null |
|
235 | + */ |
|
236 | + public function getAdditionalTableNameCondition() |
|
237 | + { |
|
238 | + $result = null; |
|
239 | + $configuration = $this->getConfiguration(); |
|
240 | + |
|
241 | + if (!empty($configuration['MM_match_fields']['tablenames'])) { |
|
242 | + $result = $configuration['MM_match_fields']['tablenames']; |
|
243 | + } elseif ($this->isGroup()) { |
|
244 | + |
|
245 | + // @todo check if $this->fieldName could be simply used as $result |
|
246 | + $fieldParts = explode('.', $this->compositeField, 2); |
|
247 | + $result = $fieldParts[1]; |
|
248 | + } |
|
249 | + |
|
250 | + return $result; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Returns a possible additional conditions for MM tables such as "tablenames", "fieldname", etc... |
|
255 | + * |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + public function getAdditionalMMCondition() |
|
259 | + { |
|
260 | + $additionalMMConditions = []; |
|
261 | + $configuration = $this->getConfiguration(); |
|
262 | + |
|
263 | + if (!empty($configuration['MM_match_fields'])) { |
|
264 | + $additionalMMConditions = $configuration['MM_match_fields']; |
|
265 | + } |
|
266 | + |
|
267 | + // Add in any case a table name for "group" |
|
268 | + if ($this->isGroup()) { |
|
269 | + |
|
270 | + // @todo check if $this->fieldName could be simply used as $result |
|
271 | + $fieldParts = explode('.', $this->compositeField, 2); |
|
272 | + $additionalMMConditions = array( |
|
273 | + 'tablenames' => $fieldParts[1], |
|
274 | + ); |
|
275 | + } |
|
276 | + return $additionalMMConditions; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Returns whether the field name is the opposite in MM relation. |
|
281 | + * |
|
282 | + * @return bool |
|
283 | + */ |
|
284 | + public function isOppositeRelation() |
|
285 | + { |
|
286 | + $configuration = $this->getConfiguration(); |
|
287 | + return isset($configuration['MM_opposite_field']); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Returns the configuration for a $field. |
|
292 | + * |
|
293 | + * @throws \Exception |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function getType() |
|
297 | + { |
|
298 | + |
|
299 | + if ($this->isSystem()) { |
|
300 | + $fieldType = FieldType::NUMBER; |
|
301 | + } else { |
|
302 | + $configuration = $this->getConfiguration(); |
|
303 | + |
|
304 | + if (empty($configuration['type'])) { |
|
305 | + throw new \Exception(sprintf('No field type found for "%s" in table "%s"', $this->fieldName, $this->tableName), 1385556627); |
|
306 | + } |
|
307 | + |
|
308 | + $fieldType = $configuration['type']; |
|
309 | + |
|
310 | + if ($configuration['type'] === FieldType::SELECT && !empty($configuration['size']) && $configuration['size'] > 1) { |
|
311 | + $fieldType = FieldType::MULTISELECT; |
|
312 | + } elseif (!empty($configuration['foreign_table']) |
|
313 | + && ($configuration['foreign_table'] == 'sys_file_reference' || $configuration['foreign_table'] == 'sys_file') |
|
314 | + ) { |
|
315 | + $fieldType = FieldType::FILE; |
|
316 | + } elseif (!empty($configuration['eval'])) { |
|
317 | + $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
318 | + if (in_array('datetime', $parts)) { |
|
319 | + $fieldType = FieldType::DATETIME; |
|
320 | + } elseif (in_array('date', $parts)) { |
|
321 | + $fieldType = FieldType::DATE; |
|
322 | + } elseif (in_array('email', $parts)) { |
|
323 | + $fieldType = FieldType::EMAIL; |
|
324 | + } elseif (in_array('int', $parts) || in_array('double2', $parts)) { |
|
325 | + $fieldType = FieldType::NUMBER; |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + // Do some legacy conversion |
|
330 | + if ($fieldType === 'input') { |
|
331 | + $fieldType = FieldType::TEXT; |
|
332 | + } elseif ($fieldType === 'text') { |
|
333 | + $fieldType = FieldType::TEXTAREA; |
|
334 | + } |
|
335 | + } |
|
336 | + return $fieldType; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Return the default value. |
|
341 | + * |
|
342 | + * @return bool |
|
343 | + */ |
|
344 | + public function getDefaultValue() |
|
345 | + { |
|
346 | + $configuration = $this->getConfiguration(); |
|
347 | + return isset($configuration['default']) ? $configuration['default'] : null; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Get the translation of a label given a column. |
|
352 | + * |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function getLabel() |
|
356 | + { |
|
357 | + $label = ''; |
|
358 | + if ($this->hasLabel()) { |
|
359 | + try { |
|
360 | + $label = LocalizationUtility::translate($this->tca['label'], ''); |
|
361 | + } catch (\InvalidArgumentException $e) { |
|
362 | + } |
|
363 | + if (empty($label)) { |
|
364 | + $label = $this->tca['label']; |
|
365 | + } |
|
366 | + } |
|
367 | + return $label; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Get the translation of a label given a column. |
|
372 | + * |
|
373 | + * @param string $itemValue the item value to search for. |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + public function getLabelForItem($itemValue) |
|
377 | + { |
|
378 | + |
|
379 | + // Early return whether there is nothing to be translated as label. |
|
380 | + if (is_null($itemValue)) { |
|
381 | + return ''; |
|
382 | + } elseif (is_string($itemValue) && $itemValue === '') { |
|
383 | + return $itemValue; |
|
384 | + } |
|
385 | + |
|
386 | + $configuration = $this->getConfiguration(); |
|
387 | + if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
388 | + foreach ($configuration['items'] as $item) { |
|
389 | + if ($item[1] == $itemValue) { |
|
390 | + try { |
|
391 | + $label = LocalizationUtility::translate($item[0], ''); |
|
392 | + } catch (\InvalidArgumentException $e) { |
|
393 | + } |
|
394 | + if (empty($label)) { |
|
395 | + $label = $item[0]; |
|
396 | + } |
|
397 | + break; |
|
398 | + } |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + // Try fetching a label from a possible itemsProcFunc |
|
403 | + if (!isset($label) && is_scalar($itemValue)) { |
|
404 | + $items = $this->fetchItemsFromUserFunction(); |
|
405 | + if (!empty($items[$itemValue])) { |
|
406 | + $label = $items[$itemValue]; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + // Returns a label if it has been found, otherwise returns the item value as fallback. |
|
411 | + return isset($label) ? $label : $itemValue; |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Retrieve items from User Function. |
|
416 | + * |
|
417 | + * @return array |
|
418 | + */ |
|
419 | + protected function fetchItemsFromUserFunction() |
|
420 | + { |
|
421 | + $values = []; |
|
422 | + |
|
423 | + $configuration = $this->getConfiguration(); |
|
424 | + if (!empty($configuration['itemsProcFunc'])) { |
|
425 | + $parts = explode('php:', $configuration['itemsProcFunc']); |
|
426 | + if (!empty($parts[1])) { |
|
427 | + |
|
428 | + list($class, $method) = explode('->', $parts[1]); |
|
429 | + |
|
430 | + $parameters['items'] = []; |
|
431 | + $object = GeneralUtility::makeInstance($class); |
|
432 | + $object->$method($parameters); |
|
433 | + |
|
434 | + foreach ($parameters['items'] as $items) { |
|
435 | + $values[$items[1]] = $items[0]; |
|
436 | + } |
|
437 | + } |
|
438 | + } |
|
439 | + return $values; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Get a possible icon given a field name an an item. |
|
444 | + * |
|
445 | + * @param string $itemValue the item value to search for. |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public function getIconForItem($itemValue) |
|
449 | + { |
|
450 | + $result = ''; |
|
451 | + $configuration = $this->getConfiguration(); |
|
452 | + if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
453 | + foreach ($configuration['items'] as $item) { |
|
454 | + if ($item[1] == $itemValue) { |
|
455 | + $result = empty($item[2]) ? '' : $item[2]; |
|
456 | + break; |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + return $result; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * Returns whether the field has a label. |
|
465 | + * |
|
466 | + * @return bool |
|
467 | + */ |
|
468 | + public function hasLabel() |
|
469 | + { |
|
470 | + return empty($this->tca['label']) ? false : true; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Tell whether the current BE User has access to this field. |
|
475 | + * |
|
476 | + * @return bool |
|
477 | + */ |
|
478 | + public function hasAccess() |
|
479 | + { |
|
480 | + $hasAccess = true; |
|
481 | + if ($this->isBackendMode() |
|
482 | + && Tca::table($this->tableName)->hasAccess() |
|
483 | + && isset($this->tca['exclude']) |
|
484 | + && $this->tca['exclude'] |
|
485 | + ) { |
|
486 | + $hasAccess = $this->getBackendUser()->check('non_exclude_fields', $this->tableName . ':' . $this->fieldName); |
|
487 | + } |
|
488 | + return $hasAccess; |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Returns whether the field is numerical. |
|
493 | + * |
|
494 | + * @return bool |
|
495 | + */ |
|
496 | + public function isNumerical() |
|
497 | + { |
|
498 | + $result = $this->isSystem(); |
|
499 | + if ($result === false) { |
|
500 | + $configuration = $this->getConfiguration(); |
|
501 | + $parts = []; |
|
502 | + if (!empty($configuration['eval'])) { |
|
503 | + $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
504 | + } |
|
505 | + $result = in_array('int', $parts) || in_array('float', $parts); |
|
506 | + } |
|
507 | + return $result; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Returns whether the field is of type text area. |
|
512 | + * |
|
513 | + * @return bool |
|
514 | + */ |
|
515 | + public function isTextArea() |
|
516 | + { |
|
517 | + return $this->getType() === FieldType::TEXTAREA; |
|
518 | + } |
|
519 | + /** |
|
520 | + * Returns whether the field is of type text area. |
|
521 | + * |
|
522 | + * @return bool |
|
523 | + */ |
|
524 | + public function isText() |
|
525 | + { |
|
526 | + return $this->getType() === FieldType::TEXT; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Returns whether the field is displayed as a tree. |
|
531 | + * |
|
532 | + * @return bool |
|
533 | + */ |
|
534 | + public function isRenderModeTree() |
|
535 | + { |
|
536 | + $configuration = $this->getConfiguration(); |
|
537 | + return isset($configuration['renderMode']) && $configuration['renderMode'] == FieldType::TREE; |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * Returns whether the field is of type select. |
|
542 | + * |
|
543 | + * @return bool |
|
544 | + */ |
|
545 | + public function isSelect() |
|
546 | + { |
|
547 | + return $this->getType() === FieldType::SELECT; |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * Returns whether the field is of type select. |
|
552 | + * |
|
553 | + * @return bool |
|
554 | + */ |
|
555 | + public function isMultipleSelect() |
|
556 | + { |
|
557 | + return $this->getType() === FieldType::MULTISELECT; |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Returns whether the field is of type select. |
|
562 | + * |
|
563 | + * @return bool |
|
564 | + */ |
|
565 | + public function isCheckBox() |
|
566 | + { |
|
567 | + return $this->getType() === FieldType::CHECKBOX; |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Returns whether the field is of type db. |
|
572 | + * |
|
573 | + * @return bool |
|
574 | + */ |
|
575 | + public function isGroup() |
|
576 | + { |
|
577 | + return $this->getType() === 'group'; |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Returns whether the field is language aware. |
|
582 | + * |
|
583 | + * @return bool |
|
584 | + */ |
|
585 | + public function isLocalized() |
|
586 | + { |
|
587 | + $isLocalized = false; |
|
588 | + if (isset($this->tca['l10n_mode'])) { |
|
589 | + |
|
590 | + if ($this->tca['l10n_mode'] == 'prefixLangTitle' || $this->tca['l10n_mode'] == 'mergeIfNotBlank') { |
|
591 | + $isLocalized = true; |
|
592 | + } |
|
593 | + } |
|
594 | + return $isLocalized; |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Returns whether the field is required. |
|
599 | + * |
|
600 | + * @return bool |
|
601 | + */ |
|
602 | + public function isRequired() |
|
603 | + { |
|
604 | + $configuration = $this->getConfiguration(); |
|
605 | + |
|
606 | + $isRequired = false; |
|
607 | + if (isset($configuration['minitems'])) { |
|
608 | + // is required of a select? |
|
609 | + $isRequired = $configuration['minitems'] == 1 ? true : false; |
|
610 | + } elseif (isset($configuration['eval'])) { |
|
611 | + $parts = GeneralUtility::trimExplode(',', $configuration['eval'], true); |
|
612 | + $isRequired = in_array('required', $parts); |
|
613 | + } |
|
614 | + return $isRequired; |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Returns an array containing the configuration of a column. |
|
619 | + * |
|
620 | + * @return array |
|
621 | + */ |
|
622 | + public function getField() |
|
623 | + { |
|
624 | + return $this->tca; |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Returns the relation type |
|
629 | + * |
|
630 | + * @return string |
|
631 | + */ |
|
632 | + public function relationDataType() |
|
633 | + { |
|
634 | + $configuration = $this->getConfiguration(); |
|
635 | + return empty($configuration['foreign_table']) ? '' : $configuration['foreign_table']; |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Returns whether the field has relation (one to many, many to many) |
|
640 | + * |
|
641 | + * @return bool |
|
642 | + */ |
|
643 | + public function hasRelation() |
|
644 | + { |
|
645 | + return null !== $this->getForeignTable(); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Returns whether the field has no relation (one to many, many to many) |
|
650 | + * |
|
651 | + * @return bool |
|
652 | + */ |
|
653 | + public function hasNoRelation() |
|
654 | + { |
|
655 | + return !$this->hasRelation(); |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Returns whether the field has a "many" objects connected including "many-to-many" or "one-to-many". |
|
660 | + * |
|
661 | + * @return bool |
|
662 | + */ |
|
663 | + public function hasMany() |
|
664 | + { |
|
665 | + $configuration = $this->getConfiguration(); |
|
666 | + return $this->hasRelation() && ($configuration['maxitems'] > 1 || isset($configuration['foreign_table_field'])); |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Returns whether the field has relation "one" object connected including of "one-to-one" or "many-to-one". |
|
671 | + * |
|
672 | + * @return bool |
|
673 | + */ |
|
674 | + public function hasOne() |
|
675 | + { |
|
676 | + $configuration = $this->getConfiguration(); |
|
677 | + return !isset($configuration['MM']) && $this->hasRelation() && ($configuration['maxitems'] == 1 || !isset($configuration['maxitems'])); |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Returns whether the field has many-to-one relation. |
|
682 | + * |
|
683 | + * @return bool |
|
684 | + */ |
|
685 | + public function hasRelationManyToOne() |
|
686 | + { |
|
687 | + $result = false; |
|
688 | + |
|
689 | + $foreignField = $this->getForeignField(); |
|
690 | + if (!empty($foreignField)) { |
|
691 | + |
|
692 | + // Load TCA service of the foreign field. |
|
693 | + $foreignTable = $this->getForeignTable(); |
|
694 | + $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasMany(); |
|
695 | + } |
|
696 | + return $result; |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Returns whether the field has one-to-many relation. |
|
701 | + * |
|
702 | + * @return bool |
|
703 | + */ |
|
704 | + public function hasRelationOneToMany() |
|
705 | + { |
|
706 | + $result = false; |
|
707 | + |
|
708 | + $foreignField = $this->getForeignField(); |
|
709 | + if (!empty($foreignField)) { |
|
710 | + |
|
711 | + // Load TCA service of the foreign field. |
|
712 | + $foreignTable = $this->getForeignTable(); |
|
713 | + $result = $this->hasMany() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
714 | + } |
|
715 | + return $result; |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Returns whether the field has one-to-one relation. |
|
720 | + * |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | + public function hasRelationOneToOne() |
|
724 | + { |
|
725 | + $result = false; |
|
726 | + |
|
727 | + $foreignField = $this->getForeignField(); |
|
728 | + if (!empty($foreignField)) { |
|
729 | + |
|
730 | + // Load TCA service of foreign field. |
|
731 | + $foreignTable = $this->getForeignTable(); |
|
732 | + $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
733 | + } |
|
734 | + return $result; |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Returns whether the field has many to many relation. |
|
739 | + * |
|
740 | + * @return bool |
|
741 | + */ |
|
742 | + public function hasRelationManyToMany() |
|
743 | + { |
|
744 | + $configuration = $this->getConfiguration(); |
|
745 | + return $this->hasRelation() && (isset($configuration['MM']) || isset($configuration['foreign_table_field'])); |
|
746 | + } |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns whether the field has many to many relation using comma separated values (legacy). |
|
750 | + * |
|
751 | + * @return bool |
|
752 | + */ |
|
753 | + public function hasRelationWithCommaSeparatedValues() |
|
754 | + { |
|
755 | + $configuration = $this->getConfiguration(); |
|
756 | + return $this->hasRelation() && !isset($configuration['MM']) && !isset($configuration['foreign_field']) && $configuration['maxitems'] > 1; |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * @return array |
|
761 | + */ |
|
762 | + public function getTca() |
|
763 | + { |
|
764 | + return $this->tca['columns']; |
|
765 | + } |
|
766 | + |
|
767 | + /** |
|
768 | + * @return string |
|
769 | + */ |
|
770 | + public function getCompositeField() |
|
771 | + { |
|
772 | + return $this->compositeField; |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * @param string $compositeField |
|
777 | + */ |
|
778 | + public function setCompositeField($compositeField) |
|
779 | + { |
|
780 | + $this->compositeField = $compositeField; |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * Returns an instance of the Frontend object. |
|
785 | + * |
|
786 | + * @return TypoScriptFrontendController |
|
787 | + */ |
|
788 | + protected function getFrontendObject() |
|
789 | + { |
|
790 | + return $GLOBALS['TSFE']; |
|
791 | + } |
|
792 | 792 | |
793 | 793 | } |
@@ -20,447 +20,447 @@ |
||
20 | 20 | class TableService extends AbstractTca |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $tca; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $columnTca; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $tableName; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $instances; |
|
42 | - |
|
43 | - /** |
|
44 | - * @throws InvalidKeyInArrayException |
|
45 | - * @param string $tableName |
|
46 | - * @return \Fab\Vidi\Tca\TableService |
|
47 | - */ |
|
48 | - public function __construct($tableName) |
|
49 | - { |
|
50 | - $this->tableName = $tableName; |
|
51 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
52 | - throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106); |
|
53 | - } |
|
54 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl']; |
|
55 | - $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns']; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Tell whether the table has a label field. |
|
60 | - * |
|
61 | - * @throws InvalidKeyInArrayException |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function hasLabelField() |
|
65 | - { |
|
66 | - return $this->has('label'); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get the label name of table name. |
|
71 | - * |
|
72 | - * @throws InvalidKeyInArrayException |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getLabelField() |
|
76 | - { |
|
77 | - $labelField = $this->get('label'); |
|
78 | - if (empty($labelField)) { |
|
79 | - throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726); |
|
80 | - } |
|
81 | - return $labelField; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Returns the translated label of the table name. |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getLabel() |
|
90 | - { |
|
91 | - $label = ''; |
|
92 | - try { |
|
93 | - $label = LocalizationUtility::translate($this->getLabelField(), ''); |
|
94 | - } catch (\InvalidArgumentException $e) { |
|
95 | - } |
|
96 | - if (empty($label)) { |
|
97 | - $label = $this->getLabelField(); |
|
98 | - } |
|
99 | - return $label; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the title of the table. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function getTitle() |
|
108 | - { |
|
109 | - $title = ''; |
|
110 | - try { |
|
111 | - $title = LocalizationUtility::translate((string)$this->get('title'), ''); |
|
112 | - } catch (\InvalidArgumentException $e) { |
|
113 | - } |
|
114 | - if (empty($title)) { |
|
115 | - $title = $this->get('title'); |
|
116 | - } |
|
117 | - return $title; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Return the "disabled" field. |
|
122 | - * |
|
123 | - * @throws InvalidKeyInArrayException |
|
124 | - * @return string|null |
|
125 | - */ |
|
126 | - public function getHiddenField() |
|
127 | - { |
|
128 | - $hiddenField = null; |
|
129 | - $enableColumns = $this->get('enablecolumns'); |
|
130 | - if (is_array($enableColumns) && !empty($enableColumns['disabled'])) { |
|
131 | - $hiddenField = $enableColumns['disabled']; |
|
132 | - } |
|
133 | - return $hiddenField; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Return the "starttime" field. |
|
138 | - * |
|
139 | - * @throws InvalidKeyInArrayException |
|
140 | - * @return string|null |
|
141 | - */ |
|
142 | - public function getStartTimeField() |
|
143 | - { |
|
144 | - $startTimeField = null; |
|
145 | - $enableColumns = $this->get('enablecolumns'); |
|
146 | - if (is_array($enableColumns) && !empty($enableColumns['starttime'])) { |
|
147 | - $startTimeField = $enableColumns['starttime']; |
|
148 | - } |
|
149 | - return $startTimeField; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Return the "endtime" field. |
|
154 | - * |
|
155 | - * @throws InvalidKeyInArrayException |
|
156 | - * @return string|null |
|
157 | - */ |
|
158 | - public function getEndTimeField() |
|
159 | - { |
|
160 | - $endTimeField = null; |
|
161 | - $enableColumns = $this->get('enablecolumns'); |
|
162 | - if (is_array($enableColumns) && !empty($enableColumns['endtime'])) { |
|
163 | - $endTimeField = $enableColumns['endtime']; |
|
164 | - } |
|
165 | - return $endTimeField; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Tells whether the table is hidden. |
|
170 | - * |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - public function isHidden() |
|
174 | - { |
|
175 | - return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Tells whether the table is not hidden. |
|
180 | - * |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - public function isNotHidden() |
|
184 | - { |
|
185 | - return !$this->isHidden(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Get the "deleted" field for the table. |
|
190 | - * |
|
191 | - * @return string|null |
|
192 | - */ |
|
193 | - public function getDeletedField() |
|
194 | - { |
|
195 | - return $this->get('delete'); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get the modification time stamp field. |
|
200 | - * |
|
201 | - * @return string|null |
|
202 | - */ |
|
203 | - public function getTimeModificationField() |
|
204 | - { |
|
205 | - return $this->get('tstamp'); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Get the creation time stamp field. |
|
210 | - * |
|
211 | - * @return string|null |
|
212 | - */ |
|
213 | - public function getTimeCreationField() |
|
214 | - { |
|
215 | - return $this->get('crdate'); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Get the language field for the table. |
|
220 | - * |
|
221 | - * @return string|null |
|
222 | - */ |
|
223 | - public function getLanguageField() |
|
224 | - { |
|
225 | - return $this->get('languageField'); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Get the field which points to the parent. |
|
230 | - * |
|
231 | - * @return string|null |
|
232 | - */ |
|
233 | - public function getLanguageParentField() |
|
234 | - { |
|
235 | - return $this->get('transOrigPointerField'); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Returns the default order in the form of a SQL segment. |
|
240 | - * |
|
241 | - * @return string|null |
|
242 | - */ |
|
243 | - public function getDefaultOrderSql() |
|
244 | - { |
|
245 | - // "sortby" typically has "sorting" as value. |
|
246 | - $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby'); |
|
247 | - return $order; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Returns the parsed default orderings. |
|
252 | - * Returns array looks like array('title' => 'ASC'); |
|
253 | - * |
|
254 | - * @return array |
|
255 | - */ |
|
256 | - public function getDefaultOrderings() |
|
257 | - { |
|
258 | - |
|
259 | - // first clean up the sql segment |
|
260 | - $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql()); |
|
261 | - $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true); |
|
262 | - |
|
263 | - $orderings = []; |
|
264 | - foreach ($defaultOrderParts as $defaultOrderPart) { |
|
265 | - $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart); |
|
266 | - if (empty($parts[1])) { |
|
267 | - $parts[1] = QueryInterface::ORDER_DESCENDING; |
|
268 | - } |
|
269 | - $orderings[$parts[0]] = $parts[1]; |
|
270 | - } |
|
271 | - |
|
272 | - return $orderings; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Returns the searchable fields. |
|
277 | - * |
|
278 | - * @return string|null |
|
279 | - */ |
|
280 | - public function getSearchFields() |
|
281 | - { |
|
282 | - return $this->get('searchFields'); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Returns an array containing the field names. |
|
287 | - * |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function getFields() |
|
291 | - { |
|
292 | - return array_keys($this->columnTca); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Returns an array containing the fields and their configuration. |
|
297 | - * |
|
298 | - * @return array |
|
299 | - */ |
|
300 | - public function getFieldsAndConfiguration() |
|
301 | - { |
|
302 | - return $this->columnTca; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Tell whether we have a field "sorting". |
|
307 | - * |
|
308 | - * @return bool |
|
309 | - */ |
|
310 | - public function hasSortableField() |
|
311 | - { |
|
312 | - return $this->has('sortby'); |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Tell whether the field exists or not. |
|
317 | - * |
|
318 | - * @param string $fieldName |
|
319 | - * @return bool |
|
320 | - */ |
|
321 | - public function hasField($fieldName) |
|
322 | - { |
|
323 | - if ($this->isComposite($fieldName)) { |
|
324 | - $parts = explode('.', $fieldName); |
|
325 | - list ($strippedFieldPath, $possibleTableName) = $parts; |
|
326 | - $hasField = isset($this->columnTca[$strippedFieldPath], $GLOBALS['TCA'][$possibleTableName]); |
|
327 | - |
|
328 | - // Continue checking that the $strippedFieldName is of type "group" |
|
329 | - if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldPath]) && count($parts) > 2) { |
|
330 | - $hasField = Tca::table($this->tableName)->field($strippedFieldPath)->isGroup(); // Group |
|
331 | - } elseif (isset($this->columnTca[$strippedFieldPath]['config']['readOnly']) && (bool)$this->columnTca[$strippedFieldPath]['config']['readOnly']) { |
|
332 | - $hasField = false; // handle case metadata.fe_groups where "fe_groups" is a tableName. |
|
333 | - } |
|
334 | - } else { |
|
335 | - $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields(), true); |
|
336 | - } |
|
337 | - return $hasField; |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Tell whether the field name contains a path, e.g. metadata.title |
|
342 | - * |
|
343 | - * @param string $fieldName |
|
344 | - * @return boolean |
|
345 | - */ |
|
346 | - public function isComposite($fieldName) |
|
347 | - { |
|
348 | - return strpos($fieldName, '.') > 0; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Tells whether the $key exists. |
|
353 | - * |
|
354 | - * @param string $key |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function has($key) |
|
358 | - { |
|
359 | - return isset($this->tca[$key]); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Tells whether the table name has "workspace" support. |
|
364 | - * |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function hasWorkspaceSupport() |
|
368 | - { |
|
369 | - return isset($this->tca['versioningWS']); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Tells whether the table name has "language" support. |
|
374 | - * |
|
375 | - * @return string |
|
376 | - */ |
|
377 | - public function hasLanguageSupport() |
|
378 | - { |
|
379 | - return isset($this->tca['languageField']); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Return configuration value given a key. |
|
384 | - * |
|
385 | - * @param string $key |
|
386 | - * @return string|null |
|
387 | - */ |
|
388 | - public function get($key) |
|
389 | - { |
|
390 | - return $this->has($key) ? $this->tca[$key] : null; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @return array |
|
395 | - */ |
|
396 | - public function getTca() |
|
397 | - { |
|
398 | - return $this->tca; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Tell whether the current BE User has access to this field. |
|
403 | - * |
|
404 | - * @return bool |
|
405 | - */ |
|
406 | - public function hasAccess() |
|
407 | - { |
|
408 | - $hasAccess = true; |
|
409 | - if ($this->isBackendMode()) { |
|
410 | - $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName); |
|
411 | - } |
|
412 | - return $hasAccess; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $fieldName |
|
417 | - * @throws \Exception |
|
418 | - * @return FieldService |
|
419 | - */ |
|
420 | - public function field($fieldName) |
|
421 | - { |
|
422 | - |
|
423 | - // In case field contains items.tx_table for field type "group" |
|
424 | - $compositeField = ''; |
|
425 | - if (strpos($fieldName, '.') !== false) { |
|
426 | - $compositeField = $fieldName; |
|
427 | - $fieldParts = explode('.', $compositeField, 2); |
|
428 | - $fieldName = $fieldParts[0]; |
|
429 | - |
|
430 | - // Special when field has been instantiated without the field name and path. |
|
431 | - if (!empty($this->instances[$fieldName])) { |
|
432 | - /** @var FieldService $field */ |
|
433 | - $field = $this->instances[$fieldName]; |
|
434 | - $field->setCompositeField($compositeField); |
|
435 | - } |
|
436 | - } |
|
437 | - |
|
438 | - // True for system fields such as uid, pid that don't necessarily have a TCA. |
|
439 | - if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { |
|
440 | - $this->columnTca[$fieldName] = []; |
|
441 | - } elseif (empty($this->columnTca[$fieldName])) { |
|
442 | - $message = sprintf( |
|
443 | - 'Does the field really exist? No TCA entry found for field "%s" for table "%s"', |
|
444 | - $fieldName, |
|
445 | - $this->tableName |
|
446 | - ); |
|
447 | - throw new \Exception($message, 1385554481); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - if (empty($this->instances[$fieldName])) { |
|
452 | - |
|
453 | - $instance = GeneralUtility::makeInstance( |
|
454 | - 'Fab\Vidi\Tca\FieldService', |
|
455 | - $fieldName, |
|
456 | - $this->columnTca[$fieldName], |
|
457 | - $this->tableName, |
|
458 | - $compositeField |
|
459 | - ); |
|
460 | - |
|
461 | - $this->instances[$fieldName] = $instance; |
|
462 | - } |
|
463 | - return $this->instances[$fieldName]; |
|
464 | - } |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $tca; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $columnTca; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $tableName; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $instances; |
|
42 | + |
|
43 | + /** |
|
44 | + * @throws InvalidKeyInArrayException |
|
45 | + * @param string $tableName |
|
46 | + * @return \Fab\Vidi\Tca\TableService |
|
47 | + */ |
|
48 | + public function __construct($tableName) |
|
49 | + { |
|
50 | + $this->tableName = $tableName; |
|
51 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
52 | + throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106); |
|
53 | + } |
|
54 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl']; |
|
55 | + $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns']; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Tell whether the table has a label field. |
|
60 | + * |
|
61 | + * @throws InvalidKeyInArrayException |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function hasLabelField() |
|
65 | + { |
|
66 | + return $this->has('label'); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get the label name of table name. |
|
71 | + * |
|
72 | + * @throws InvalidKeyInArrayException |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getLabelField() |
|
76 | + { |
|
77 | + $labelField = $this->get('label'); |
|
78 | + if (empty($labelField)) { |
|
79 | + throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726); |
|
80 | + } |
|
81 | + return $labelField; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Returns the translated label of the table name. |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getLabel() |
|
90 | + { |
|
91 | + $label = ''; |
|
92 | + try { |
|
93 | + $label = LocalizationUtility::translate($this->getLabelField(), ''); |
|
94 | + } catch (\InvalidArgumentException $e) { |
|
95 | + } |
|
96 | + if (empty($label)) { |
|
97 | + $label = $this->getLabelField(); |
|
98 | + } |
|
99 | + return $label; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the title of the table. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function getTitle() |
|
108 | + { |
|
109 | + $title = ''; |
|
110 | + try { |
|
111 | + $title = LocalizationUtility::translate((string)$this->get('title'), ''); |
|
112 | + } catch (\InvalidArgumentException $e) { |
|
113 | + } |
|
114 | + if (empty($title)) { |
|
115 | + $title = $this->get('title'); |
|
116 | + } |
|
117 | + return $title; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Return the "disabled" field. |
|
122 | + * |
|
123 | + * @throws InvalidKeyInArrayException |
|
124 | + * @return string|null |
|
125 | + */ |
|
126 | + public function getHiddenField() |
|
127 | + { |
|
128 | + $hiddenField = null; |
|
129 | + $enableColumns = $this->get('enablecolumns'); |
|
130 | + if (is_array($enableColumns) && !empty($enableColumns['disabled'])) { |
|
131 | + $hiddenField = $enableColumns['disabled']; |
|
132 | + } |
|
133 | + return $hiddenField; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Return the "starttime" field. |
|
138 | + * |
|
139 | + * @throws InvalidKeyInArrayException |
|
140 | + * @return string|null |
|
141 | + */ |
|
142 | + public function getStartTimeField() |
|
143 | + { |
|
144 | + $startTimeField = null; |
|
145 | + $enableColumns = $this->get('enablecolumns'); |
|
146 | + if (is_array($enableColumns) && !empty($enableColumns['starttime'])) { |
|
147 | + $startTimeField = $enableColumns['starttime']; |
|
148 | + } |
|
149 | + return $startTimeField; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Return the "endtime" field. |
|
154 | + * |
|
155 | + * @throws InvalidKeyInArrayException |
|
156 | + * @return string|null |
|
157 | + */ |
|
158 | + public function getEndTimeField() |
|
159 | + { |
|
160 | + $endTimeField = null; |
|
161 | + $enableColumns = $this->get('enablecolumns'); |
|
162 | + if (is_array($enableColumns) && !empty($enableColumns['endtime'])) { |
|
163 | + $endTimeField = $enableColumns['endtime']; |
|
164 | + } |
|
165 | + return $endTimeField; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Tells whether the table is hidden. |
|
170 | + * |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + public function isHidden() |
|
174 | + { |
|
175 | + return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Tells whether the table is not hidden. |
|
180 | + * |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + public function isNotHidden() |
|
184 | + { |
|
185 | + return !$this->isHidden(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Get the "deleted" field for the table. |
|
190 | + * |
|
191 | + * @return string|null |
|
192 | + */ |
|
193 | + public function getDeletedField() |
|
194 | + { |
|
195 | + return $this->get('delete'); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get the modification time stamp field. |
|
200 | + * |
|
201 | + * @return string|null |
|
202 | + */ |
|
203 | + public function getTimeModificationField() |
|
204 | + { |
|
205 | + return $this->get('tstamp'); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Get the creation time stamp field. |
|
210 | + * |
|
211 | + * @return string|null |
|
212 | + */ |
|
213 | + public function getTimeCreationField() |
|
214 | + { |
|
215 | + return $this->get('crdate'); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Get the language field for the table. |
|
220 | + * |
|
221 | + * @return string|null |
|
222 | + */ |
|
223 | + public function getLanguageField() |
|
224 | + { |
|
225 | + return $this->get('languageField'); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Get the field which points to the parent. |
|
230 | + * |
|
231 | + * @return string|null |
|
232 | + */ |
|
233 | + public function getLanguageParentField() |
|
234 | + { |
|
235 | + return $this->get('transOrigPointerField'); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Returns the default order in the form of a SQL segment. |
|
240 | + * |
|
241 | + * @return string|null |
|
242 | + */ |
|
243 | + public function getDefaultOrderSql() |
|
244 | + { |
|
245 | + // "sortby" typically has "sorting" as value. |
|
246 | + $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby'); |
|
247 | + return $order; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Returns the parsed default orderings. |
|
252 | + * Returns array looks like array('title' => 'ASC'); |
|
253 | + * |
|
254 | + * @return array |
|
255 | + */ |
|
256 | + public function getDefaultOrderings() |
|
257 | + { |
|
258 | + |
|
259 | + // first clean up the sql segment |
|
260 | + $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql()); |
|
261 | + $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true); |
|
262 | + |
|
263 | + $orderings = []; |
|
264 | + foreach ($defaultOrderParts as $defaultOrderPart) { |
|
265 | + $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart); |
|
266 | + if (empty($parts[1])) { |
|
267 | + $parts[1] = QueryInterface::ORDER_DESCENDING; |
|
268 | + } |
|
269 | + $orderings[$parts[0]] = $parts[1]; |
|
270 | + } |
|
271 | + |
|
272 | + return $orderings; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Returns the searchable fields. |
|
277 | + * |
|
278 | + * @return string|null |
|
279 | + */ |
|
280 | + public function getSearchFields() |
|
281 | + { |
|
282 | + return $this->get('searchFields'); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Returns an array containing the field names. |
|
287 | + * |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function getFields() |
|
291 | + { |
|
292 | + return array_keys($this->columnTca); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Returns an array containing the fields and their configuration. |
|
297 | + * |
|
298 | + * @return array |
|
299 | + */ |
|
300 | + public function getFieldsAndConfiguration() |
|
301 | + { |
|
302 | + return $this->columnTca; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Tell whether we have a field "sorting". |
|
307 | + * |
|
308 | + * @return bool |
|
309 | + */ |
|
310 | + public function hasSortableField() |
|
311 | + { |
|
312 | + return $this->has('sortby'); |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Tell whether the field exists or not. |
|
317 | + * |
|
318 | + * @param string $fieldName |
|
319 | + * @return bool |
|
320 | + */ |
|
321 | + public function hasField($fieldName) |
|
322 | + { |
|
323 | + if ($this->isComposite($fieldName)) { |
|
324 | + $parts = explode('.', $fieldName); |
|
325 | + list ($strippedFieldPath, $possibleTableName) = $parts; |
|
326 | + $hasField = isset($this->columnTca[$strippedFieldPath], $GLOBALS['TCA'][$possibleTableName]); |
|
327 | + |
|
328 | + // Continue checking that the $strippedFieldName is of type "group" |
|
329 | + if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldPath]) && count($parts) > 2) { |
|
330 | + $hasField = Tca::table($this->tableName)->field($strippedFieldPath)->isGroup(); // Group |
|
331 | + } elseif (isset($this->columnTca[$strippedFieldPath]['config']['readOnly']) && (bool)$this->columnTca[$strippedFieldPath]['config']['readOnly']) { |
|
332 | + $hasField = false; // handle case metadata.fe_groups where "fe_groups" is a tableName. |
|
333 | + } |
|
334 | + } else { |
|
335 | + $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields(), true); |
|
336 | + } |
|
337 | + return $hasField; |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Tell whether the field name contains a path, e.g. metadata.title |
|
342 | + * |
|
343 | + * @param string $fieldName |
|
344 | + * @return boolean |
|
345 | + */ |
|
346 | + public function isComposite($fieldName) |
|
347 | + { |
|
348 | + return strpos($fieldName, '.') > 0; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Tells whether the $key exists. |
|
353 | + * |
|
354 | + * @param string $key |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function has($key) |
|
358 | + { |
|
359 | + return isset($this->tca[$key]); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Tells whether the table name has "workspace" support. |
|
364 | + * |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function hasWorkspaceSupport() |
|
368 | + { |
|
369 | + return isset($this->tca['versioningWS']); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Tells whether the table name has "language" support. |
|
374 | + * |
|
375 | + * @return string |
|
376 | + */ |
|
377 | + public function hasLanguageSupport() |
|
378 | + { |
|
379 | + return isset($this->tca['languageField']); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Return configuration value given a key. |
|
384 | + * |
|
385 | + * @param string $key |
|
386 | + * @return string|null |
|
387 | + */ |
|
388 | + public function get($key) |
|
389 | + { |
|
390 | + return $this->has($key) ? $this->tca[$key] : null; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @return array |
|
395 | + */ |
|
396 | + public function getTca() |
|
397 | + { |
|
398 | + return $this->tca; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Tell whether the current BE User has access to this field. |
|
403 | + * |
|
404 | + * @return bool |
|
405 | + */ |
|
406 | + public function hasAccess() |
|
407 | + { |
|
408 | + $hasAccess = true; |
|
409 | + if ($this->isBackendMode()) { |
|
410 | + $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName); |
|
411 | + } |
|
412 | + return $hasAccess; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $fieldName |
|
417 | + * @throws \Exception |
|
418 | + * @return FieldService |
|
419 | + */ |
|
420 | + public function field($fieldName) |
|
421 | + { |
|
422 | + |
|
423 | + // In case field contains items.tx_table for field type "group" |
|
424 | + $compositeField = ''; |
|
425 | + if (strpos($fieldName, '.') !== false) { |
|
426 | + $compositeField = $fieldName; |
|
427 | + $fieldParts = explode('.', $compositeField, 2); |
|
428 | + $fieldName = $fieldParts[0]; |
|
429 | + |
|
430 | + // Special when field has been instantiated without the field name and path. |
|
431 | + if (!empty($this->instances[$fieldName])) { |
|
432 | + /** @var FieldService $field */ |
|
433 | + $field = $this->instances[$fieldName]; |
|
434 | + $field->setCompositeField($compositeField); |
|
435 | + } |
|
436 | + } |
|
437 | + |
|
438 | + // True for system fields such as uid, pid that don't necessarily have a TCA. |
|
439 | + if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { |
|
440 | + $this->columnTca[$fieldName] = []; |
|
441 | + } elseif (empty($this->columnTca[$fieldName])) { |
|
442 | + $message = sprintf( |
|
443 | + 'Does the field really exist? No TCA entry found for field "%s" for table "%s"', |
|
444 | + $fieldName, |
|
445 | + $this->tableName |
|
446 | + ); |
|
447 | + throw new \Exception($message, 1385554481); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + if (empty($this->instances[$fieldName])) { |
|
452 | + |
|
453 | + $instance = GeneralUtility::makeInstance( |
|
454 | + 'Fab\Vidi\Tca\FieldService', |
|
455 | + $fieldName, |
|
456 | + $this->columnTca[$fieldName], |
|
457 | + $this->tableName, |
|
458 | + $compositeField |
|
459 | + ); |
|
460 | + |
|
461 | + $this->instances[$fieldName] = $instance; |
|
462 | + } |
|
463 | + return $this->instances[$fieldName]; |
|
464 | + } |
|
465 | 465 | |
466 | 466 | } |
@@ -25,135 +25,135 @@ |
||
25 | 25 | class Tca implements SingletonInterface, TcaServiceInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Fields that are considered as system. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - static protected $systemFields = array( |
|
34 | - 'uid', |
|
35 | - 'pid', |
|
36 | - 'tstamp', |
|
37 | - 'crdate', |
|
38 | - 'deleted', |
|
39 | - 'hidden', |
|
40 | - 'sys_language_uid', |
|
41 | - 'l18n_parent', |
|
42 | - 'l18n_diffsource', |
|
43 | - 't3ver_oid', |
|
44 | - 't3ver_id', |
|
45 | - 't3ver_wsid', |
|
46 | - 't3ver_label', |
|
47 | - 't3ver_state', |
|
48 | - 't3ver_stage', |
|
49 | - 't3ver_count', |
|
50 | - 't3ver_tstamp', |
|
51 | - 't3_origuid', |
|
52 | - ); |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - static protected $instances; |
|
58 | - |
|
59 | - /** |
|
60 | - * Returns a class instance of a corresponding TCA service. |
|
61 | - * If the class instance does not exist, create one. |
|
62 | - * |
|
63 | - * @throws NotExistingClassException |
|
64 | - * @param string $dataType |
|
65 | - * @param string $serviceType |
|
66 | - * @return TcaServiceInterface |
|
67 | - * @throws InvalidKeyInArrayException |
|
68 | - * @throws \InvalidArgumentException |
|
69 | - */ |
|
70 | - static protected function getService($dataType, $serviceType) |
|
71 | - { |
|
72 | - if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && empty($dataType)) { |
|
73 | - |
|
74 | - /** @var ModuleLoader $moduleLoader */ |
|
75 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
76 | - $dataType = $moduleLoader->getDataType(); |
|
77 | - } |
|
78 | - |
|
79 | - if (empty(self::$instances[$dataType][$serviceType])) { |
|
80 | - $className = sprintf('Fab\Vidi\Tca\%sService', ucfirst($serviceType)); |
|
81 | - |
|
82 | - // Signal to pre-process the TCA of the given $dataType. |
|
83 | - self::emitPreProcessTcaSignal($dataType, $serviceType); |
|
84 | - |
|
85 | - $instance = GeneralUtility::makeInstance($className, $dataType, $serviceType); |
|
86 | - self::$instances[$dataType][$serviceType] = $instance; |
|
87 | - } |
|
88 | - return self::$instances[$dataType][$serviceType]; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns a "grid" service instance. |
|
93 | - * |
|
94 | - * @param string|Content $tableNameOrContentObject |
|
95 | - * @return GridService |
|
96 | - * @throws NotExistingClassException |
|
97 | - */ |
|
98 | - static public function grid($tableNameOrContentObject = '') |
|
99 | - { |
|
100 | - $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
101 | - return self::getService($tableName, self::TYPE_GRID); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns a "table" service instance ("ctrl" part of the TCA). |
|
106 | - * |
|
107 | - * @param string|Content $tableNameOrContentObject |
|
108 | - * @return TableService |
|
109 | - * @throws NotExistingClassException |
|
110 | - */ |
|
111 | - static public function table($tableNameOrContentObject = '') |
|
112 | - { |
|
113 | - $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
114 | - return self::getService($tableName, self::TYPE_TABLE); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public static function getInstanceStorage() |
|
121 | - { |
|
122 | - return self::$instances; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public static function getSystemFields() |
|
129 | - { |
|
130 | - return self::$systemFields; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Signal that is called after the content repository for a content type has been instantiated. |
|
135 | - * |
|
136 | - * @param string $dataType |
|
137 | - * @param string $serviceType |
|
138 | - * @throws InvalidSlotException |
|
139 | - * @throws InvalidSlotReturnException |
|
140 | - * @throws \InvalidArgumentException |
|
141 | - */ |
|
142 | - static protected function emitPreProcessTcaSignal($dataType, $serviceType) |
|
143 | - { |
|
144 | - self::getSignalSlotDispatcher()->dispatch(Tca::class, 'preProcessTca', array($dataType, $serviceType)); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get the SignalSlot dispatcher |
|
149 | - * |
|
150 | - * @return Dispatcher |
|
151 | - * @throws \InvalidArgumentException |
|
152 | - */ |
|
153 | - static protected function getSignalSlotDispatcher() |
|
154 | - { |
|
155 | - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
156 | - return $objectManager->get(Dispatcher::class); |
|
157 | - } |
|
28 | + /** |
|
29 | + * Fields that are considered as system. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + static protected $systemFields = array( |
|
34 | + 'uid', |
|
35 | + 'pid', |
|
36 | + 'tstamp', |
|
37 | + 'crdate', |
|
38 | + 'deleted', |
|
39 | + 'hidden', |
|
40 | + 'sys_language_uid', |
|
41 | + 'l18n_parent', |
|
42 | + 'l18n_diffsource', |
|
43 | + 't3ver_oid', |
|
44 | + 't3ver_id', |
|
45 | + 't3ver_wsid', |
|
46 | + 't3ver_label', |
|
47 | + 't3ver_state', |
|
48 | + 't3ver_stage', |
|
49 | + 't3ver_count', |
|
50 | + 't3ver_tstamp', |
|
51 | + 't3_origuid', |
|
52 | + ); |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + static protected $instances; |
|
58 | + |
|
59 | + /** |
|
60 | + * Returns a class instance of a corresponding TCA service. |
|
61 | + * If the class instance does not exist, create one. |
|
62 | + * |
|
63 | + * @throws NotExistingClassException |
|
64 | + * @param string $dataType |
|
65 | + * @param string $serviceType |
|
66 | + * @return TcaServiceInterface |
|
67 | + * @throws InvalidKeyInArrayException |
|
68 | + * @throws \InvalidArgumentException |
|
69 | + */ |
|
70 | + static protected function getService($dataType, $serviceType) |
|
71 | + { |
|
72 | + if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && empty($dataType)) { |
|
73 | + |
|
74 | + /** @var ModuleLoader $moduleLoader */ |
|
75 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
76 | + $dataType = $moduleLoader->getDataType(); |
|
77 | + } |
|
78 | + |
|
79 | + if (empty(self::$instances[$dataType][$serviceType])) { |
|
80 | + $className = sprintf('Fab\Vidi\Tca\%sService', ucfirst($serviceType)); |
|
81 | + |
|
82 | + // Signal to pre-process the TCA of the given $dataType. |
|
83 | + self::emitPreProcessTcaSignal($dataType, $serviceType); |
|
84 | + |
|
85 | + $instance = GeneralUtility::makeInstance($className, $dataType, $serviceType); |
|
86 | + self::$instances[$dataType][$serviceType] = $instance; |
|
87 | + } |
|
88 | + return self::$instances[$dataType][$serviceType]; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns a "grid" service instance. |
|
93 | + * |
|
94 | + * @param string|Content $tableNameOrContentObject |
|
95 | + * @return GridService |
|
96 | + * @throws NotExistingClassException |
|
97 | + */ |
|
98 | + static public function grid($tableNameOrContentObject = '') |
|
99 | + { |
|
100 | + $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
101 | + return self::getService($tableName, self::TYPE_GRID); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns a "table" service instance ("ctrl" part of the TCA). |
|
106 | + * |
|
107 | + * @param string|Content $tableNameOrContentObject |
|
108 | + * @return TableService |
|
109 | + * @throws NotExistingClassException |
|
110 | + */ |
|
111 | + static public function table($tableNameOrContentObject = '') |
|
112 | + { |
|
113 | + $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; |
|
114 | + return self::getService($tableName, self::TYPE_TABLE); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public static function getInstanceStorage() |
|
121 | + { |
|
122 | + return self::$instances; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public static function getSystemFields() |
|
129 | + { |
|
130 | + return self::$systemFields; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Signal that is called after the content repository for a content type has been instantiated. |
|
135 | + * |
|
136 | + * @param string $dataType |
|
137 | + * @param string $serviceType |
|
138 | + * @throws InvalidSlotException |
|
139 | + * @throws InvalidSlotReturnException |
|
140 | + * @throws \InvalidArgumentException |
|
141 | + */ |
|
142 | + static protected function emitPreProcessTcaSignal($dataType, $serviceType) |
|
143 | + { |
|
144 | + self::getSignalSlotDispatcher()->dispatch(Tca::class, 'preProcessTca', array($dataType, $serviceType)); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get the SignalSlot dispatcher |
|
149 | + * |
|
150 | + * @return Dispatcher |
|
151 | + * @throws \InvalidArgumentException |
|
152 | + */ |
|
153 | + static protected function getSignalSlotDispatcher() |
|
154 | + { |
|
155 | + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
156 | + return $objectManager->get(Dispatcher::class); |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |