Skip to content

Commit

Permalink
Merge pull request #240 from franzholz/develop
Browse files Browse the repository at this point in the history
fix that sorting in the frontend requires the TCA in the backend
  • Loading branch information
franzholz authored Feb 16, 2024
2 parents cfd1707 + 6eda58a commit 78a34b5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
5 changes: 4 additions & 1 deletion model/class.tx_ttproducts_article.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public function init($functablename): bool

$tableObj = $this->getTableObj();
$tableObj->setConfig($tableConfig);
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);

if (isset($GLOBALS['TCA'][$tableObj->getName()]['columns']['sorting'])) {
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);
}
}

return $result;
Expand Down
4 changes: 3 additions & 1 deletion model/class.tx_ttproducts_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public function init(
$cnf = GeneralUtility::makeInstance('tx_ttproducts_config');
$this->tableconf = $cnf->getTableConf($functablename);
$tableObj = $this->getTableObj();
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);
if (isset($GLOBALS['TCA'][$tableObj->getName()]['columns']['sorting'])) {
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);
}
$tablename = $this->getTablename();
$tableObj->setTCAFieldArray($tablename);

Expand Down
7 changes: 5 additions & 2 deletions model/class.tx_ttproducts_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public function init($functablename): bool
$result = parent::init($functablename);

if ($result) {
$tableObj = $this->getTableObj();
$tablename = $this->getTablename();
$this->getTableObj()->addDefaultFieldArray(['sorting' => 'sorting']);
$this->getTableObj()->setTCAFieldArray('tt_products_emails');
if (isset($GLOBALS['TCA'][$tablename]['columns']['sorting'])) {
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);
}
$tableObj->setTCAFieldArray('tt_products_emails');
}

return $result;
Expand Down
4 changes: 3 additions & 1 deletion model/class.tx_ttproducts_product.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public function init(

$tableObj = $this->getTableObj();
$tableObj->setConfig($tableConfig);
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);
if (isset($GLOBALS['TCA'][$tableObj->getName()]['columns']['sorting'])) {
$tableObj->addDefaultFieldArray(['sorting' => 'sorting']);
}
}

return $result;
Expand Down
9 changes: 7 additions & 2 deletions view/class.tx_ttproducts_list_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,12 @@ public function printView(
ksort($displayConf['header'], SORT_STRING);
}
}

$categorySorting = 'uid';
if (isset($GLOBALS['TCA'][$categoryTable->getTableObj()->getName()]['columns']['sorting'])) {
$categorySorting = 'sorting';
}

$selectConf['orderBy'] = $tableConfArray[$functablename]['orderBy'];
// performing query for display:
if (!$selectConf['orderBy']) {
Expand Down Expand Up @@ -2018,8 +2024,7 @@ public function printView(
) {
$currentCat = $row['category'];
}

$catArray = $categoryTable->getCategoryArray($row, 'sorting');
$catArray = $categoryTable->getCategoryArray($row, $categorySorting);

if (
empty($tableConfArray[$categoryfunctablename]['onlyDefaultCategory']) &&
Expand Down
7 changes: 7 additions & 0 deletions view/class.tx_ttproducts_single_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,13 @@ public function printView(
);
$count = count($orderByFieldArray);

if (
!isset($GLOBALS['TCA'][$tablename]['columns']['sorting']) &&
in_array('sorting', $orderByFieldArray)
) {
throw new RuntimeException('Error in tt_products: No "sorting" field is set in the backend for table "' . $tablename . '", but it is set in the setup of orderBy.', 1708024007);
}

if ($count) {
$bDefaultOrder = false;
$queryPrevPrefixArray = [];
Expand Down

0 comments on commit 78a34b5

Please sign in to comment.