Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/punktDe/archivist
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellienert committed Feb 9, 2018
2 parents 09799d6 + a049cb3 commit b5e7402
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Classes/Archivist.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PunktDe\Archivist;

/*
Expand Down Expand Up @@ -67,6 +68,12 @@ class Archivist
*/
public function organizeNode(NodeInterface $triggeringNode, array $sortingInstructions)
{
if (isset($sortingInstructions['condition'])) {
$condition = $this->eelEvaluationService->evaluate($sortingInstructions['condition'], ['node' => $triggeringNode]);
if ($condition !== true) {
return;
}
}
if (isset($sortingInstructions['affectedNode'])) {
$affectedNode = $this->eelEvaluationService->evaluate($sortingInstructions['affectedNode'], ['node' => $triggeringNode]);

Expand Down
3 changes: 3 additions & 0 deletions Configuration/Testing/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions Tests/Functional/ArchivistTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PunktDe\Archivist\Tests\Functional;

/*
Expand All @@ -13,6 +14,7 @@
use Neos\ContentRepository\Domain\Model\NodeTemplate;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Tests\Functional\AbstractNodeTest;
use Neos\Eel\Exception;
use Neos\Eel\FlowQuery\FlowQuery;

class ArchivistTest extends AbstractNodeTest
Expand Down Expand Up @@ -60,6 +62,19 @@ public function simpleCreateNode()
$this->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
*/
Expand Down

0 comments on commit b5e7402

Please sign in to comment.