diff --git a/Classes/Domain/Model/Category.php b/Classes/Domain/Model/Category.php new file mode 100644 index 0000000..1b1412e --- /dev/null +++ b/Classes/Domain/Model/Category.php @@ -0,0 +1,40 @@ + + * + * 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; + } +} diff --git a/Classes/Domain/Model/Event.php b/Classes/Domain/Model/Event.php index a613211..79d5772 100644 --- a/Classes/Domain/Model/Event.php +++ b/Classes/Domain/Model/Event.php @@ -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 */ 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; } /** diff --git a/Configuration/Extbase/Persistence/Classes.php b/Configuration/Extbase/Persistence/Classes.php new file mode 100644 index 0000000..ff15775 --- /dev/null +++ b/Configuration/Extbase/Persistence/Classes.php @@ -0,0 +1,9 @@ + [ + 'tableName' => 'sys_category', + ], +]; diff --git a/Configuration/TCA/Overrides/sys_category.php b/Configuration/TCA/Overrides/sys_category.php new file mode 100644 index 0000000..4c79736 --- /dev/null +++ b/Configuration/TCA/Overrides/sys_category.php @@ -0,0 +1,16 @@ + [ + 'sorting' => [ + 'config' => [ + // Allow extbase to map this column to model + 'type' => 'passthrough', + ], + ], + ], + ]); +})('events', 'sys_category');