Skip to content

Instantly share code, notes, and snippets.

@aertmann
Created August 15, 2012 14:33
Show Gist options
  • Save aertmann/3360629 to your computer and use it in GitHub Desktop.
Save aertmann/3360629 to your computer and use it in GitHub Desktop.
/**
* Finds the nearest parent folder node of the provided node by looping recursively trough
* the node's parent nodes and checking if they are a sub content type of TYPO3.TYPO3CR:Folder
*
* @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node
* @return \TYPO3\TYPO3CR\Domain\Model\NodeInterface|NULL
*/
protected function findNextParentFolderNode(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node) {
$folderTypes = $this->contentTypeManager->getSubContentTypes('TYPO3.TYPO3CR:Folder');
$check = function($node) use ($folderTypes) {
if (array_key_exists($node->getContentType(), $folderTypes)) {
return TRUE;
}
};
if ($check($node, $folderTypes)) {
return $node;
}
while ($node = $node->getParent()) {
if ($check($node, $folderTypes)) {
return $node;
}
}
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment