BoxerBuffa
(Finn Thorwarth)
1
Hey,
we would like to create documents based on a xml feed.
First i would like to get the parent node, but since we have different sites with different dimensions whats the way to get the node?
I have the name of the root node of the page, is there a function to get the node based on that?
The import function will be triggered by a cron.
Thanks for helping!
BoxerBuffa
(Finn Thorwarth)
2
Found a solution:
$parentNode = $this->getParentNode($targetLanguage);
private function getParentNode(string $targetLanguage): ?NodeInterface
{
$parentNodeType = 'WG.BaseSite:Document.StellenangeboteCollectionPage';
$siteName = 'eq-germany-career';
// Create a context with the target language dimension
$context = $this->contextFactory->create([
'dimensions' => ['language' => [$targetLanguage]],
'targetDimensions' => ['language' => $targetLanguage],
'invisibleContentShown' => true,
'inaccessibleContentShown' => true
]);
// Find the specific site node
$siteNode = $context->getNode('/sites/' . $siteName);
if (!$siteNode) {
$this->logger->error('Site node not found for site: ' . $siteName);
return null;
}
//$this->logger->info('Site node found: ' . $siteNode->getIdentifier() . ' for site: ' . $siteName);
// Use FlowQuery to find the parent node within the specific site
$flowQuery = new FlowQuery([$siteNode]);
$parentNode = $flowQuery
->find('[instanceof ' . $parentNodeType . ']')
->get(0);
if (!$parentNode) {
$this->logger->error('Parent node not found in site: ' . $siteName . '. Debugging information:');
$this->logger->info('Parent node type: ' . $parentNodeType);
return null;
}
// $this->logger->info('Parent node found: ' . $parentNode->getIdentifier() . ' - ' . $parentNode->getProperty('uriPathSegment') . ' in site: ' . $siteName);
return $parentNode;
}
This works for me to find the node of type ‘WG.BaseSite:Document.StellenangeboteCollectionPage’ inside the ‘eq-germany-career’ site.