Completed
Push — master ( 5c161a...b70884 )
by Fabien
52:39
created
Classes/Controller/ClipboardController.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -20,77 +20,77 @@
 block discarded – undo
20 20
  */
21 21
 class ClipboardController extends ActionController
22 22
 {
23
-    /**
24
-     * Save data into the clipboard.
25
-     *
26
-     * @param array $matches
27
-     * @return string
28
-     */
29
-    public function saveAction(array $matches = array()): ResponseInterface
30
-    {
31
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
32
-        $this->getClipboardService()->save($matcher);
23
+	/**
24
+	 * Save data into the clipboard.
25
+	 *
26
+	 * @param array $matches
27
+	 * @return string
28
+	 */
29
+	public function saveAction(array $matches = array()): ResponseInterface
30
+	{
31
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
32
+		$this->getClipboardService()->save($matcher);
33 33
 
34
-        // Fetch objects via the Content Service.
35
-        $contentService = $this->getContentService()->findBy($matcher);
36
-        $numberOfObjects = $contentService->getNumberOfObjects();
34
+		// Fetch objects via the Content Service.
35
+		$contentService = $this->getContentService()->findBy($matcher);
36
+		$numberOfObjects = $contentService->getNumberOfObjects();
37 37
 
38
-        if ($numberOfObjects === 0) {
39
-            $this->getClipboardService()->flush();
40
-        }
38
+		if ($numberOfObjects === 0) {
39
+			$this->getClipboardService()->flush();
40
+		}
41 41
 
42
-        # Json header is not automatically sent in the BE...
43
-        $this->response->setHeader('Content-Type', 'application/json');
44
-        $this->response->sendHeaders();
45
-        return $this->jsonResponse(json_encode($numberOfObjects));
46
-    }
42
+		# Json header is not automatically sent in the BE...
43
+		$this->response->setHeader('Content-Type', 'application/json');
44
+		$this->response->sendHeaders();
45
+		return $this->jsonResponse(json_encode($numberOfObjects));
46
+	}
47 47
 
48
-    /**
49
-     * Completely flush the clipboard.
50
-     *
51
-     * @return string
52
-     */
53
-    public function flushAction(): ResponseInterface
54
-    {
55
-        $this->getClipboardService()->flush();
48
+	/**
49
+	 * Completely flush the clipboard.
50
+	 *
51
+	 * @return string
52
+	 */
53
+	public function flushAction(): ResponseInterface
54
+	{
55
+		$this->getClipboardService()->flush();
56 56
 
57
-        # Json header is not automatically sent in the BE...
58
-        $this->response->setHeader('Content-Type', 'application/json');
59
-        $this->response->sendHeaders();
60
-        return $this->jsonResponse(json_encode(true));
61
-    }
57
+		# Json header is not automatically sent in the BE...
58
+		$this->response->setHeader('Content-Type', 'application/json');
59
+		$this->response->sendHeaders();
60
+		return $this->jsonResponse(json_encode(true));
61
+	}
62 62
 
63
-    /**
64
-     * Show the content of the clipboard.
65
-     */
66
-    public function showAction(): ResponseInterface
67
-    {
68
-        // Retrieve matcher object from clipboard.
69
-        $matcher = $this->getClipboardService()->getMatcher();
63
+	/**
64
+	 * Show the content of the clipboard.
65
+	 */
66
+	public function showAction(): ResponseInterface
67
+	{
68
+		// Retrieve matcher object from clipboard.
69
+		$matcher = $this->getClipboardService()->getMatcher();
70 70
 
71
-        // Fetch objects via the Content Service.
72
-        $contentService = $this->getContentService()->findBy($matcher);
71
+		// Fetch objects via the Content Service.
72
+		$contentService = $this->getContentService()->findBy($matcher);
73 73
 
74
-        // count number of items and display it.
75
-        $this->view->assign('target', GeneralUtility::_GP('id'));
76
-        $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
77
-        $this->view->assign('objects', $contentService->getObjects());
78
-        return $this->htmlResponse();
79
-    }
74
+		// count number of items and display it.
75
+		$this->view->assign('target', GeneralUtility::_GP('id'));
76
+		$this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
77
+		$this->view->assign('objects', $contentService->getObjects());
78
+		return $this->htmlResponse();
79
+	}
80 80
 
81
-    /**
82
-     * @return ClipboardService|object
83
-     */
84
-    protected function getClipboardService()
85
-    {
86
-        return GeneralUtility::makeInstance(ClipboardService::class);
87
-    }
81
+	/**
82
+	 * @return ClipboardService|object
83
+	 */
84
+	protected function getClipboardService()
85
+	{
86
+		return GeneralUtility::makeInstance(ClipboardService::class);
87
+	}
88 88
 
89
-    /**
90
-     * @return ContentService|object
91
-     */
92
-    protected function getContentService()
93
-    {
94
-        return GeneralUtility::makeInstance(ContentService::class);
95
-    }
89
+	/**
90
+	 * @return ContentService|object
91
+	 */
92
+	protected function getContentService()
93
+	{
94
+		return GeneralUtility::makeInstance(ContentService::class);
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Classes/Behavior/SavingBehavior.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@
 block discarded – undo
16 16
  */
17 17
 class SavingBehavior extends Enumeration
18 18
 {
19
-    public const REMOVE = 'remove';
19
+	public const REMOVE = 'remove';
20 20
 
21
-    public const APPEND = 'append';
21
+	public const APPEND = 'append';
22 22
 
23
-    public const REPLACE = 'replace';
23
+	public const REPLACE = 'replace';
24 24
 }
Please login to merge, or discard this patch.
Classes/Tool/RelationAnalyserTool.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -19,86 +19,86 @@
 block discarded – undo
19 19
  */
20 20
 class RelationAnalyserTool extends AbstractTool
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
-    {
57
-        $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/RelationAnalyser/WorkResult.html';
58
-        $view = $this->initializeStandaloneView($templateNameAndPath);
49
+	/**
50
+	 * Do the job
51
+	 *
52
+	 * @param array $arguments
53
+	 * @return string
54
+	 */
55
+	public function work(array $arguments = array()): string
56
+	{
57
+		$templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/RelationAnalyser/WorkResult.html';
58
+		$view = $this->initializeStandaloneView($templateNameAndPath);
59 59
 
60
-        $dataType = $this->getModuleLoader()->getDataType();
61
-        $analyse = $this->getGridAnalyserService()->checkRelationForTable($dataType);
60
+		$dataType = $this->getModuleLoader()->getDataType();
61
+		$analyse = $this->getGridAnalyserService()->checkRelationForTable($dataType);
62 62
 
63
-        if (empty($analyse)) {
64
-            $result = 'No relation involved in this Grid.';
65
-        } else {
66
-            $result = implode("\n", $analyse);
67
-        }
63
+		if (empty($analyse)) {
64
+			$result = 'No relation involved in this Grid.';
65
+		} else {
66
+			$result = implode("\n", $analyse);
67
+		}
68 68
 
69
-        $view->assign('result', $result);
70
-        $view->assign('dataType', $dataType);
69
+		$view->assign('result', $result);
70
+		$view->assign('dataType', $dataType);
71 71
 
72
-        return $view->render();
73
-    }
72
+		return $view->render();
73
+	}
74 74
 
75
-    /**
76
-     * Tell whether the tools should be displayed according to the context.
77
-     *
78
-     * @return bool
79
-     */
80
-    public function isShown(): bool
81
-    {
82
-        return $this->getBackendUser()->isAdmin();
83
-    }
75
+	/**
76
+	 * Tell whether the tools should be displayed according to the context.
77
+	 *
78
+	 * @return bool
79
+	 */
80
+	public function isShown(): bool
81
+	{
82
+		return $this->getBackendUser()->isAdmin();
83
+	}
84 84
 
85
-    /**
86
-     * Get the Vidi Module Loader.
87
-     *
88
-     * @return ModuleLoader|object
89
-     */
90
-    protected function getModuleLoader(): ModuleLoader
91
-    {
92
-        return GeneralUtility::makeInstance(ModuleLoader::class);
93
-    }
85
+	/**
86
+	 * Get the Vidi Module Loader.
87
+	 *
88
+	 * @return ModuleLoader|object
89
+	 */
90
+	protected function getModuleLoader(): ModuleLoader
91
+	{
92
+		return GeneralUtility::makeInstance(ModuleLoader::class);
93
+	}
94 94
 
95
-    /**
96
-     * Get the Vidi Module Loader.
97
-     *
98
-     * @return GridAnalyserService|object
99
-     */
100
-    protected function getGridAnalyserService()
101
-    {
102
-        return GeneralUtility::makeInstance(GridAnalyserService::class);
103
-    }
95
+	/**
96
+	 * Get the Vidi Module Loader.
97
+	 *
98
+	 * @return GridAnalyserService|object
99
+	 */
100
+	protected function getGridAnalyserService()
101
+	{
102
+		return GeneralUtility::makeInstance(GridAnalyserService::class);
103
+	}
104 104
 }
Please login to merge, or discard this patch.
Classes/Tool/ToolInterface.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -14,32 +14,32 @@
 block discarded – undo
14 14
  */
15 15
 interface ToolInterface
16 16
 {
17
-    /**
18
-     * Display the title of the tool on the welcome screen.
19
-     *
20
-     * @return string
21
-     */
22
-    public function getTitle();
17
+	/**
18
+	 * Display the title of the tool on the welcome screen.
19
+	 *
20
+	 * @return string
21
+	 */
22
+	public function getTitle();
23 23
 
24
-    /**
25
-     * Display the description of the tool on the welcome screen.
26
-     *
27
-     * @return string
28
-     */
29
-    public function getDescription();
24
+	/**
25
+	 * Display the description of the tool on the welcome screen.
26
+	 *
27
+	 * @return string
28
+	 */
29
+	public function getDescription();
30 30
 
31
-    /**
32
-     * Do the job.
33
-     *
34
-     * @param array $arguments
35
-     * @return string
36
-     */
37
-    public function work(array $arguments = array());
31
+	/**
32
+	 * Do the job.
33
+	 *
34
+	 * @param array $arguments
35
+	 * @return string
36
+	 */
37
+	public function work(array $arguments = array());
38 38
 
39
-    /**
40
-     * Tell whether the tools should be displayed.
41
-     *
42
-     * @return bool
43
-     */
44
-    public function isShown();
39
+	/**
40
+	 * Tell whether the tools should be displayed.
41
+	 *
42
+	 * @return bool
43
+	 */
44
+	public function isShown();
45 45
 }
Please login to merge, or discard this patch.
Classes/Tool/AbstractTool.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -18,40 +18,40 @@
 block discarded – undo
18 18
  */
19 19
 abstract class AbstractTool implements ToolInterface
20 20
 {
21
-    /**
22
-     * @param string $templateNameAndPath
23
-     * @return StandaloneView
24
-     * @throws \InvalidArgumentException
25
-     */
26
-    protected function initializeStandaloneView($templateNameAndPath)
27
-    {
28
-        $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath);
21
+	/**
22
+	 * @param string $templateNameAndPath
23
+	 * @return StandaloneView
24
+	 * @throws \InvalidArgumentException
25
+	 */
26
+	protected function initializeStandaloneView($templateNameAndPath)
27
+	{
28
+		$templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath);
29 29
 
30
-        /** @var StandaloneView $view */
31
-        $view = GeneralUtility::makeInstance(StandaloneView::class);
30
+		/** @var StandaloneView $view */
31
+		$view = GeneralUtility::makeInstance(StandaloneView::class);
32 32
 
33
-        $view->setTemplatePathAndFilename($templateNameAndPath);
34
-        return $view;
35
-    }
33
+		$view->setTemplatePathAndFilename($templateNameAndPath);
34
+		return $view;
35
+	}
36 36
 
