Hi there,
I was wondering if their is a better approach to find nodes in the document tree then what I did.
Given: I have 100 video nodes in my document tree with informations like link to youtube video file. Now I want to add a new nodeType, a content element, where I can select in the inspector, within the selectbox, one of the 100 videos. To display this video somewhere on the page.
What I did:
I’ve created a content element “video” and added a DataSource which should deliver all available videos.
Now the VideoDataSource should search for: [instancesof Vender.Name:VideoDocument]
and return an array with all nodes to be able to select a video.
Thing is, in my working solution, I have to specify the site-root with the node UUID, which is not very convenient.
So is there a better way to get all nodes?
/**
* Get data
*
* @param NodeInterface $node The node that is currently edited (optional)
* @param array $arguments Additional arguments (key / value)
* @return array JSON serializable data
*/
public function getData(NodeInterface $node = NULL, array $arguments)
{
$context = $this->contextFactory->create(array('workspaceName' => 'live'));
$node = $context->getNodeByIdentifier('318bbf14-121d-4953-8554-5805a5dc57ba'); // Use the identifier of the node at path /sites/website/node-56a5b4a7a127c, prefere UUID because they never change
$allVideoNodes = (new FlowQuery([$node]))->find('[instanceof Vendor.Name:VideoDocument]')->get();
$result = array();
/** @var NodeInterface $videoNode */
foreach ($allVideoNodes as $videoNode){
$result[] = $videoNode->getProperty('videoId');
}
return $result;
}`