/** * Returns the specified node * * @param string $term * @param integer $requestIndex * @return void * @ExtDirect * @todo Improve this WIP search implementation */ public function searchAction($term, $requestIndex) { $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext($this->securityContext->getParty()->getPreferences()->get('context.workspace')); $this->nodeRepository->setContext($contentContext); $searchContentGroups = array(); $searchContentTypes = array(); foreach (array('TYPO3.Phoenix.ContentTypes:Page', 'TYPO3.Phoenix.ContentTypes:ContentObject') as $contentType) { $searchContentGroups[$contentType] = $this->contentTypeManager->getContentType($contentType)->getConfiguration(); array_push($searchContentTypes, $contentType); $subContentTypes = $this->contentTypeManager->getSubContentTypes($contentType); if (count($subContentTypes) > 0) { $searchContentGroups[$contentType]['subContentTypes'] = $subContentTypes; $searchContentTypes = array_merge($searchContentTypes, array_keys($subContentTypes)); } } $staticWebBaseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/TYPO3.TYPO3/'; $groups = array(); foreach ($this->nodeSearchService->findByProperties($term, $searchContentTypes) as $result) { $contentType = $result->getContentType(); if (array_key_exists($contentType->getName(), $searchContentGroups)) { $type = $contentType->getName(); } else { foreach ($searchContentGroups as $searchContentGroup => $searchContentGroupConfiguration) { if (isset($searchContentGroupConfiguration['subContentTypes']) && array_key_exists($contentType->getName(), $searchContentGroupConfiguration['subContentTypes'])) { $type = $searchContentGroup; break; } } } if (!array_key_exists($type, $groups)) { $groups[$type] = array('type' => $contentType->getName(), 'label' => $searchContentGroups[$type]['search'], 'items' => array()); } foreach ($contentType->getProperties() as $property => $configuration) { if ($property[0] !== '_') { $labelProperty = $property; break; } } $this->uriBuilder->reset(); if ($result->getContentType()->isOfType('TYPO3.Phoenix.ContentTypes:Page')) { $pageNode = $result; } else { $pageNode = $this->findNextParentFolderNode($result); $this->uriBuilder->setSection('c' . $result->getIdentifier()); } $searchResult = array('type' => $contentType->getName(), 'label' => substr(trim(strip_tags($result->getProperty($labelProperty))), 0, 50), 'action' => $this->uriBuilder->uriFor('show', array('node' => $pageNode), 'Frontend\\Node', 'TYPO3.TYPO3'), 'path' => $result->getPath()); $contentTypeConfiguration = $contentType->getConfiguration(); if (isset($contentTypeConfiguration['darkIcon'])) { $searchResult['icon'] = $staticWebBaseUri . $contentTypeConfiguration['darkIcon']; } array_push($groups[$type]['items'], $searchResult); } $data = array('requestIndex' => $requestIndex, 'actions' => array(array('label' => 'Clear all cache', 'command' => 'clear:cache:all'), array('label' => 'Clear page cache', 'command' => 'clear:cache:pages')), 'results' => array_values($groups)); $this->view->assign('value', array('data' => $data, 'success' => TRUE)); }
/** * Search a page, needed for internal links. * * @param string $query * @return void * @ExtDirect */ public function searchPageAction($query) { $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live'); $this->nodeRepository->setContext($contentContext); $nodes = $this->nodeSearchService->findByProperties($query, array('TYPO3.Phoenix.ContentTypes:Page')); $searchResult = array(); foreach ($nodes as $uninitializedNode) { $node = $contentContext->getNode($uninitializedNode->getPath()); $searchResult[] = $this->processNodeForEditorPlugins($node); } $this->view->assign('value', array('searchResult' => $searchResult, 'success' => TRUE)); }