37
-    /**
38
-     * Returns an instance of the current Backend User.
39
-     *
40
-     * @return BackendUserAuthentication
41
-     */
42
-    protected function getBackendUser()
43
-    {
44
-        return $GLOBALS['BE_USER'];
45
-    }
37
+	/**
38
+	 * Returns an instance of the current Backend User.
39
+	 *
40
+	 * @return BackendUserAuthentication
41
+	 */
42
+	protected function getBackendUser()
43
+	{
44
+		return $GLOBALS['BE_USER'];
45
+	}
46 46
 
47
-    /**
48
-     * Get the Vidi Module Loader.
49
-     *
50
-     * @return ModuleLoader
51
-     * @throws \InvalidArgumentException
52
-     */
53
-    protected function getModuleLoader()
54
-    {
55
-        return GeneralUtility::makeInstance(ModuleLoader::class);
56
-    }
47
+	/**
48
+	 * Get the Vidi Module Loader.
49
+	 *
50
+	 * @return ModuleLoader
51
+	 * @throws \InvalidArgumentException
52
+	 */
53
+	protected function getModuleLoader()
54
+	{
55
+		return GeneralUtility::makeInstance(ModuleLoader::class);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
Classes/Tool/ModulePreferencesTool.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -22,121 +22,121 @@
 block discarded – undo
22 22
  */
23 23
 class ModulePreferencesTool extends AbstractTool
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
-        if (isset($arguments['save'])) {
61
-            // Revert visible <-> excluded
62
-            $excludedFields = array_diff(
63
-                Tca::grid()->getAllFieldNames(),
64
-                $arguments['excluded_fields'],
65
-                $this->getExcludedFieldsFromTca()
66
-            );
67
-            $arguments['excluded_fields'] = $excludedFields;
68
-            $this->getModulePreferences()->save($arguments);
69
-        }
70
-
71
-        $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/WorkResult.html';
72
-        $view = $this->initializeStandaloneView($templateNameAndPath);
73
-
74
-        $view->assign('title', Tca::table($this->getModuleLoader()->getDataType())->getTitle());
75
-
76
-        // Fetch the menu of visible items.
77
-        $menuVisibleItems = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS);
78
-        $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS, $menuVisibleItems);
79
-
80
-        // Fetch the default number of menu visible items.
81
-        $menuDefaultVisible = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT);
82
-        $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT, $menuDefaultVisible);
83
-
84
-        // Get the visible columns
85
-        $view->assign('columns', Tca::grid()->getAllFieldNames());
86
-
87
-        return $view->render();
88
-    }
89
-
90
-    /**
91
-     * @return array
92
-     */
93
-    protected function getExcludedFieldsFromTca()
94
-    {
95
-        $tca = Tca::grid()->getTca();
96
-        $excludedFields = [];
97
-        if (!empty($tca['excluded_fields'])) {
98
-            $excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], true);
99
-        } elseif (!empty($tca['export']['excluded_fields'])) { // only for export for legacy reason.
100
-            $excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], true);
101
-        }
102
-        return $excludedFields;
103
-    }
104
-
105
-    /**
106
-     * Tell whether the tools should be displayed according to the context.
107
-     *
108
-     * @return bool
109
-     */
110
-    public function isShown()
111
-    {
112
-        return $this->getBackendUser()->isAdmin();
113
-    }
114
-
115
-    /**
116
-     * Get the Vidi Module Loader.
117
-     *
118
-     * @return ModuleLoader|object
119
-     */
120
-    protected function getModuleLoader()
121
-    {
122
-        return GeneralUtility::makeInstance(ModuleLoader::class);
123
-    }
124
-
125
-    /**
126
-     * @return ModulePreferences|object
127
-     */
128
-    protected function getModulePreferences()
129
-    {
130
-        return GeneralUtility::makeInstance(ModulePreferences::class);
131
-    }
132
-
133
-    /**
134
-     * Get the Vidi Module Loader.
135
-     *
136
-     * @return GridAnalyserService|object
137
-     */
138
-    protected function getGridAnalyserService()
139
-    {
140
-        return GeneralUtility::makeInstance(GridAnalyserService::class);
141
-    }
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
+		if (isset($arguments['save'])) {
61
+			// Revert visible <-> excluded
62
+			$excludedFields = array_diff(
63
+				Tca::grid()->getAllFieldNames(),
64
+				$arguments['excluded_fields'],
65
+				$this->getExcludedFieldsFromTca()
66
+			);
67
+			$arguments['excluded_fields'] = $excludedFields;
68
+			$this->getModulePreferences()->save($arguments);
69
+		}
70
+
71
+		$templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/WorkResult.html';
72
+		$view = $this->initializeStandaloneView($templateNameAndPath);
73
+
74
+		$view->assign('title', Tca::table($this->getModuleLoader()->getDataType())->getTitle());
75
+
76
+		// Fetch the menu of visible items.
77
+		$menuVisibleItems = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS);
78
+		$view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS, $menuVisibleItems);
79
+
80
+		// Fetch the default number of menu visible items.
81
+		$menuDefaultVisible = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT);
82
+		$view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT, $menuDefaultVisible);
83
+
84
+		// Get the visible columns
85
+		$view->assign('columns', Tca::grid()->getAllFieldNames());
86
+
87
+		return $view->render();
88
+	}
89
+
90
+	/**
91
+	 * @return array
92
+	 */
93
+	protected function getExcludedFieldsFromTca()
94
+	{
95
+		$tca = Tca::grid()->getTca();
96
+		$excludedFields = [];
97
+		if (!empty($tca['excluded_fields'])) {
98
+			$excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], true);
99
+		} elseif (!empty($tca['export']['excluded_fields'])) { // only for export for legacy reason.
100
+			$excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], true);
101
+		}
102
+		return $excludedFields;
103
+	}
104
+
105
+	/**
106
+	 * Tell whether the tools should be displayed according to the context.
107
+	 *
108
+	 * @return bool
109
+	 */
110
+	public function isShown()
111
+	{
112
+		return $this->getBackendUser()->isAdmin();
113
+	}
114
+
115
+	/**
116
+	 * Get the Vidi Module Loader.
117
+	 *
118
+	 * @return ModuleLoader|object
119
+	 */
120
+	protected function getModuleLoader()
121
+	{
122
+		return GeneralUtility::makeInstance(ModuleLoader::class);
123
+	}
124
+
125
+	/**
126
+	 * @return ModulePreferences|object
127
+	 */
128
+	protected function getModulePreferences()
129
+	{
130
+		return GeneralUtility::makeInstance(ModulePreferences::class);
131
+	}
132
+
133
+	/**
134
+	 * Get the Vidi Module Loader.
135
+	 *
136
+	 * @return GridAnalyserService|object
137
+	 */
138
+	protected function getGridAnalyserService()
139
+	{
140
+		return GeneralUtility::makeInstance(GridAnalyserService::class);
141
+	}
142 142
 }
Please login to merge, or discard this patch.
Classes/Tool/ToolRegistry.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -18,173 +18,173 @@
 block discarded – undo
18 18
  */
19 19
 class ToolRegistry implements SingletonInterface
20 20
 {
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $tools = [];
25
-
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $overriddenPermissions = [];
30
-
31
-    /**
32
-     * Returns a class instance.
33
-     *
34
-     * @return \Fab\Vidi\Tool\ToolRegistry|object
35
-     */
36
-    public static function getInstance()
37
-    {
38
-        return GeneralUtility::makeInstance(\Fab\Vidi\Tool\ToolRegistry::class);
39
-    }
40
-
41
-    /**
42
-     * Register a tool for a data type.
43
-     *
44
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
45
-     * @param string $toolName class name which must implement "ToolInterface".
46
-     * @return $this
47
-     */
48
-    public function register($dataType, $toolName)
49
-    {
50
-        if (!isset($this->tools[$dataType])) {
51
-            $this->tools[$dataType] = [];
52
-        }
53
-
54
-        $this->tools[$dataType][] = $toolName;
55
-        return $this;
56
-    }
57
-
58
-    /**
59
-     * Override permissions for a tool by passing a Closure that will be evaluated when checking permissions.
60
-     *
61
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
62
-     * @param string $toolName class name which must implement "ToolInterface".
63
-     * @param $permission
64
-     * @return $this
65
-     */
66
-    public function overridePermission($dataType, $toolName, Closure $permission)
67
-    {
68
-        if (empty($this->overriddenPermissions[$dataType])) {
69
-            $this->overriddenPermissions[$dataType] = [];
70
-        }
71
-
72
-        $this->overriddenPermissions[$dataType][$toolName] = $permission;
73
-        return $this;
74
-    }
75
-
76
-    /**
77
-     * Un-Register a tool for a given data type.
78
-     *
79
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
80
-     * @param string $toolName class name which must implement "ToolInterface".
81
-     * @return $this
82
-     */
83
-    public function unRegister($dataType, $toolName)
84
-    {
85
-        if ($this->hasTools($dataType, $toolName)) {
86
-            $toolPosition = array_search($toolName, $this->tools['*']);
87
-            if ($toolPosition !== false) {
88
-                unset($this->tools['*'][$toolPosition]);
89
-            }
90
-
91
-            $toolPosition = array_search($toolName, $this->tools[$dataType]);
92
-            if ($toolPosition !== false) {
93
-                unset($this->tools[$dataType][$toolPosition]);
94
-            }
95
-        }
96
-
97
-        return $this;
98
-    }
99
-
100
-    /**
101
-     * Tell whether the given data type has any tools registered.
102
-     *
103
-     * @param string $dataType
104
-     * @return bool
105
-     */
106
-    public function hasAnyTools($dataType)
107
-    {
108
-        $tools = $this->getTools($dataType);
109
-        return !empty($tools);
110
-    }
111
-
112
-    /**
113
-     * Tell whether the given data type has this $tool.
114
-     *
115
-     * @param string $dataType
116
-     * @param string $tool
117
-     * @return bool
118
-     */
119
-    public function hasTools($dataType, $tool)
120
-    {
121
-        return in_array($tool, $this->tools['*']) || in_array($tool, $this->tools[$dataType]);
122
-    }
123
-
124
-    /**
125
-     * Tell whether the given tool is allowed for this data type.
126
-     *
127
-     * @param string $dataType
128
-     * @param string $toolName
129
-     * @return bool
130
-     */
131
-    public function isAllowed($dataType, $toolName)
132
-    {
133
-        $isAllowed = false;
134
-
135
-        if ($this->hasTools($dataType, $toolName)) {
136
-            $permission = $this->getOverriddenPermission($dataType, $toolName);
137
-            if (!is_null($permission)) {
138
-                $isAllowed = $permission();
139
-            } else {
140
-                /** @var ToolInterface $toolName */
141
-                $toolName = GeneralUtility::makeInstance($toolName);
142
-                $isAllowed = $toolName->isShown();
143
-            }
144
-        }
145
-        return $isAllowed;
146
-    }
147
-
148
-    /**
149
-     * Get Registered tools.
150
-     *
151
-     * @param string $dataType
152
-     * @return ToolInterface[]
153
-     */
154
-    public function getTools($dataType)
155
-    {
156
-        $tools = [];
157
-
158
-        foreach (array($dataType, '*') as $toolSource) {
159
-            if (isset($this->tools[$toolSource])) {
160
-                $toolNames = $this->tools[$toolSource];
161
-
162
-                foreach ($toolNames as $toolName) {
163
-                    /** @var ToolInterface $tool */
164
-                    if ($this->isAllowed($dataType, $toolName)) {
165
-                        $tools[] = GeneralUtility::makeInstance($toolName);
166
-                    }
167
-                }
168
-            }
169
-        }
170
-        return $tools;
171
-    }
172
-
173
-    /**
174
-     * Get the proper permission for a tool.
175
-     *
176
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
177
-     * @param string $toolName class name which must implement "ToolInterface".
178
-     * @return null|Closure
179
-     */
180
-    protected function getOverriddenPermission($dataType, $toolName)
181
-    {
182
-        $permission = null;
183
-        if (isset($this->overriddenPermissions[$dataType][$toolName])) {
184
-            $permission = $this->overriddenPermissions[$dataType][$toolName];
185
-        } elseif (isset($this->overriddenPermissions['*'][$toolName])) {
186
-            $permission = $this->overriddenPermissions['*'][$toolName];
187
-        }
188
-        return $permission;
189
-    }
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $tools = [];
25
+
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $overriddenPermissions = [];
30
+
31
+	/**
32
+	 * Returns a class instance.
33
+	 *
34
+	 * @return \Fab\Vidi\Tool\ToolRegistry|object
35
+	 */
36
+	public static function getInstance()
37
+	{
38
+		return GeneralUtility::makeInstance(\Fab\Vidi\Tool\ToolRegistry::class);
39
+	}
40
+
41
+	/**
42
+	 * Register a tool for a data type.
43
+	 *
44
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
45
+	 * @param string $toolName class name which must implement "ToolInterface".
46
+	 * @return $this
47
+	 */
48
+	public function register($dataType, $toolName)
49
+	{
50
+		if (!isset($this->tools[$dataType])) {
51
+			$this->tools[$dataType] = [];
52
+		}
53
+
54
+		$this->tools[$dataType][] = $toolName;
55
+		return $this;
56
+	}
57
+
58
+	/**
59
+	 * Override permissions for a tool by passing a Closure that will be evaluated when checking permissions.
60
+	 *
61
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
62
+	 * @param string $toolName class name which must implement "ToolInterface".
63
+	 * @param $permission
64
+	 * @return $this
65
+	 */
66
+	public function overridePermission($dataType, $toolName, Closure $permission)
67
+	{
68
+		if (empty($this->overriddenPermissions[$dataType])) {
69
+			$this->overriddenPermissions[$dataType] = [];
70
+		}
71
+
72
+		$this->overriddenPermissions[$dataType][$toolName] = $permission;
73
+		return $this;
74
+	}
75
+
76
+	/**
77
+	 * Un-Register a tool for a given data type.
78
+	 *
79
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
80
+	 * @param string $toolName class name which must implement "ToolInterface".
81
+	 * @return $this
82
+	 */
83
+	public function unRegister($dataType, $toolName)
84
+	{
85
+		if ($this->hasTools($dataType, $toolName)) {
86
+			$toolPosition = array_search($toolName, $this->tools['*']);
87
+			if ($toolPosition !== false) {
88
+				unset($this->tools['*'][$toolPosition]);
89
+			}
90
+
91
+			$toolPosition = array_search($toolName, $this->tools[$dataType]);
92
+			if ($toolPosition !== false) {
93
+				unset($this->tools[$dataType][$toolPosition]);
94
+			}
95
+		}
96
+
97
+		return $this;
98
+	}
99
+
100
+	/**
101
+	 * Tell whether the given data type has any tools registered.
102
+	 *
103
+	 * @param string $dataType
104
+	 * @return bool
105
+	 */
106
+	public function hasAnyTools($dataType)
107
+	{
108
+		$tools = $this->getTools($dataType);
109
+		return !empty($tools);
110
+	}
111
+
112
+	/**
113
+	 * Tell whether the given data type has this $tool.
114
+	 *
115
+	 * @param string $dataType
116
+	 * @param string $tool
117
+	 * @return bool
118
+	 */
119
+	public function hasTools($dataType, $tool)
120
+	{
121
+		return in_array($tool, $this->tools['*']) || in_array($tool, $this->tools[$dataType]);
122
+	}
123
+
124
+	/**
125
+	 * Tell whether the given tool is allowed for this data type.
126
+	 *
127
+	 * @param string $dataType
128
+	 * @param string $toolName
129
+	 * @return bool
130
+	 */
131
+	public function isAllowed($dataType, $toolName)
132
+	{
133
+		$isAllowed = false;
134
+
135
+		if ($this->hasTools($dataType, $toolName)) {
136
+			$permission = $this->getOverriddenPermission($dataType, $toolName);
137
+			if (!is_null($permission)) {
138
+				$isAllowed = $permission();
139
+			} else {
140
+				/** @var ToolInterface $toolName */
141
+				$toolName = GeneralUtility::makeInstance($toolName);
142
+				$isAllowed = $toolName->isShown();
143
+			}
144
+		}
145
+		return $isAllowed;
146
+	}
147
+
148
+	/**
149
+	 * Get Registered tools.
150
+	 *
151
+	 * @param string $dataType
152
+	 * @return ToolInterface[]
153
+	 */
154
+	public function getTools($dataType)
155
+	{
156
+		$tools = [];
157
+
158
+		foreach (array($dataType, '*') as $toolSource) {
159
+			if (isset($this->tools[$toolSource])) {
160
+				$toolNames = $this->tools[$toolSource];
161
+
162
+				foreach ($toolNames as $toolName) {
163
+					/** @var ToolInterface $tool */
164
+					if ($this->isAllowed($dataType, $toolName)) {
165
+						$tools[] = GeneralUtility::makeInstance($toolName);
166
+					}
167
+				}
168
+			}
169
+		}
170
+		return $tools;
171
+	}
172
+
173
+	/**
174
+	 * Get the proper permission for a tool.
175
+	 *
176
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
177
+	 * @param string $toolName class name which must implement "ToolInterface".
178
+	 * @return null|Closure
179
+	 */
180
+	protected function getOverriddenPermission($dataType, $toolName)
181
+	{
182
+		$permission = null;
183
+		if (isset($this->overriddenPermissions[$dataType][$toolName])) {
184
+			$permission = $this->overriddenPermissions[$dataType][$toolName];
185
+		} elseif (isset($this->overriddenPermissions['*'][$toolName])) {
186
+			$permission = $this->overriddenPermissions['*'][$toolName];
187
+		}
188
+		return $permission;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
Classes/Tool/ConfiguredPidTool.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -19,76 +19,76 @@
 block discarded – undo
19 19
  */
20 20
 class ConfiguredPidTool extends AbstractTool
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(
30
-            '%s (%s)',
31
-            LocalizationUtility::translate('tool.configured_pid', 'vidi'),
32
-            $this->getModulePidService()->getConfiguredNewRecordPid()
33
-        );
34
-    }
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(
30
+			'%s (%s)',
31
+			LocalizationUtility::translate('tool.configured_pid', 'vidi'),
32
+			$this->getModulePidService()->getConfiguredNewRecordPid()
33
+		);
34
+	}
35 35
 
36
-    /**
37
-     * Display the description of the tool in the welcome screen.
38
-     *
39
-     * @return string
40
-     */
41
-    public function getDescription(): string
42
-    {
43
-        $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ConfiguredPid/Launcher.html';
44
-        $view = $this->initializeStandaloneView($templateNameAndPath);
45
-        $view->assignMultiple([
46
-            'sitePath' => Environment::getPublicPath() . '/',
47
-            'dataType' => $this->getModuleLoader()->getDataType(),
48
-            'configuredPid' => $this->getModulePidService()->getConfiguredNewRecordPid(),
49
-            'errors' => $this->getModulePidService()->validateConfiguredPid(),
50
-        ]);
36
+	/**
37
+	 * Display the description of the tool in the welcome screen.
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function getDescription(): string
42
+	{
43
+		$templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ConfiguredPid/Launcher.html';
44
+		$view = $this->initializeStandaloneView($templateNameAndPath);
45
+		$view->assignMultiple([
46
+			'sitePath' => Environment::getPublicPath() . '/',
47
+			'dataType' => $this->getModuleLoader()->getDataType(),
48
+			'configuredPid' => $this->getModulePidService()->getConfiguredNewRecordPid(),
49
+			'errors' => $this->getModulePidService()->validateConfiguredPid(),
50
+		]);
51 51
 
52
-        return $view->render();
53
-    }
52
+		return $view->render();
53
+	}
54 54
 
55
-    /**
56
-     * Do the job
57
-     *
58
-     * @param array $arguments
59
-     * @return string
60
-     */
61
-    public function work(array $arguments = array()): string
62
-    {
63
-        return '';
64
-    }
55
+	/**
56
+	 * Do the job
57
+	 *
58
+	 * @param array $arguments
59
+	 * @return string
60
+	 */
61
+	public function work(array $arguments = array()): string
62
+	{
63
+		return '';
64
+	}
65 65
 
66
-    /**
67
-     * Tell whether the tools should be displayed according to the context.
68
-     *
69
-     * @return bool
70
-     */
71
-    public function isShown(): bool
72
-    {
73
-        return $this->getBackendUser()->isAdmin();
74
-    }
66
+	/**
67
+	 * Tell whether the tools should be displayed according to the context.
68
+	 *
69
+	 * @return bool
70
+	 */
71
+	public function isShown(): bool
72
+	{
73
+		return $this->getBackendUser()->isAdmin();
74
+	}
75 75
 
76
-    /**
77
-     * Get the Vidi Module Loader.
78
-     *
79
-     * @return ModuleLoader|object
80
-     */
81
-    protected function getModuleLoader(): ModuleLoader
82
-    {
83
-        return GeneralUtility::makeInstance(ModuleLoader::class);
84
-    }
76
+	/**
77
+	 * Get the Vidi Module Loader.
78
+	 *
79
+	 * @return ModuleLoader|object
80
+	 */
81
+	protected function getModuleLoader(): ModuleLoader
82
+	{
83
+		return GeneralUtility::makeInstance(ModuleLoader::class);
84
+	}
85 85
 
86
-    /**
87
-     * @return ModulePidService|object
88
-     */
89
-    public function getModulePidService()
90
-    {
91
-        /** @var ModulePidService $modulePidService */
92
-        return GeneralUtility::makeInstance(ModulePidService::class);
93
-    }
86
+	/**
87
+	 * @return ModulePidService|object
88
+	 */
89
+	public function getModulePidService()
90
+	{
91
+		/** @var ModulePidService $modulePidService */
92
+		return GeneralUtility::makeInstance(ModulePidService::class);
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Classes/Module/ModulePidService.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -21,212 +21,212 @@
 block discarded – undo
21 21
  */
22 22
 class ModulePidService
23 23
 {
24
-    /**
25
-     * The data type (table)
26
-     *
27
-     * @var string
28
-     */
29
-    protected $dataType = '';
30
-
31
-    /**
32
-     * A collection of speaking error messages why the pid is invalid.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $errors = [];
37
-
38
-    /**
39
-     * ModulePidService constructor.
40
-     */
41
-    public function __construct()
42
-    {
43
-        $this->dataType = $this->getModuleLoader()->getDataType();
44
-    }
45
-
46
-    /**
47
-     * Returns a class instance
48
-     *
49
-     * @return \Fab\Vidi\Module\ModulePidService|object
50
-     */
51
-    public static function getInstance()
52
-    {
53
-        return GeneralUtility::makeInstance(self::class);
54
-    }
55
-
56
-    /**
57
-     * @return bool
58
-     */
59
-    public function isConfiguredPidValid(): bool
60
-    {
61
-        $errors = $this->validateConfiguredPid();
62
-        return empty($errors);
63
-    }
64
-
65
-    /**
66
-     * @return array
67
-     */
68
-    public function validateConfiguredPid(): array
69
-    {
70
-        $configuredPid = $this->getConfiguredNewRecordPid();
71
-        $this->validateRootLevel($configuredPid);
72
-        $this->validatePageExist($configuredPid);
73
-        $this->validateDoktype($configuredPid);
74
-        return $this->errors;
75
-    }
76
-
77
-    /**
78
-     * Return the default configured pid.
79
-     *
80
-     * @return int
81
-     */
82
-    public function getConfiguredNewRecordPid(): int
83
-    {
84
-        if (GeneralUtility::_GP(Parameter::PID)) {
85
-            $configuredPid = (int)GeneralUtility::_GP(Parameter::PID);
86
-        } else {
87
-            // Get pid from User TSConfig if any.
88
-            $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType);
89
-            $result = $this->getBackendUser()->getTSConfig($tsConfigPath);
90
-            $configuredPid = isset($result['value'])
91
-                ? $configuredPid = (int)$result['value']
92
-                : $this->getModuleLoader()->getDefaultPid();
93
-        }
94
-
95
-        return $configuredPid;
96
-    }
97
-
98
-    /**
99
-     * Check if pid is 0 and given table is allowed on root level.
100
-     *
101
-     * @param int $configuredPid
102
-     * @return void
103
-     */
104
-    protected function validateRootLevel(int $configuredPid): void
105
-    {
106
-        if ($configuredPid > 0) {
107
-            return;
108
-        }
109
-
110
-        $isRootLevel = (bool)Tca::table()->get('rootLevel');
111
-        if (!$isRootLevel) {
112
-            $this->errors[] = sprintf(
113
-                'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;',
114
-                $this->dataType
115
-            );
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Check if a page exists for the configured pid
121
-     *
122
-     * @param int $configuredPid
123
-     * @return void
124
-     */
125
-    protected function validatePageExist(int $configuredPid): void
126
-    {
127
-        if ($configuredPid === 0) {
128
-            return;
129
-        }
130
-
131
-        $page = $this->getPage($configuredPid);
132
-        if (empty($page)) {
133
-            $this->errors[] = sprintf(
134
-                'No page found for the configured page id "%s".',
135
-                $configuredPid
136
-            );
137
-        }
138
-    }
139
-
140
-    /**
141
-     * Check if configured page is a sysfolder and if it is allowed.
142
-     *
143
-     * @param int $configuredPid
144
-     * @return void
145
-     */
146
-    protected function validateDoktype(int $configuredPid): void
147
-    {
148
-        if ($configuredPid === 0) {
149
-            return;
150
-        }
151
-
152
-        $page = $this->getPage($configuredPid);
153
-        if (!empty($page)
154
-            && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER
155
-            && !$this->isTableAllowedOnStandardPages()
156
-            && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) {
157
-            $this->errors[] = sprintf(
158
-                'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.',
159
-                $configuredPid,
160
-                $this->dataType
161
-            );
162
-        }
163
-    }
164
-
165
-    /**
166
-     * Check if given table is allowed on standard pages
167
-     *
168
-     * @return bool
169
-     * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages()
170
-     */
171
-    protected function isTableAllowedOnStandardPages(): bool
172
-    {
173
-        $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']);
174
-        return in_array($this->dataType, $allowedTables, true);
175
-    }
176
-
177
-    /**
178
-     * Returns the page record of the configured pid
179
-     *
180
-     * @param int $configuredPid
181
-     * @return array
182
-     */
183
-    protected function getPage(int $configuredPid): ?array
184
-    {
185
-        $query = $this->getQueryBuilder('pages');
186
-        $query->getRestrictions()->removeAll(); // we are in BE context.
187
-
188
-        $page = $query->select('doktype')
189
-            ->from('pages')
190
-            ->where(
191
-                'deleted = 0',
192
-                'uid = ' . $configuredPid
193
-            )
194
-            ->execute()
195
-            ->fetch();
196
-
197
-        return is_array($page)
198
-            ? $page
199
-            : [];
200
-    }
201
-
202
-    /**
203
-     * @param string $tableName
204
-     * @return object|QueryBuilder
205
-     */
206
-    protected function getQueryBuilder($tableName): QueryBuilder
207
-    {
208
-        /** @var ConnectionPool $connectionPool */
209
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
210
-        return $connectionPool->getQueryBuilderForTable($tableName);
211
-    }
212
-
213
-    /**
214
-     * Returns an instance of the current Backend User.
215
-     *
216
-     * @return BackendUserAuthentication
217
-     */
218
-    protected function getBackendUser()
219
-    {
220
-        return $GLOBALS['BE_USER'];
221
-    }
222
-
223
-    /**
224
-     * Get the Vidi Module Loader.
225
-     *
226
-     * @return ModuleLoader|object
227
-     */
228
-    protected function getModuleLoader()
229
-    {
230
-        return GeneralUtility::makeInstance(ModuleLoader::class);
231
-    }
24
+	/**
25
+	 * The data type (table)
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $dataType = '';
30
+
31
+	/**
32
+	 * A collection of speaking error messages why the pid is invalid.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $errors = [];
37
+
38
+	/**
39
+	 * ModulePidService constructor.
40
+	 */
41
+	public function __construct()
42
+	{
43
+		$this->dataType = $this->getModuleLoader()->getDataType();
44
+	}
45
+
46
+	/**
47
+	 * Returns a class instance
48
+	 *
49
+	 * @return \Fab\Vidi\Module\ModulePidService|object
50
+	 */
51
+	public static function getInstance()
52
+	{
53
+		return GeneralUtility::makeInstance(self::class);
54
+	}
55
+
56
+	/**
57
+	 * @return bool
58
+	 */
59
+	public function isConfiguredPidValid(): bool
60
+	{
61
+		$errors = $this->validateConfiguredPid();
62
+		return empty($errors);
63
+	}
64
+
65
+	/**
66
+	 * @return array
67
+	 */
68
+	public function validateConfiguredPid(): array
69
+	{
70
+		$configuredPid = $this->getConfiguredNewRecordPid();
71
+		$this->validateRootLevel($configuredPid);
72
+		$this->validatePageExist($configuredPid);
73
+		$this->validateDoktype($configuredPid);
74
+		return $this->errors;
75
+	}
76
+
77
+	/**
78
+	 * Return the default configured pid.
79
+	 *
80
+	 * @return int
81
+	 */
82
+	public function getConfiguredNewRecordPid(): int
83
+	{
84
+		if (GeneralUtility::_GP(Parameter::PID)) {
85
+			$configuredPid = (int)GeneralUtility::_GP(Parameter::PID);
86
+		} else {
87
+			// Get pid from User TSConfig if any.
88
+			$tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType);
89
+			$result = $this->getBackendUser()->getTSConfig($tsConfigPath);
90
+			$configuredPid = isset($result['value'])
91
+				? $configuredPid = (int)$result['value']
92
+				: $this->getModuleLoader()->getDefaultPid();
93
+		}
94
+
95
+		return $configuredPid;
96
+	}
97
+
98
+	/**
99
+	 * Check if pid is 0 and given table is allowed on root level.
100
+	 *
101
+	 * @param int $configuredPid
102
+	 * @return void
103
+	 */
104
+	protected function validateRootLevel(int $configuredPid): void
105
+	{
106
+		if ($configuredPid > 0) {
107
+			return;
108
+		}
109
+
110
+		$isRootLevel = (bool)Tca::table()->get('rootLevel');
111
+		if (!$isRootLevel) {
112
+			$this->errors[] = sprintf(
113
+				'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;',
114
+				$this->dataType
115
+			);
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Check if a page exists for the configured pid
121
+	 *
122
+	 * @param int $configuredPid
123
+	 * @return void
124
+	 */
125
+	protected function validatePageExist(int $configuredPid): void
126
+	{
127
+		if ($configuredPid === 0) {
128
+			return;
129
+		}
130
+
131
+		$page = $this->getPage($configuredPid);
132
+		if (empty($page)) {
133
+			$this->errors[] = sprintf(
134
+				'No page found for the configured page id "%s".',
135
+				$configuredPid
136
+			);
137
+		}
138
+	}
139
+
140
+	/**
141
+	 * Check if configured page is a sysfolder and if it is allowed.
142
+	 *
143
+	 * @param int $configuredPid
144
+	 * @return void
145
+	 */
146
+	protected function validateDoktype(int $configuredPid): void
147
+	{
148
+		if ($configuredPid === 0) {
149
+			return;
150
+		}
151
+
152
+		$page = $this->getPage($configuredPid);
153
+		if (!empty($page)
154
+			&& (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER
155
+			&& !$this->isTableAllowedOnStandardPages()
156
+			&& $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) {
157
+			$this->errors[] = sprintf(
158
+				'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.',
159
+				$configuredPid,
160
+				$this->dataType
161
+			);
162
+		}
163
+	}
164
+
165
+	/**
166
+	 * Check if given table is allowed on standard pages
167
+	 *
168
+	 * @return bool
169
+	 * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages()
170
+	 */
171
+	protected function isTableAllowedOnStandardPages(): bool
172
+	{
173
+		$allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']);
174
+		return in_array($this->dataType, $allowedTables, true);
175
+	}
176
+
177
+	/**
178
+	 * Returns the page record of the configured pid
179
+	 *
180
+	 * @param int $configuredPid
181
+	 * @return array
182
+	 */
183
+	protected function getPage(int $configuredPid): ?array
184
+	{
185
+		$query = $this->getQueryBuilder('pages');
186
+		$query->getRestrictions()->removeAll(); // we are in BE context.
187
+
188
+		$page = $query->select('doktype')
189
+			->from('pages')
190
+			->where(
191
+				'deleted = 0',
192
+				'uid = ' . $configuredPid
193
+			)
194
+			->execute()
195
+			->fetch();
196
+
197
+		return is_array($page)
198
+			? $page
199
+			: [];
200
+	}
201
+
202
+	/**
203
+	 * @param string $tableName
204
+	 * @return object|QueryBuilder
205
+	 */
206
+	protected function getQueryBuilder($tableName): QueryBuilder
207
+	{
208
+		/** @var ConnectionPool $connectionPool */
209
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
210
+		return $connectionPool->getQueryBuilderForTable($tableName);
211
+	}
212
+
213
+	/**
214
+	 * Returns an instance of the current Backend User.
215
+	 *
216
+	 * @return BackendUserAuthentication
217
+	 */
218
+	protected function getBackendUser()
219
+	{
220
+		return $GLOBALS['BE_USER'];
221
+	}
222
+
223
+	/**
224
+	 * Get the Vidi Module Loader.
225
+	 *
226
+	 * @return ModuleLoader|object
227
+	 */
228
+	protected function getModuleLoader()
229
+	{
230
+		return GeneralUtility::makeInstance(ModuleLoader::class);
231
+	}
232 232
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@
 block discarded – undo
189 189
             ->from('pages')
190 190
             ->where(
191 191
                 'deleted = 0',
192
-                'uid = ' . $configuredPid
192
+                'uid = '.$configuredPid
193 193
             )
194 194
             ->execute()
195 195
             ->fetch();
Please login to merge, or discard this patch.