diff --git a/Classes/Archivist.php b/Classes/Archivist.php index 41d00d4..1ee187f 100644 --- a/Classes/Archivist.php +++ b/Classes/Archivist.php @@ -1,4 +1,5 @@ eelEvaluationService->evaluate($sortingInstructions['condition'], ['node' => $triggeringNode]); + if ($condition !== true) { + return; + } + } if (isset($sortingInstructions['affectedNode'])) { $affectedNode = $this->eelEvaluationService->evaluate($sortingInstructions['affectedNode'], ['node' => $triggeringNode]); diff --git a/Configuration/Testing/Settings.yaml b/Configuration/Testing/Settings.yaml index 3b7dd66..79ab285 100644 --- a/Configuration/Testing/Settings.yaml +++ b/Configuration/Testing/Settings.yaml @@ -16,6 +16,9 @@ PunktDe: # or an eel expression like seen below sorting: title + # Optional: Trigger sorting only, when condition is met. Can be used to make sure that required properties are set as expected. + condition: "${node.properties.date != null}" + # In the context is evaluated first. You can define variables here which you can use in # the remaining configuration context: diff --git a/Readme.md b/Readme.md index 0712528..b253474 100644 --- a/Readme.md +++ b/Readme.md @@ -36,6 +36,9 @@ PunktDe: # or an eel expression like seen below sorting: title + # Optional: Trigger sorting only, when condition is met. Can be used to make sure that required properties are set as expected. + condition: "${node.properties.date != null}" + # In the context is evaluated first. You can define variables here which you can use in # the remaining configuration context: diff --git a/Tests/Functional/ArchivistTest.php b/Tests/Functional/ArchivistTest.php index 14229a9..09d3f21 100644 --- a/Tests/Functional/ArchivistTest.php +++ b/Tests/Functional/ArchivistTest.php @@ -1,4 +1,5 @@ assertEquals($this->nodeContextPath . '/2018/1/trigger-node', $newNode->getPath()); } + + /** + * @test + */ + public function doNotSortWhenConditionIsNotMet() + { + $triggerNode = $this->createNode('trigger-node', ['title' => 'New Article']); + $this->assertCount(0, $this->node->getChildNodes('PunktDe.Archivist.HierarchyNode')); + + $triggerNode->setProperty('date', new \DateTime('2018-01-19')); + $this->assertEquals($this->nodeContextPath . '/2018/1/trigger-node', $triggerNode->getPath()); + } + /** * @test */