/** * Gets the list of available columns for a given page id * * @param int $id * @return array $tcaItems */ public function getColPosListItemsParsed($id) { $tsConfig = BackendUtility::getModTSconfig($id, 'TCEFORM.tt_content.colPos'); $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config']; $tcaItems = $tcaConfig['items']; $tcaItems = FormEngineUtility::addItems($tcaItems, $tsConfig['properties']['addItems.']); if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) { $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems); } foreach (GeneralUtility::trimExplode(',', $tsConfig['properties']['removeItems'], TRUE) as $removeId) { foreach ($tcaItems as $key => $item) { if ($item[1] == $removeId) { unset($tcaItems[$key]); } } } return $tcaItems; }
/** * Modify a single FlexForm sheet according to given configuration * * @param array $sheet Flexform sheet to manipulate * @param string $table The table name * @param string $tableField The field name * @param array $tableRow The record data * @param array $sheetConf Sheet configuration * @param array $nonExcludeFields Non-exclude-fields for this sheet * @return array Modified sheet * @see \TYPO3\CMS\Backend\Form\FlexFormsHelper::modifyFlexFormDS() */ public function modifySingleFlexFormSheet(array $sheet, $table, $tableField, array $tableRow, array $sheetConf, array $nonExcludeFields) { if (empty($sheet) || empty($table) || empty($tableField) || empty($tableRow)) { return $sheet; } // Modify fields foreach ($sheet as $fieldName => $field) { // Remove excluded fields if (!$GLOBALS['BE_USER']->isAdmin() && !empty($field['TCEforms']['exclude']) && empty($nonExcludeFields[$fieldName])) { unset($sheet[$fieldName]); continue; } // Stop here if no TSConfig was found for this field if (empty($sheetConf[$fieldName]) || !is_array($sheetConf[$fieldName])) { continue; } // Remove disabled fields if (!empty($sheetConf[$fieldName]['disabled'])) { unset($sheet[$fieldName]); continue; } $fieldConf = $sheetConf[$fieldName]; $removeItems = !empty($fieldConf['removeItems']) ? GeneralUtility::trimExplode(',', $fieldConf['removeItems'], TRUE) : array(); $keepItems = !empty($fieldConf['keepItems']) ? GeneralUtility::trimExplode(',', $fieldConf['keepItems'], TRUE) : array(); $renameItems = !empty($fieldConf['altLabels']) && is_array($fieldConf['altLabels']) ? $fieldConf['altLabels'] : array(); $changeIcons = !empty($fieldConf['altIcons']) && is_array($fieldConf['altIcons']) ? $fieldConf['altIcons'] : array(); $addItems = !empty($fieldConf['addItems']) && is_array($fieldConf['addItems']) ? $fieldConf['addItems'] : array(); unset($fieldConf['removeItems']); unset($fieldConf['keepItems']); unset($fieldConf['altLabels']); unset($fieldConf['altIcons']); unset($fieldConf['addItems']); // Manipulate field if (!empty($field['TCEforms']) && is_array($field['TCEforms'])) { $sheet[$fieldName]['TCEforms'] = $field['TCEforms']; ArrayUtility::mergeRecursiveWithOverrule($sheet[$fieldName]['TCEforms'], $fieldConf); } // Manipulate only select fields, other field types will stop here if (empty($field['TCEforms']['config']['type']) || $field['TCEforms']['config']['type'] != 'select' || $field['TCEforms']['config']['renderMode'] === 'tree') { continue; } // Getting the selector box items from system $selItems = FormEngineUtility::addSelectOptionsToItemArray(FormEngineUtility::initItemArray($field['TCEforms']), $field['TCEforms'], FormEngineUtility::getTSconfigForTableRow($table, $tableRow), $tableField); // Possibly filter some items $selItems = ArrayUtility::keepItemsInArray($selItems, $keepItems, function ($value) { return $value[1]; }); // Possibly add some items $selItems = FormEngineUtility::addItems($selItems, $addItems); // Process items by a user function if (!empty($field['TCEforms']['config']['itemsProcFunc'])) { $dataPreprocessor = GeneralUtility::makeInstance(DataPreprocessor::class); $selItems = $dataPreprocessor->procItems($selItems, $fieldConf['config'], $field['TCEforms']['config'], $table, $tableRow, $tableField); } // Remove special configuration options after creating items to prevent double parsing foreach ($this->removeSelectConfig as $option) { unset($sheet[$fieldName]['TCEforms']['config'][$option]); } // Rename and remove items or change item icon in select if ((!empty($removeItems) || !empty($renameItems) || !empty($changeIcons)) && !empty($selItems) && is_array($selItems)) { foreach ($selItems as $itemKey => $itemConf) { // Option has no key, no manipulation possible if (!isset($itemConf[1])) { continue; } // Remove foreach ($removeItems as $removeKey => $removeValue) { if (strcasecmp($removeValue, $itemConf[1]) == 0) { unset($selItems[$itemKey]); unset($removeItems[$removeKey]); } } // Rename foreach ($renameItems as $renameKey => $renameValue) { if (strcasecmp($renameKey, $itemConf[1]) == 0) { $selItems[$itemKey][0] = htmlspecialchars($renameValue); unset($renameItems[$renameKey]); } } // Change icon foreach ($changeIcons as $iconKey => $iconValue) { if (strcasecmp($iconKey, $itemConf[1]) == 0) { $selItems[$itemKey][2] = $iconValue; unset($changeIcons[$iconKey]); } } } } $sheet[$fieldName]['TCEforms']['config']['items'] = $selItems; } return $sheet; }
/** * Collects the items for a select field by reading the configured * select items from the configuration and / or by collecting them * from a foreign table. * * @param string $table The table name of the record * @param string $fieldName The select field name * @param array $row The record data array where the value(s) for the field can be found * @param array $PA An array with additional configuration options. * @return array */ public static function getSelectItems($table, $fieldName, array $row, array $PA) { $config = $PA['fieldConf']['config']; // Getting the selector box items from the system $selectItems = FormEngineUtility::addSelectOptionsToItemArray(FormEngineUtility::initItemArray($PA['fieldConf']), $PA['fieldConf'], FormEngineUtility::getTSconfigForTableRow($table, $row), $fieldName); // Possibly filter some items: $selectItems = ArrayUtility::keepItemsInArray($selectItems, $PA['fieldTSConfig']['keepItems'], function ($value) { return $value[1]; }); // Possibly add some items: $selectItems = FormEngineUtility::addItems($selectItems, $PA['fieldTSConfig']['addItems.']); // Process items by a user function: if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) { $dataPreprocessor = GeneralUtility::makeInstance(DataPreprocessor::class); $selectItems = $dataPreprocessor->procItems($selectItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $fieldName); } // Possibly remove some items: $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE); foreach ($selectItems as $selectItemIndex => $selectItem) { // Checking languages and authMode: $languageDeny = FALSE; $beUserAuth = static::getBackendUserAuthentication(); if (!empty($GLOBALS['TCA'][$table]['ctrl']['languageField']) && $GLOBALS['TCA'][$table]['ctrl']['languageField'] === $fieldName && !$beUserAuth->checkLanguageAccess($selectItem[1])) { $languageDeny = TRUE; } $authModeDeny = FALSE; if ($config['type'] === 'select' && $config['authMode'] && !$beUserAuth->checkAuthMode($table, $fieldName, $selectItem[1], $config['authMode'])) { $authModeDeny = TRUE; } if (in_array($selectItem[1], $removeItems) || $languageDeny || $authModeDeny) { unset($selectItems[$selectItemIndex]); } elseif (isset($PA['fieldTSConfig']['altLabels.'][$selectItem[1]])) { $selectItems[$selectItemIndex][0] = htmlspecialchars(static::getLanguageService()->sL($PA['fieldTSConfig']['altLabels.'][$selectItem[1]])); } // Removing doktypes with no access: if (($table === 'pages' || $table === 'pages_language_overlay') && $fieldName === 'doktype') { if (!($beUserAuth->isAdmin() || GeneralUtility::inList($beUserAuth->groupData['pagetypes_select'], $selectItem[1]))) { unset($selectItems[$selectItemIndex]); } } } return $selectItems; }
/** * Get possible records. * Copied from FormEngine and modified. * * @param string $table The table name of the record * @param string $field The field name which this element is supposed to edit * @param array $row The record data array where the value(s) for the field can be found * @param array $conf An array with additional configuration options. * @param string $checkForConfField For which field in the foreign_table the possible records should be fetched * @return mixed Array of possible record items; FALSE if type is "group/db", then everything could be "possible */ protected function getPossibleRecords($table, $field, $row, $conf, $checkForConfField = 'foreign_selector') { $backendUser = $this->getBackendUserAuthentication(); $languageService = $this->getLanguageService(); // ctrl configuration from TCA: $tcaTableCtrl = $GLOBALS['TCA'][$table]['ctrl']; // Field configuration from TCA: $foreign_check = $conf[$checkForConfField]; $foreignConfig = FormEngineUtility::getInlinePossibleRecordsSelectorConfig($conf, $foreign_check); $PA = $foreignConfig['PA']; $config = $PA['fieldConf']['config']; if ($foreignConfig['type'] == 'select') { // Getting the selector box items from the system $selItems = FormEngineUtility::addSelectOptionsToItemArray(FormEngineUtility::initItemArray($PA['fieldConf']), $PA['fieldConf'], FormEngineUtility::getTSconfigForTableRow($table, $row), $field); // Possibly filter some items: $selItems = ArrayUtility::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], function ($value) { return $value[1]; }); // Possibly add some items: $selItems = FormEngineUtility::addItems($selItems, $PA['fieldTSConfig']['addItems.']); if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) { $dataPreprocessor = GeneralUtility::makeInstance(DataPreprocessor::class); $selItems = $dataPreprocessor->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field); } // Possibly remove some items: $removeItems = GeneralUtility::trimExplode(',', $PA['fieldTSConfig']['removeItems'], TRUE); foreach ($selItems as $tk => $p) { // Checking languages and authMode: $languageDeny = $tcaTableCtrl['languageField'] && (string) $tcaTableCtrl['languageField'] === $field && !$backendUser->checkLanguageAccess($p[1]); $authModeDeny = $config['type'] == 'select' && $config['authMode'] && !$backendUser->checkAuthMode($table, $field, $p[1], $config['authMode']); if (in_array($p[1], $removeItems) || $languageDeny || $authModeDeny) { unset($selItems[$tk]); } else { if (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) { $selItems[$tk][0] = htmlspecialchars($languageService->sL($PA['fieldTSConfig']['altLabels.'][$p[1]])); } if (isset($PA['fieldTSConfig']['altIcons.'][$p[1]])) { $selItems[$tk][2] = $PA['fieldTSConfig']['altIcons.'][$p[1]]; } } // Removing doktypes with no access: if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') { if (!($backendUser->isAdmin() || GeneralUtility::inList($backendUser->groupData['pagetypes_select'], $p[1]))) { unset($selItems[$tk]); } } } } else { $selItems = FALSE; } return $selItems; }