Ejemplo n.º 1
0
 /**
  * Add selector box items of more exotic kinds.
  *
  * @param array $items The array of items (label,value,icon)
  * @param array $fieldValue The "columns" array for the field (from TCA)
  * @param array $TSconfig TSconfig for the table/row
  * @param string $field The fieldname
  * @return array The $items array modified.
  * @internal
  */
 public static function addSelectOptionsToItemArray($items, $fieldValue, $TSconfig, $field)
 {
     $languageService = static::getLanguageService();
     // Values from foreign tables:
     if ($fieldValue['config']['foreign_table']) {
         $items = static::foreignTable($items, $fieldValue, $TSconfig, $field);
         if ($fieldValue['config']['neg_foreign_table']) {
             $items = static::foreignTable($items, $fieldValue, $TSconfig, $field, 1);
         }
     }
     // Values from a file folder:
     if ($fieldValue['config']['fileFolder']) {
         $fileFolder = GeneralUtility::getFileAbsFileName($fieldValue['config']['fileFolder']);
         if (@is_dir($fileFolder)) {
             // Configurations:
             $extList = $fieldValue['config']['fileFolder_extList'];
             $recursivityLevels = isset($fieldValue['config']['fileFolder_recursions']) ? MathUtility::forceIntegerInRange($fieldValue['config']['fileFolder_recursions'], 0, 99) : 99;
             // Get files:
             $fileFolder = rtrim($fileFolder, '/') . '/';
             $fileArr = GeneralUtility::getAllFilesAndFoldersInPath(array(), $fileFolder, $extList, 0, $recursivityLevels);
             $fileArr = GeneralUtility::removePrefixPathFromList($fileArr, $fileFolder);
             foreach ($fileArr as $fileRef) {
                 $fI = pathinfo($fileRef);
                 $icon = GeneralUtility::inList('gif,png,jpeg,jpg', strtolower($fI['extension'])) ? '../' . PathUtility::stripPathSitePrefix($fileFolder) . $fileRef : '';
                 $items[] = array($fileRef, $fileRef, $icon);
             }
         }
     }
     // If 'special' is configured:
     if ($fieldValue['config']['special']) {
         switch ($fieldValue['config']['special']) {
             case 'tables':
                 foreach ($GLOBALS['TCA'] as $theTableNames => $_) {
                     if (!$GLOBALS['TCA'][$theTableNames]['ctrl']['adminOnly']) {
                         // Icon:
                         $icon = IconUtility::mapRecordTypeToSpriteIconName($theTableNames, array());
                         // Add help text
                         $helpText = array();
                         $languageService->loadSingleTableDescription($theTableNames);
                         $helpTextArray = $GLOBALS['TCA_DESCR'][$theTableNames]['columns'][''];
                         if (!empty($helpTextArray['description'])) {
                             $helpText['description'] = $helpTextArray['description'];
                         }
                         // Item configuration:
                         $items[] = array($languageService->sL($GLOBALS['TCA'][$theTableNames]['ctrl']['title']), $theTableNames, $icon, $helpText);
                     }
                 }
                 break;
             case 'pagetypes':
                 $theTypes = $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'];
                 foreach ($theTypes as $theTypeArrays) {
                     // Icon:
                     $icon = 'empty-empty';
                     if ($theTypeArrays[1] != '--div--') {
                         $icon = IconUtility::mapRecordTypeToSpriteIconName('pages', array('doktype' => $theTypeArrays[1]));
                     }
                     // Item configuration:
                     $items[] = array($languageService->sL($theTypeArrays[0]), $theTypeArrays[1], $icon);
                 }
                 break;
             case 'exclude':
                 $theTypes = BackendUtility::getExcludeFields();
                 foreach ($theTypes as $theTypeArrays) {
                     list($theTable, $theFullField) = explode(':', $theTypeArrays[1]);
                     // If the field comes from a FlexForm, the syntax is more complex
                     $theFieldParts = explode(';', $theFullField);
                     $theField = array_pop($theFieldParts);
                     // Add header if not yet set for table:
                     if (!array_key_exists($theTable, $items)) {
                         $icon = IconUtility::mapRecordTypeToSpriteIconName($theTable, array());
                         $items[$theTable] = array($languageService->sL($GLOBALS['TCA'][$theTable]['ctrl']['title']), '--div--', $icon);
                     }
                     // Add help text
                     $helpText = array();
                     $languageService->loadSingleTableDescription($theTable);
                     $helpTextArray = $GLOBALS['TCA_DESCR'][$theTable]['columns'][$theFullField];
                     if (!empty($helpTextArray['description'])) {
                         $helpText['description'] = $helpTextArray['description'];
                     }
                     // Item configuration:
                     $items[] = array(rtrim($languageService->sL($GLOBALS['TCA'][$theTable]['columns'][$theField]['label']), ':') . ' (' . $theField . ')', $theTypeArrays[1], 'empty-empty', $helpText);
                 }
                 break;
             case 'explicitValues':
                 $theTypes = BackendUtility::getExplicitAuthFieldValues();
                 // Icons:
                 $icons = array('ALLOW' => 'status-status-permission-granted', 'DENY' => 'status-status-permission-denied');
                 // Traverse types:
                 foreach ($theTypes as $tableFieldKey => $theTypeArrays) {
                     if (is_array($theTypeArrays['items'])) {
                         // Add header:
                         $items[] = array($theTypeArrays['tableFieldLabel'], '--div--');
                         // Traverse options for this field:
                         foreach ($theTypeArrays['items'] as $itemValue => $itemContent) {
                             // Add item to be selected:
                             $items[] = array('[' . $itemContent[2] . '] ' . $itemContent[1], $tableFieldKey . ':' . preg_replace('/[:|,]/', '', $itemValue) . ':' . $itemContent[0], $icons[$itemContent[0]]);
                         }
                     }
                 }
                 break;
             case 'languages':
                 $items = array_merge($items, BackendUtility::getSystemLanguages());
                 break;
             case 'custom':
                 // Initialize:
                 $customOptions = $GLOBALS['TYPO3_CONF_VARS']['BE']['customPermOptions'];
                 if (is_array($customOptions)) {
                     foreach ($customOptions as $coKey => $coValue) {
                         if (is_array($coValue['items'])) {
                             // Add header:
                             $items[] = array($languageService->sL($coValue['header']), '--div--');
                             // Traverse items:
                             foreach ($coValue['items'] as $itemKey => $itemCfg) {
                                 // Icon:
                                 if ($itemCfg[1]) {
                                     list($icon) = FormEngineUtility::getIcon($itemCfg[1]);
                                 } else {
                                     $icon = 'empty-empty';
                                 }
                                 // Add help text
                                 $helpText = array();
                                 if (!empty($itemCfg[2])) {
                                     $helpText['description'] = $languageService->sL($itemCfg[2]);
                                 }
                                 // Add item to be selected:
                                 $items[] = array($languageService->sL($itemCfg[0]), $coKey . ':' . preg_replace('/[:|,]/', '', $itemKey), $icon, $helpText);
                             }
                         }
                     }
                 }
                 break;
             case 'modListGroup':
             case 'modListUser':
                 $loadModules = GeneralUtility::makeInstance(ModuleLoader::class);
                 $loadModules->load($GLOBALS['TBE_MODULES']);
                 $modList = $fieldValue['config']['special'] == 'modListUser' ? $loadModules->modListUser : $loadModules->modListGroup;
                 if (is_array($modList)) {
                     foreach ($modList as $theMod) {
                         // Icon:
                         $icon = $languageService->moduleLabels['tabs_images'][$theMod . '_tab'];
                         if ($icon) {
                             $icon = '../' . PathUtility::stripPathSitePrefix($icon);
                         }
                         // Add help text
                         $helpText = array('title' => $languageService->moduleLabels['labels'][$theMod . '_tablabel'], 'description' => $languageService->moduleLabels['labels'][$theMod . '_tabdescr']);
                         $label = '';
                         // Add label for main module:
                         $pp = explode('_', $theMod);
                         if (count($pp) > 1) {
                             $label .= $languageService->moduleLabels['tabs'][$pp[0] . '_tab'] . '>';
                         }
                         // Add modules own label now:
                         $label .= $languageService->moduleLabels['tabs'][$theMod . '_tab'];
                         // Item configuration:
                         $items[] = array($label, $theMod, $icon, $helpText);
                     }
                 }
                 break;
         }
     }
     return $items;
 }