Neos.Media.Browser/Classes/Controller/UsageController.php
public function relatedNodesAction(AssetInterface $asset)
    {
        $userWorkspace = $this->userService->getPersonalWorkspace();

        $usageReferences = $this->assetService->getUsageReferences($asset);
        $relatedNodes = [];
        $inaccessibleRelations = [];

        $existingSites = $this->siteRepository->findAll();

        foreach ($usageReferences as $usage) {
            $inaccessibleRelation = [
                'type' => get_class($usage),
                'usage' => $usage
            ];

            if (!$usage instanceof AssetUsageInNodeProperties) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            try {
                $nodeType = $this->nodeTypeManager->getNodeType($usage->getNodeTypeName());
            } catch (NodeTypeNotFoundException $e) {
                $nodeType = null;
            }
            /** @var Workspace $workspace */
            $workspace = $this->workspaceRepository->findByIdentifier($usage->getWorkspaceName());
            $accessible = $this->domainUserService->currentUserCanReadWorkspace($workspace);

            $inaccessibleRelation['nodeIdentifier'] = $usage->getNodeIdentifier();
            $inaccessibleRelation['workspaceName'] = $usage->getWorkspaceName();
            $inaccessibleRelation['workspace'] = $workspace;
            $inaccessibleRelation['nodeType'] = $nodeType;
            $inaccessibleRelation['accessible'] = $accessible;

            if (!$accessible) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            $node = $this->getNodeFrom($usage);
            // this should actually never happen.
            if (!$node) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            $flowQuery = new FlowQuery([$node]);
            $documentNode = $flowQuery->closest('[instanceof Neos.Neos:Document]')->get(0);
            // this should actually never happen, too.
            if (!$documentNode) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            $site = $node->getContext()->getCurrentSite();
            foreach ($existingSites as $existingSite) {
                /** @var Site $existingSite * */
                $siteNodePath = '/sites/' . $existingSite->getNodeName();
                if ($siteNodePath === $node->getPAth() || strpos($node->getPath(), $siteNodePath . '/') === 0) {
                    $site = $existingSite;
                }
            }

            $relatedNodes[$site->getNodeName()]['site'] = $site;
            $relatedNodes[$site->getNodeName()]['nodes'][] = [
                'node' => $node,
                'documentNode' => $documentNode
            ];
        }

        $this->view->assignMultiple([
            'totalUsageCount' => count($usageReferences),
            'nodeUsageClass' => AssetUsageInNodeProperties::class,
            'asset' => $asset,
            'inaccessibleRelations' => $inaccessibleRelations,
            'relatedNodes' => $relatedNodes,
            'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets(),
            'userWorkspace' => $userWorkspace
        ]);
    }
public function relatedNodesAction(AssetInterface $asset)
    {
        $userWorkspace = $this->userService->getPersonalWorkspace();

        $usageReferences = $this->assetService->getUsageReferences($asset);
        $relatedNodes = [];
        $inaccessibleRelations = [];

        $existingSites = $this->siteRepository->findAll();

        foreach ($usageReferences as $usage) {
            $inaccessibleRelation = [
                'type' => get_class($usage),
                'usage' => $usage
            ];

            if (!$usage instanceof AssetUsageInNodeProperties) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            try {
                $nodeType = $this->nodeTypeManager->getNodeType($usage->getNodeTypeName());
            } catch (NodeTypeNotFoundException $e) {
                $nodeType = null;
            }
            /** @var Workspace $workspace */
            $workspace = $this->workspaceRepository->findByIdentifier($usage->getWorkspaceName());
            $accessible = $this->domainUserService->currentUserCanReadWorkspace($workspace);

            $inaccessibleRelation['nodeIdentifier'] = $usage->getNodeIdentifier();
            $inaccessibleRelation['workspaceName'] = $usage->getWorkspaceName();
            $inaccessibleRelation['workspace'] = $workspace;
            $inaccessibleRelation['nodeType'] = $nodeType;
            $inaccessibleRelation['accessible'] = $accessible;

            if (!$accessible) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            $node = $this->getNodeFrom($usage);
            // this should actually never happen.
            if (!$node) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            $flowQuery = new FlowQuery([$node]);
            $documentNode = $flowQuery->closest('[instanceof Neos.Neos:Document]')->get(0);
            // this should actually never happen, too.
            if (!$documentNode) {
                $inaccessibleRelations[] = $inaccessibleRelation;
                continue;
            }

            $site = $node->getContext()->getCurrentSite();
            foreach ($existingSites as $existingSite) {
                /** @var Site $existingSite * */
                $siteNodePath = '/sites/' . $existingSite->getNodeName();
                if ($siteNodePath === $node->getPAth() || strpos($node->getPath(), $siteNodePath . '/') === 0) {
                    $site = $existingSite;
                }
            }

            $relatedNodes[$site->getNodeName()]['site'] = $site;
            $relatedNodes[$site->getNodeName()]['nodes'][] = [
                'node' => $node,
                'documentNode' => $documentNode
            ];
        }

        $this->view->assignMultiple([
            'totalUsageCount' => count($usageReferences),
            'nodeUsageClass' => AssetUsageInNodeProperties::class,
            'asset' => $asset,
            'inaccessibleRelations' => $inaccessibleRelations,
            'relatedNodes' => $relatedNodes,
            'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets(),
            'userWorkspace' => $userWorkspace
        ]);
    }
public function relatedNodesAction ( AssetInterface $ asset ) { $ userWorkspace = $ this -> userService -> getPersonalWorkspace ( ) ; $ usageReferences = $ this -> assetService -> getUsageReferences ( $ asset ) ; $ relatedNodes = [ ] ; $ inaccessibleRelations = [ ] ; $ existingSites = $ this -> siteRepository -> findAll ( ) ; foreach ( $ usageReferences as $ usage ) { $ inaccessibleRelation = [ 'type' => get_class ( $ usage ) , 'usage' => $ usage ] ; if ( ! $ usage instanceof AssetUsageInNodeProperties ) { $ inaccessibleRelations [ ] = $ inaccessibleRelation ; continue ; } try { $ nodeType = $ this -> nodeTypeManager -> getNodeType ( $ usage -> getNodeTypeName ( ) ) ; } catch ( NodeTypeNotFoundException $ e ) { $ nodeType = null ; } /** @var Workspace $workspace */ $ workspace = $ this -> workspaceRepository -> findByIdentifier ( $ usage -> getWorkspaceName ( ) ) ; $ accessible = $ this -> domainUserService -> currentUserCanReadWorkspace ( $ workspace ) ; $ inaccessibleRelation [ 'nodeIdentifier' ] = $ usage -> getNodeIdentifier ( ) ; $ inaccessibleRelation [ 'workspaceName' ] = $ usage -> getWorkspaceName ( ) ; $ inaccessibleRelation [ 'workspace' ] = $ workspace ; $ inaccessibleRelation [ 'nodeType' ] = $ nodeType ; $ inaccessibleRelation [ 'accessible' ] = $ accessible ; if ( ! $ accessible ) { $ inaccessibleRelations [ ] = $ inaccessibleRelation ; continue ; } $ node = $ this -> getNodeFrom ( $ usage ) ; // this should actually never happen. if ( ! $ node ) { $ inaccessibleRelations [ ] = $ inaccessibleRelation ; continue ; } $ flowQuery = new FlowQuery ( [ $ node ] ) ; $ documentNode = $ flowQuery -> closest ( '[instanceof Neos.Neos:Document]' ) -> get ( 0 ) ; // this should actually never happen, too. if ( ! $ documentNode ) { $ inaccessibleRelations [ ] = $ inaccessibleRelation ; continue ; } $ site = $ node -> getContext ( ) -> getCurrentSite ( ) ; foreach ( $ existingSites as $ existingSite ) { /** @var Site $existingSite * */ $ siteNodePath = '/sites/' . $ existingSite -> getNodeName ( ) ; if ( $ siteNodePath === $ node -> getPAth ( ) || strpos ( $ node -> getPath ( ) , $ siteNodePath . '/' ) === 0 ) { $ site = $ existingSite ; } } $ relatedNodes [ $ site -> getNodeName ( ) ] [ 'site' ] = $ site ; $ relatedNodes [ $ site -> getNodeName ( ) ] [ 'nodes' ] [ ] = [ 'node' => $ node , 'documentNode' => $ documentNode ] ; } $ this -> view -> assignMultiple ( [ 'totalUsageCount' => count ( $ usageReferences ) , 'nodeUsageClass' => AssetUsageInNodeProperties :: class , 'asset' => $ asset , 'inaccessibleRelations' => $ inaccessibleRelations , 'relatedNodes' => $ relatedNodes , 'contentDimensions' => $ this -> contentDimensionPresetSource -> getAllPresets ( ) , 'userWorkspace' => $ userWorkspace ] ) ; }
Get Related Nodes for an asset

@param AssetInterface $asset
@return void
Get Related Nodes for an asset