-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Classes/ContentRepository/Transformations/FlatStructureTransformation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Jonnitto\ImagesInARow\ContentRepository\Transformations; | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
use Neos\ContentRepository\Domain\Model\NodeData; | ||
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation; | ||
use Neos\Neos\Controller\CreateContentContextTrait; | ||
|
||
/** | ||
* Move content of collections to the container | ||
*/ | ||
class FlatStructureTransformation extends AbstractTransformation | ||
{ | ||
use CreateContentContextTrait; | ||
|
||
/** | ||
* @param NodeData $node | ||
* @return boolean | ||
*/ | ||
public function isTransformable(NodeData $node) | ||
{ | ||
$numberOfChildNodes = $node->getNumberOfChildNodes('Neos.Neos:ContentCollection', $node->getWorkspace(), $node->getDimensions()); | ||
return ($numberOfChildNodes > 0); | ||
} | ||
|
||
/** | ||
* @param NodeData $node | ||
* @return void | ||
*/ | ||
public function execute(NodeData $node) | ||
{ | ||
$contentContext = $this->createContentContext('live', []); | ||
$containerNode = $contentContext->getNodeByIdentifier($node->getIdentifier()); | ||
$contentCollections = $containerNode->getChildNodes('Neos.Neos:ContentCollection'); | ||
|
||
foreach ($contentCollections as $contentCollection) { | ||
/** @var NodeInterface $contentCollection */ | ||
if ($contentCollection->hasChildNodes()) { | ||
$this->moveChildNodes($contentCollection->getChildNodes(), $containerNode); | ||
$contentCollection->remove(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param array $children | ||
* @param NodeInterface $container | ||
*/ | ||
protected function moveChildNodes(array $children, NodeInterface $container) | ||
{ | ||
foreach ($children as $childNode) { | ||
if ($childNode instanceof NodeInterface) { | ||
/** @var NodeInterface $childNode */ | ||
$childNode->moveInto($container); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
up: | ||
comments: 'Migrate content collection of images to a flat structure' | ||
migration: | ||
- filters: | ||
- type: 'NodeType' | ||
settings: | ||
nodeType: 'Jonnitto.ImagesInARow:Container' | ||
transformations: | ||
- type: 'Jonnitto\ImagesInARow\ContentRepository\Transformations\FlatStructureTransformation' | ||
settings: [] | ||
down: | ||
comments: 'No down migration available' |