d2b0ed4a29c41852da6e0926e787fa73d8b19765
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / ProcessAvailableActionsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Xavier Perseguers <xavier@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * View helper to let 3rd-party extensions process the list of available
32 * actions for a given extension.
33 *
34 * @author Xavier Perseguers <xavier@typo3.org>
35 */
36 class ProcessAvailableActionsViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper {
37
38 const SIGNAL_ProcessActions = 'processActions';
39
40 /**
41 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
42 * @inject
43 */
44 protected $signalSlotDispatcher;
45
46 /**
47 * Processes the list of actions.
48 *
49 * @param string $extension
50 * @return string the rendered list of actions
51 */
52 public function render($extension) {
53 $html = $this->renderChildren();
54 $actions = preg_split('#\\n\\s*#s', trim($html));
55
56 $actions = $this->emitProcessActionsSignal($extension, $actions);
57
58 return implode(' ', $actions);
59 }
60
61 /**
62 * Emits a signal after the list of actions is processed
63 *
64 * @param string $extension
65 * @param array $actions
66 * @return array Modified action array
67 */
68 protected function emitProcessActionsSignal($extension, array $actions) {
69 $signalArguments = $this->signalSlotDispatcher->dispatch(
70 __CLASS__,
71 static::SIGNAL_ProcessActions,
72 array(
73 'extension' => $extension,
74 'actions' => $actions,
75 )
76 );
77 return $signalArguments[1];
78 }
79
80 }