TYPO3 CMS  TYPO3_8-7
ValueSliderWizard.php
Go to the documentation of this file.
1 <?php
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 
18 
29 {
37  public function renderWizard($params)
38  {
40  $field = $params['field'];
41  if (is_array($params['row'][$field])) {
42  $value = $params['row'][$field][0];
43  } else {
44  $value = $params['row'][$field];
45  }
46  // If Slider is used in a flexform
47  if (!empty($params['flexFormPath'])) {
48  $flexFormTools = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::class);
49  $flexFormValue = $flexFormTools->getArrayValueByPath($params['flexFormPath'], $params['row'][$field]);
50  if ($flexFormValue !== null) {
51  $value = $flexFormValue;
52  }
53  }
54  $itemName = $params['itemName'];
55  // Set default values (which correspond to those of the JS component)
56  $min = 0;
57  $max = 10000;
58  // Use the range property, if defined, to set min and max values
59  if (isset($params['fieldConfig']['range'])) {
60  $min = isset($params['fieldConfig']['range']['lower']) ? (int)$params['fieldConfig']['range']['lower'] : 0;
61  $max = isset($params['fieldConfig']['range']['upper']) ? (int)$params['fieldConfig']['range']['upper'] : 10000;
62  }
63  $elementType = $params['fieldConfig']['type'];
64  $step = $params['wConf']['step'] ?: 1;
65  $width = (int)$params['wConf']['width'] ?: 400;
66  $type = 'null';
67  if (isset($params['fieldConfig']['eval'])) {
68  $eval = GeneralUtility::trimExplode(',', $params['fieldConfig']['eval'], true);
69  if (in_array('int', $eval, true)) {
70  $type = 'int';
71  $value = (int)$value;
72  } elseif (in_array('double2', $eval, true)) {
73  $type = 'double';
74  $value = (double)$value;
75  }
76  }
77  if (isset($params['fieldConfig']['items'])) {
78  $type = 'array';
79  $index = 0;
80  $itemAmount = count($params['fieldConfig']['items']);
81  for (; $index < $itemAmount; ++$index) {
82  $item = $params['fieldConfig']['items'][$index];
83  if ((string)$item[1] === $value) {
84  break;
85  }
86  }
87  $min = 0;
88  $max = $itemAmount -1;
89  $step = 1;
90  $value = $index;
91  }
92  $callbackParams = [ $params['table'], $params['row']['uid'], $params['field'], $params['itemName'] ];
93  $id = 'slider-' . $params['md5ID'];
94  $content =
95  '<div'
96  . ' id="' . $id . '"'
97  . ' data-slider-id="' . $id . '"'
98  . ' data-slider-min="' . $min . '"'
99  . ' data-slider-max="' . $max . '"'
100  . ' data-slider-step="' . htmlspecialchars($step) . '"'
101  . ' data-slider-value="' . htmlspecialchars($value) . '"'
102  . ' data-slider-value-type="' . htmlspecialchars($type) . '"'
103  . ' data-slider-item-name="' . htmlspecialchars($itemName) . '"'
104  . ' data-slider-element-type="' . htmlspecialchars($elementType) . '"'
105  . ' data-slider-callback-params="' . htmlspecialchars(json_encode($callbackParams)) . '"'
106  . ' style="width: ' . $width . 'px;"'
107  . '></div>';
108 
109  return $content;
110  }
111 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)