FlexFormContainerContainer.php 5.44 KB
Newer Older
Christian Kuhn's avatar
Christian Kuhn committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
namespace TYPO3\CMS\Backend\Form\Container;

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use TYPO3\CMS\Backend\Utility\IconUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Backend\Form\NodeFactory;
Christian Kuhn's avatar
Christian Kuhn committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

/**
 * Flex form container implementation
 * This one is called by FlexFormSectionContainer and renders HTML for a single container.
 * For processing of single elements FlexFormElementContainer is called
 */
class FlexFormContainerContainer extends AbstractContainer {

	/**
	 * Entry method
	 *
	 * @return array As defined in initializeResultArray() of AbstractNode
	 */
	public function render() {
		$table = $this->globalOptions['table'];
		$row = $this->globalOptions['databaseRow'];
		$fieldName = $this->globalOptions['fieldName'];
		$flexFormFormPrefix = $this->globalOptions['flexFormFormPrefix'];
		$flexFormContainerElementCollapsed = $this->globalOptions['flexFormContainerElementCollapsed'];
		$flexFormContainerTitle = $this->globalOptions['flexFormContainerTitle'];
		$flexFormFieldIdentifierPrefix = $this->globalOptions['flexFormFieldIdentifierPrefix'];
		$parameterArray = $this->globalOptions['parameterArray'];

		// Every container adds its own part to the id prefix
		$flexFormFieldIdentifierPrefix = $flexFormFieldIdentifierPrefix . '-' . GeneralUtility::shortMd5(uniqid('id', TRUE));

		$toggleIcons = IconUtility::getSpriteIcon(
			'actions-move-down',
			array(
				'class' => 't3-flex-control-toggle-icon-open',
				'style' => $flexFormContainerElementCollapsed ? 'display: none;' : '',
			)
		);
		$toggleIcons .= IconUtility::getSpriteIcon(
			'actions-move-right',
			array(
				'class' => 't3-flex-control-toggle-icon-close',
				'style' => $flexFormContainerElementCollapsed ? '' : 'display: none;',
			)
		);

		$flexFormContainerCounter = $this->globalOptions['flexFormContainerCounter'];
		$actionFieldName = '_ACTION_FLEX_FORM'
			. $parameterArray['itemFormElName']
			. $this->globalOptions['flexFormFormPrefix']
			. '[_ACTION]'
			. '[' . $flexFormContainerCounter . ']';
		$toggleFieldName = 'data[' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'
			. $flexFormFormPrefix
			. '[' . $flexFormContainerCounter . ']'
			. '[_TOGGLE]';

		$moveAndDeleteContent = array();
		$userHasAccessToDefaultLanguage = $this->getBackendUserAuthentication()->checkLanguageAccess(0);
		if ($userHasAccessToDefaultLanguage) {
			$moveAndDeleteContent[] = '<div class="pull-right">';
			$moveAndDeleteContent[] = IconUtility::getSpriteIcon(
				'actions-move-move',
				array(
					'title' => 'Drag to Move', // @todo: hardcoded title ...
					'class' => 't3-js-sortable-handle'
				)
			);
			$moveAndDeleteContent[] = IconUtility::getSpriteIcon(
				'actions-edit-delete',
				array(
					'title' => 'Delete', // @todo: hardcoded title ...
					'class' => 't3-delete'
				)
			);
			$moveAndDeleteContent[] = '</div>';
		}

		$options = $this->globalOptions;
		$options['flexFormFieldIdentifierPrefix'] = $flexFormFieldIdentifierPrefix;
		// Append container specific stuff to field prefix
		$options['flexFormFormPrefix'] =  $flexFormFormPrefix . '[' . $flexFormContainerCounter . '][' .  $this->globalOptions['flexFormContainerName'] . '][el]';
98
		$options['renderType'] = 'flexFormElementContainer';
99
100
101
		/** @var NodeFactory $nodeFactory */
		$nodeFactory = $this->globalOptions['nodeFactory'];
		$containerContentResult = $nodeFactory->create($options)->render();
Christian Kuhn's avatar
Christian Kuhn committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

		$html = array();
		$html[] = '<div id="' . $flexFormFieldIdentifierPrefix . '" class="t3-form-field-container-flexsections t3-flex-section">';
		$html[] = 	'<input class="t3-flex-control t3-flex-control-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value="" />';
		$html[] = 	'<div class="t3-form-field-header-flexsection t3-flex-section-header">';
		$html[] = 		'<div class="pull-left">';
		$html[] = 			'<a href="#" class="t3-flex-control-toggle-button">' . $toggleIcons . '</a>';
		$html[] = 			'<span class="t3-record-title">' . $flexFormContainerTitle . '</span>';
		$html[] = 		'</div>';
		$html[] = 		implode(LF, $moveAndDeleteContent);
		$html[] = 	'</div>';
		$html[] = 	'<div class="t3-form-field-record-flexsection t3-flex-section-content"' . ($flexFormContainerElementCollapsed ? ' style="display:none;"' : '') . '>';
		$html[] = 		$containerContentResult['html'];
		$html[] = 	'</div>';
		$html[] = 	'<input';
		$html[] = 		'class="t3-flex-control t3-flex-control-toggle"';
		$html[] = 		'id="' . $flexFormFieldIdentifierPrefix . '-toggleClosed"';
		$html[] = 		'type="hidden"';
		$html[] = 		'name="' . htmlspecialchars($toggleFieldName) . '"';
		$html[] = 		'value="' . ($flexFormContainerElementCollapsed ? '1' : '0') . '"';
		$html[] = 	'/>';
		$html[] = '</div>';

		$containerContentResult['html'] = '';
		$resultArray = $this->initializeResultArray();
		$resultArray['html'] = implode(LF, $html);
		$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $containerContentResult);

		return $resultArray;
	}

	/**
	 * @return BackendUserAuthentication
	 */
	protected function getBackendUserAuthentication() {
		return $GLOBALS['BE_USER'];
	}

}