/** * renderMultipleSelectWithGroup * * @test */ public function renderMultipleSelectWithGroup() { $group1 = array(1 => 'test 1', 2 => 'test 2', 3 => 'test 3'); $group2 = array(4 => 'test 4', 5 => 'test 5', 6 => 'test 6'); $htmlGenerated = tx_t3devapi_html::renderMultipleSelectWithGroup('test', array('group1' => $group1, 'group2' => $group2), array(1, 3), array('class' => 'test')); $html = '<select multiple="multiple" name="test" id="test" class="test"><optgroup label="group1"><option value="1" selected="selected">test 1</option><option value="2">test 2</option><option value="3" selected="selected">test 3</option></optgroup><optgroup label="group2"><option value="4">test 4</option><option value="5">test 5</option><option value="6">test 6</option></optgroup></select>'; $this->debug($htmlGenerated); $this->assertEquals(trim($htmlGenerated), $html); }
/** * Generate a field from a tca type "group" * * @param string $field * @param string|array $val * @return string */ public function getFieldFromTcaGroup($field, $val) { $config = $this->getFieldConfig($field); $attributes = array(); $aVal = explode(',', $val); if ($config['internal_type'] == 'file') { $content = ''; $contentList = ''; $uploadFolder = $config['uploadfolder']; if (substr($uploadFolder, -1) != '/') { $uploadFolder = $uploadFolder . '/'; } if (!empty($val)) { $contentList = '<ul>'; foreach ($aVal as $keyFile => $file) { $currentFile = $uploadFolder . $file; $attributes['id'] = tx_t3devapi_html::cleanId($this->getPrefix($field . 'del') . '[]') . $keyFile; $contentCheck = tx_t3devapi_html::renderCheckbox($this->getPrefix($field . 'del') . '[]', $file, array(), $attributes); $contentCheck .= tx_t3devapi_html::renderLabel($attributes['id'], $this->getLabel('deletefile')); $contentList .= '<li>'; if (getimagesize($currentFile) !== false) { $contentList .= '<a class="img" href="' . $currentFile . '" target="_blank">' . $this->resizeImg($currentFile, $file, '', '40', '40c') . '</a>'; } $contentList .= '<a class="path" href="' . $currentFile . '" target="_blank">' . $file . '</a>'; $contentList .= $contentCheck . '</li>'; $content .= tx_t3devapi_html::renderHidden($this->getPrefix($field) . '[]', $file, array('id' => '')); } $contentList .= '</ul>'; } // $content .= $contentList . tx_t3devapi_html::renderInputFile($this->getPrefix($field)); // prepare other input file $content .= $contentList; if (!empty($aVal[0])) { $nbToDisplay = $config['maxitems'] - count($aVal); } else { $nbToDisplay = $config['maxitems']; } for ($i = 1; $i <= $nbToDisplay; $i++) { $id = tx_t3devapi_html::cleanId($this->getPrefix($field) . '_' . $i); if ($i === 1) { $content .= tx_t3devapi_html::renderInputFile($this->getPrefix($field) . '[]', array('id' => $id)); } else { $content .= tx_t3devapi_html::renderInputFile($this->getPrefix($field) . '[]', array('style' => 'display:none;padding-top:5px;', 'id' => $id)); } } $content .= '<script type="text/javascript">'; $content .= '$(document).ready(function(){'; $content .= '$("#' . ($this->extKey . '_' . $this->pObj->cObj->data['uid'] . '_' . $field) . ' input[type=file]").on("change", function(){'; $content .= 'if ($(this).next().is("input[type=file]")) {'; $content .= 'if ($(this).val() != "") {'; $content .= '$(this).next().show();'; $content .= '} else {'; $content .= '$(this).next().hide();'; $content .= '}'; $content .= '}'; $content .= '});'; $content .= '});'; $content .= '</script>'; return $content; } if ($config['internal_type'] == 'db') { if (!empty($config['MM'])) { return 'TODO: manage MM for internal_type=db (like in tt_news)'; } $arrItems = array(); $tableItems = array(); $arrAllowed = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $config['allowed'], true); if (count($arrAllowed) == 1) { $table = $arrAllowed[0]; if ($GLOBALS['TCA'][$table]) { $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, ' . $GLOBALS['TCA'][$table]['ctrl']['label'], $table, '1 ' . $this->pObj->cObj->enableFields($table)); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $tableItems[$row['uid']] = $row[$GLOBALS['TCA'][$table]['ctrl']['label']]; } $GLOBALS['TYPO3_DB']->sql_free_result($res); } return tx_t3devapi_html::renderMultipleSelect($this->getPrefix($field) . '[]', $tableItems, $aVal, $attributes); } else { foreach ($arrAllowed as $table) { if ($GLOBALS['TCA'][$table]) { $tableItems = array(); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, ' . $GLOBALS['TCA'][$table]['ctrl']['label'], $table, '1 ' . $this->pObj->cObj->enableFields($table)); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $tableItems[$table . '_' . $row['uid']] = $row[$GLOBALS['TCA'][$table]['ctrl']['label']]; } $GLOBALS['TYPO3_DB']->sql_free_result($res); $arrItems[$table] = $tableItems; } } return tx_t3devapi_html::renderMultipleSelectWithGroup($this->getPrefix($field) . '[]', $arrItems, $aVal, $attributes); } } return $val; }