Skip to content

Commit

Permalink
[FEATURE] Enable sorting for category menu
Browse files Browse the repository at this point in the history
A editor con now select the sorting of the category
menu using either the event plugin or by TypoScript.

Refs #820
  • Loading branch information
derhansen committed Feb 1, 2021
1 parent 6537a41 commit a356990
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public function createCategoryDemandObjectFromSettings(array $settings)
$demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
$demand->setCategories($settings['categoryMenu']['categories']);
$demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']);
$demand->setOrderField($settings['categoryMenu']['orderField'] ?? 'uid');
$demand->setOrderDirection($settings['categoryMenu']['orderDirection'] ?? 'asc');

return $demand;
}
Expand Down
46 changes: 46 additions & 0 deletions Classes/Domain/Model/Dto/CategoryDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class CategoryDemand extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
const ORDER_FIELD_ALLOWED = ['title', 'uid', 'sorting'];

/**
* Storage page
*
Expand Down Expand Up @@ -44,6 +46,16 @@ class CategoryDemand extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
protected $includeSubcategories = false;

/**
* @var string
*/
protected $orderField = 'uid';

/**
* @var string
*/
protected $orderDirection = 'asc';

/**
* Sets the storage page
*
Expand Down Expand Up @@ -123,4 +135,38 @@ public function setIncludeSubcategories($includeSubcategories)
{
$this->includeSubcategories = $includeSubcategories;
}



/**
* @return string
*/
public function getOrderDirection(): string
{
return $this->orderDirection;
}

/**
* @param string $orderDirection
*/
public function setOrderDirection(string $orderDirection): void
{
$this->orderDirection = $orderDirection;
}

/**
* @return string
*/
public function getOrderField(): string
{
return $this->orderField;
}

/**
* @param string $orderField
*/
public function setOrderField(string $orderField): void
{
$this->orderField = $orderField;
}
}
11 changes: 11 additions & 0 deletions Classes/Domain/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

namespace DERHANSEN\SfEventMgt\Domain\Repository;

use DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand;
use DERHANSEN\SfEventMgt\Service\CategoryService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;

/**
* The repository for Categories
Expand Down Expand Up @@ -54,6 +56,15 @@ public function findDemanded($demand)
$query->matching($query->logicalAnd($constraints));
}

if ($demand->getOrderField() !== '' && $demand->getOrderDirection() !== '' &&
in_array($demand->getOrderField(), CategoryDemand::ORDER_FIELD_ALLOWED, true)
) {
$orderings[$demand->getOrderField()] = ((strtolower($demand->getOrderDirection()) == 'desc') ?
QueryInterface::ORDER_DESCENDING :
QueryInterface::ORDER_ASCENDING);
$query->setOrderings($orderings);
}

return $query->execute();
}
}
48 changes: 45 additions & 3 deletions Configuration/FlexForms/Flexform_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@
<type>array</type>
<el>

<!-- category -->
<settings.categoryMenu.categories>
<TCEforms>
<label>LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_categorymenu.categories</label>
Expand All @@ -841,7 +840,6 @@
</TCEforms>
</settings.categoryMenu.categories>

<!-- disable overrideDemand -->
<settings.categoryMenu.includeSubcategories>
<TCEforms>
<label>LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_categorymenu.includeSubcategories</label>
Expand All @@ -851,8 +849,52 @@
</TCEforms>
</settings.categoryMenu.includeSubcategories>

<settings.categoryMenu.orderField>
<TCEforms>
<label>LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderField</label>
<config>
<type>select</type>
<renderType>selectSingle</renderType>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderField.title</numIndex>
<numIndex index="1">title</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderField.uid</numIndex>
<numIndex index="1">uid</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderField.sorting</numIndex>
<numIndex index="1">sorting</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.categoryMenu.orderField>

<settings.categoryMenu.orderDirection>
<TCEforms>
<label>LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderDirection</label>
<config>
<type>select</type>
<renderType>selectSingle</renderType>
<items>
<numIndex index="0">
<numIndex index="0">LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderDirection.ascending</numIndex>
<numIndex index="1">asc</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:flexforms_general.orderDirection.descending</numIndex>
<numIndex index="1">desc</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.categoryMenu.orderDirection>

</el>
</ROOT>
</categoryMenu>
</sheets>
</T3DataStructure>
</T3DataStructure>
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Tab notification

:Key:
notification.senderName

- :Property:
settings.notification.replyToEmail

Expand Down Expand Up @@ -616,3 +616,27 @@ Tab category menu

:Key:
categoryMenu.includeSubcategories

- :Property:
Order field

:View:
List

:Description:
Order field for the category menu (internally limited to "title", "uid" and "sorting")

:Key:
categoryMenu.orderField

- :Property:
Order direction

:View:
List

:Description:
Order direction for the category menu

:Key:
categoryMenu.orderDirection
8 changes: 7 additions & 1 deletion Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
<trans-unit id="flexforms_general.orderField.title">
<source>Title</source>
</trans-unit>
<trans-unit id="flexforms_general.orderField.uid">
<source>Record ID</source>
</trans-unit>
<trans-unit id="flexforms_general.orderField.sorting">
<source>Sorting in TYPO3</source>
</trans-unit>
<trans-unit id="flexforms_general.orderField.startdate">
<source>Start date</source>
</trans-unit>
Expand Down Expand Up @@ -407,4 +413,4 @@
</trans-unit>
</body>
</file>
</xliff>
</xliff>
34 changes: 34 additions & 0 deletions Tests/Unit/Domain/Model/Dto/CategoryDemandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,38 @@ public function setIncludeSubcategoriesSetsValueForBoolean()
$this->subject->setIncludeSubcategories(true);
self::assertTrue($this->subject->getIncludeSubcategories());
}

/**
* @test
*/
public function orderFieldReturnsDefaultValue()
{
$this->assertSame('uid', $this->subject->getOrderField());
}

/**
* @test
*/
public function orderFieldCanBeSet()
{
$this->subject->setOrderField('title');
$this->assertSame('title', $this->subject->getOrderField());
}

/**
* @test
*/
public function orderDirectionReturnsDefaultValue()
{
$this->assertSame('asc', $this->subject->getOrderDirection());
}

/**
* @test
*/
public function orderDirectionCanBeSet()
{
$this->subject->setOrderDirection('desc');
$this->assertSame('desc', $this->subject->getOrderDirection());
}
}

0 comments on commit a356990

Please sign in to comment.