Find nodes blow /sites/ with php FlowQuery in DataSource class

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;
}`

If you have the context, you can just start at the site node, which can be fetched using getCurrentSiteNode() – no need for the identifier in that case.

Works perfect! Thank you!

That’s how I did it now. Maybe it helps someone else as well:

`/**
 * 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)
{
	$results = [];

	/** @var $contentContext ContentContext */
	$contentContext = $node->getContext();
	$site = $contentContext->getCurrentSiteNode();

	$allVideoNodes = (new FlowQuery([$site]))->find('[instanceof Vendor.Name:VideoDocument]')->sort('title', 'ASC')->get();

	/** @var NodeInterface $videoNode */
	foreach ($allVideoNodes as $key => $videoNode) {
		$results[$key] = array();
		$results[$key]['value'] = $videoNode->getProperty('videoId');
                $results[$key]['label'] = $videoNode->getProperty('title');
	}

	return $results;
}