Ejemplo n.º 1
0
 /**
  * If the select field is build by a foreign_table the related UIDs
  * will be returned.
  *
  * Otherwise the label of the currently selected value will be written
  * to the alternativeFieldValue class property.
  *
  * @param array $fieldConfig The "config" section of the TCA for the current select field.
  * @param string $fieldName The name of the select field.
  * @param string $value The current value in the local record, usually a comma separated list of selected values.
  * @return array Array of related UIDs.
  */
 protected function getRelatedSelectFieldUids(array $fieldConfig, $fieldName, $value)
 {
     $relatedUids = array();
     $isTraversable = FALSE;
     if (isset($fieldConfig['foreign_table'])) {
         $isTraversable = TRUE;
         // if a foreign_table is used we pre-filter the records for performance
         $fieldConfig['foreign_table_where'] .= ' AND ' . $fieldConfig['foreign_table'] . '.uid IN (' . $value . ')';
     }
     $PA = array();
     $PA['fieldConf']['config'] = $fieldConfig;
     $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type'];
     $PA['fieldTSConfig'] = $this->formEngine->setTSconfig($this->currentTable, $this->currentRow, $fieldName);
     $PA['fieldConf']['config'] = $this->formEngine->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
     $selectItemArray = $this->formEngine->getSelectItems($this->currentTable, $fieldName, $this->currentRow, $PA);
     if ($isTraversable && count($selectItemArray)) {
         $this->currentTable = $fieldConfig['foreign_table'];
         $relatedUids = $this->getSelectedValuesFromSelectItemArray($selectItemArray, $value);
     } else {
         $selectedLabels = $this->getSelectedValuesFromSelectItemArray($selectItemArray, $value, 1, TRUE);
         if (count($selectedLabels) === 1) {
             $this->alternativeFieldValue = $selectedLabels[0];
             $this->forceAlternativeFieldValueUse = TRUE;
         }
     }
     return $relatedUids;
 }
Ejemplo n.º 2
0
 /**
  * Determine the configuration and the type of a record selector.
  *
  * @param array $conf TCA configuration of the parent(!) field
  * @return array Associative array with the keys 'PA' and 'type', both are FALSE if the selector was not valid.
  * @todo Define visibility
  */
 public function getPossibleRecordsSelectorConfig($conf, $field = '')
 {
     $foreign_table = $conf['foreign_table'];
     $foreign_selector = $conf['foreign_selector'];
     $PA = FALSE;
     $type = FALSE;
     $table = FALSE;
     $selector = FALSE;
     if ($field) {
         $PA = array();
         $PA['fieldConf'] = $GLOBALS['TCA'][$foreign_table]['columns'][$field];
         if ($PA['fieldConf'] && $conf['foreign_selector_fieldTcaOverride']) {
             \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($PA['fieldConf'], $conf['foreign_selector_fieldTcaOverride']);
         }
         $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ?: $PA['fieldConf']['config']['type'];
         // Using "form_type" locally in this script
         $PA['fieldTSConfig'] = $this->fObj->setTSconfig($foreign_table, array(), $field);
         $config = $PA['fieldConf']['config'];
         // Determine type of Selector:
         $type = $this->getPossibleRecordsSelectorType($config);
         // Return table on this level:
         $table = $type == 'select' ? $config['foreign_table'] : $config['allowed'];
         // Return type of the selector if foreign_selector is defined and points to the same field as in $field:
         if ($foreign_selector && $foreign_selector == $field && $type) {
             $selector = $type;
         }
     }
     return array('PA' => $PA, 'type' => $type, 'table' => $table, 'selector' => $selector);
 }