c280868bbbe86dff0369b88ba0799c0cc51861b6
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Element / RadioElement.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Element;
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
17 /**
18 * Generation of TCEform elements of the type "radio"
19 */
20 class RadioElement extends AbstractFormElement {
21
22 /**
23 * This will render a series of radio buttons.
24 *
25 * @param string $table The table name of the record
26 * @param string $field The field name which this element is supposed to edit
27 * @param array $row The record data array where the value(s) for the field can be found
28 * @param array $additionalInformation An array with additional configuration options.
29 * @return string The HTML code for the TCEform field
30 */
31 public function render($table, $field, $row, &$additionalInformation) {
32 $config = $additionalInformation['fieldConf']['config'];
33 $item = '';
34 $disabled = '';
35 if ($this->isRenderReadonly() || $config['readOnly']) {
36 $disabled = ' disabled';
37 }
38
39 // Get items for the array
40 $selectedItems = $this->formEngine->initItemArray($additionalInformation['fieldConf']);
41 if ($config['itemsProcFunc']) {
42 $selectedItems = $this->formEngine->procItems(
43 $selectedItems,
44 $additionalInformation['fieldTSConfig']['itemsProcFunc.'],
45 $config,
46 $table,
47 $row,
48 $field
49 );
50 }
51
52 // Traverse the items, making the form elements
53 foreach ($selectedItems as $checkbox => $selectedItem) {
54 $radioId = htmlspecialchars($additionalInformation['itemFormElID'] . '_' . $checkbox);
55 $radioOnClick = implode('', $additionalInformation['fieldChangeFunc']);
56 $radioChecked = (string)$selectedItem[1] === (string)$additionalInformation['itemFormElValue'] ? ' checked="checked"' : '';
57 $item .= '<div class="radio' . $disabled . '">'
58 . '<label for="' . $radioId . '">'
59 . '<input '
60 . 'type="radio" '
61 . 'class="' . $this->cssClassTypeElementPrefix . 'radio" '
62 . 'name="' . htmlspecialchars($additionalInformation['itemFormElName']) . '" '
63 . 'id="' . $radioId . '" '
64 . 'value="' . htmlspecialchars($selectedItem[1]) . '" '
65 . $radioChecked . ' '
66 . $additionalInformation['onFocus'] . ' '
67 . $disabled . ' '
68 . 'onclick="' . htmlspecialchars($radioOnClick) . '" '
69 . '/>'
70 . htmlspecialchars($selectedItem[0])
71 . '</label>'
72 . '</div>';
73 }
74 return $item;
75 }
76
77 }