mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-22 04:16:10 +01:00
Use sorting of categories
Extbase will properly use mm sorting. But categories can't be sorted within the TCA tree component. Therefore it makes more sense to use actual sys_category sorting. In order to do so, we add our own model and pass the sorting. That way PHP can do the sorting. That's the easiest approach. Also events shouldn't contain to many categories. A performance impact should not be high. Relates: #8459
This commit is contained in:
parent
9a8ee30580
commit
1929a4a566
4 changed files with 74 additions and 7 deletions
40
Classes/Domain/Model/Category.php
Normal file
40
Classes/Domain/Model/Category.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Wrm\Events\Domain\Model;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\Domain\Model\Category as ExtbaseCategory;
|
||||
|
||||
/**
|
||||
* Extend original model to include furher properties.
|
||||
*/
|
||||
class Category extends ExtbaseCategory
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $sorting = 0;
|
||||
|
||||
public function getSorting(): int
|
||||
{
|
||||
return $this->sorting;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ namespace Wrm\Events\Domain\Model;
|
|||
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\Category;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
|
@ -209,7 +208,7 @@ class Event extends AbstractEntity
|
|||
/**
|
||||
* categories
|
||||
*
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
|
||||
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Category>
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
|
@ -763,12 +762,15 @@ class Event extends AbstractEntity
|
|||
$this->categories->attach($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $categories
|
||||
*/
|
||||
public function getCategories()
|
||||
public function getCategories(): array
|
||||
{
|
||||
return $this->categories;
|
||||
$categories = $this->categories->toArray();
|
||||
|
||||
usort($categories, function (Category $catA, Category $catB) {
|
||||
return $catA->getSorting() <=> $catB->getSorting();
|
||||
});
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
9
Configuration/Extbase/Persistence/Classes.php
Normal file
9
Configuration/Extbase/Persistence/Classes.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
\Wrm\Events\Domain\Model\Category::class => [
|
||||
'tableName' => 'sys_category',
|
||||
],
|
||||
];
|
16
Configuration/TCA/Overrides/sys_category.php
Normal file
16
Configuration/TCA/Overrides/sys_category.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
defined('TYPO3') or die();
|
||||
|
||||
(function (string $extKey, string $table) {
|
||||
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA'][$table], [
|
||||
'columns' => [
|
||||
'sorting' => [
|
||||
'config' => [
|
||||
// Allow extbase to map this column to model
|
||||
'type' => 'passthrough',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
})('events', 'sys_category');
|
Loading…
Reference in a new issue