Example #1
0
 /**
  * This method sets the configuration for a m:n relation based on
  * the $TCA column configuration
  *
  * @param string|ColumnMap $columnMap The column map
  * @param string $columnConfiguration The column configuration from $TCA
  * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedRelationException
  * @return ColumnMap
  */
 protected function setManyToManyRelation(ColumnMap $columnMap, $columnConfiguration)
 {
     if (isset($columnConfiguration['MM'])) {
         $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY);
         $columnMap->setChildTableName($columnConfiguration['foreign_table']);
         $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where']);
         $columnMap->setRelationTableName($columnConfiguration['MM']);
         if (is_array($columnConfiguration['MM_match_fields'])) {
             $columnMap->setRelationTableMatchFields($columnConfiguration['MM_match_fields']);
         }
         if (is_array($columnConfiguration['MM_insert_fields'])) {
             $columnMap->setRelationTableInsertFields($columnConfiguration['MM_insert_fields']);
         }
         $columnMap->setRelationTableWhereStatement($columnConfiguration['MM_table_where']);
         if (!empty($columnConfiguration['MM_opposite_field'])) {
             $columnMap->setParentKeyFieldName('uid_foreign');
             $columnMap->setChildKeyFieldName('uid_local');
             $columnMap->setChildSortByFieldName('sorting_foreign');
         } else {
             $columnMap->setParentKeyFieldName('uid_local');
             $columnMap->setChildKeyFieldName('uid_foreign');
             $columnMap->setChildSortByFieldName('sorting');
         }
     } else {
         throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedRelationException('The given information to build a many-to-many-relation was not sufficient. Check your TCA definitions. mm-relations with IRRE must have at least a defined "MM" or "foreign_selector".', 1268817963);
     }
     if ($this->getControlSection($columnMap->getRelationTableName()) !== null) {
         $columnMap->setRelationTablePageIdColumnName('pid');
     }
     return $columnMap;
 }