Last active
January 13, 2021 13:42
-
-
Save aertmann/a300ac4b9abfafd5e026 to your computer and use it in GitHub Desktop.
Slide support in content collection
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
<?php | |
namespace TYPO3\NeosDemoTypo3Org\TypoScript; | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | |
/** | |
* Extended TypoScript implementation to render ContentCollections. Will render needed | |
* metadata for removed nodes and has support for slide. | |
*/ | |
class ContentCollectionImplementation extends \TYPO3\Neos\TypoScript\ContentCollectionImplementation { | |
/** | |
* Internal cache for the nodePath property. | |
* | |
* @var string | |
*/ | |
protected $nodePath; | |
/** | |
* Internal cache for the contentCollectionNode property. | |
* | |
* @var NodeInterface | |
*/ | |
protected $contentCollectionNode; | |
/** | |
* Internal cache for the slide property. | |
* | |
* @var boolean | |
*/ | |
protected $slide; | |
/** | |
* Returns the identifier of the content collection node which shall be rendered | |
* | |
* @return string | |
*/ | |
public function getNodePath() { | |
if ($this->nodePath === NULL) { | |
$this->nodePath = (string)$this->tsValue('nodePath'); | |
} | |
return $this->nodePath; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getSlide() { | |
if ($this->slide === NULL) { | |
$this->slide = (boolean)$this->tsValue('slide'); | |
} | |
return $this->slide; | |
} | |
/** | |
* @return NodeInterface | |
*/ | |
public function getContentCollectionNode() { | |
if ($this->contentCollectionNode === NULL) { | |
$currentContext = $this->tsRuntime->getCurrentContext(); | |
$this->contentCollectionNode = $currentContext['contentCollectionNode']; | |
} | |
return $this->contentCollectionNode; | |
} | |
/** | |
* @return array | |
*/ | |
public function getCollection() { | |
$contentCollectionNode = $this->getContentCollectionNode(); | |
if ($contentCollectionNode === NULL) { | |
return array(); | |
} | |
$collection = $contentCollectionNode->getChildNodes(); | |
if ($contentCollectionNode->getContext()->getWorkspaceName() !== 'live') { | |
$collection = array_merge($contentCollectionNode->getChildNodes(), $this->getRemovedChildNodes()); | |
} | |
if (count($collection) === 0 && $this->getSlide() === TRUE) { | |
$parentsQuery = new \TYPO3\Eel\FlowQuery\FlowQuery(array($contentCollectionNode)); | |
$this->contentCollectionNode = $parentsQuery->parents('[instanceof TYPO3.Neos:Document]')->first()->parent()->children($this->getNodePath())->get(0); | |
if ($this->contentCollectionNode !== NULL) { | |
$collection = $this->getCollection(); | |
} | |
} | |
return $collection; | |
} | |
} |
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
prototype(TYPO3.Neos:ContentCollection).@class = 'TYPO3\\NeosDemoTypo3Org\\TypoScript\\ContentCollectionImplementation' | |
page.body.content.aside = ContentCollection { | |
nodePath = 'aside' | |
slide = ${node.context.workspaceName == 'live' ? true : false} | |
} |
I figured out how to do it with the latest refactorings: https://gist.github.com/hhoechtl/c5e5b84261f75a8feac5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since many things around the ContentCollections have been refactored on the way to Neos 2.0 could you please provide an example for the new way to achieve this?