[!!!][TASK] Cleanup ContextMenu classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / ContextMenu / Pagetree / Extdirect / ContextMenuConfiguration.php
1 <?php
2 namespace TYPO3\CMS\Backend\ContextMenu\Pagetree\Extdirect;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Backend\ContextMenu\ContextMenuActionCollection;
17 use TYPO3\CMS\Backend\ContextMenu\Pagetree\ContextMenuDataProvider;
18 use TYPO3\CMS\Backend\Tree\Pagetree\Commands;
19 use TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode;
20 use TYPO3\CMS\Backend\Tree\TreeNode;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Context Menu of the Page Tree
25 */
26 class ContextMenuConfiguration
27 {
28 /**
29 * Data Provider
30 *
31 * @var ContextMenuDataProvider
32 */
33 protected $dataProvider = null;
34
35 /**
36 * @param ContextMenuDataProvider $dataProvider
37 * @return void
38 */
39 public function setDataProvider(ContextMenuDataProvider $dataProvider)
40 {
41 $this->dataProvider = $dataProvider;
42 }
43
44 /**
45 * @return ContextMenuDataProvider
46 */
47 public function getDataProvider()
48 {
49 return $this->dataProvider;
50 }
51 /**
52 * Sets the data provider
53 *
54 * @return void
55 */
56 protected function initDataProvider()
57 {
58 $dataProvider = GeneralUtility::makeInstance(ContextMenuDataProvider::class);
59 $this->setDataProvider($dataProvider);
60 }
61
62 /**
63 * Returns the actions for the given node information's
64 *
65 * @param \stdClass $nodeData
66 * @return array
67 */
68 public function getActionsForNodeArray($nodeData)
69 {
70 $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
71 $node->setRecord(Commands::getNodeRecord($node->getId()));
72 $this->initDataProvider();
73 $this->dataProvider->setContextMenuType('table.' . $node->getType());
74 $actionCollection = $this->dataProvider->getActionsForNode($node);
75 $actions = array();
76 if ($actionCollection instanceof ContextMenuActionCollection) {
77 $actions = $actionCollection->toArray();
78 }
79 return $actions;
80 }
81
82 /**
83 * Unused for this implementation
84 *
85 * @see getActionsForNodeArray()
86 * @param TreeNode $node
87 * @return array
88 */
89 public function getActionsForNode(TreeNode $node)
90 {
91 }
92 }