/** * 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)); }
/** * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $referenceNode * @param array $nodeData * @param string $position * @return \TYPO3\TYPO3CR\Domain\Model\Node * @throws \InvalidArgumentException */ protected function createNewNode(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $referenceNode, array $nodeData, $position) { if (!in_array($position, array('before', 'into', 'after'), TRUE)) { throw new \InvalidArgumentException('The position should be one of the following: "before", "into", "after".', 1347133640); } if (empty($nodeData['nodeName'])) { $nodeData['nodeName'] = uniqid('node'); } $contentType = $this->contentTypeManager->getContentType($nodeData['contentType']); if ($position === 'into') { $newNode = $referenceNode->createNode($nodeData['nodeName'], $contentType); } else { $parentNode = $referenceNode->getParent(); $newNode = $parentNode->createNode($nodeData['nodeName'], $contentType); if ($position === 'before') { $newNode->moveBefore($referenceNode); } else { $newNode->moveAfter($referenceNode); } } if (isset($nodeData['properties']) && is_array($nodeData['properties'])) { foreach ($nodeData['properties'] as $propertyName => $propertyValue) { $newNode->setProperty($propertyName, $propertyValue); } } return $newNode; }
/** * Iterates over the nodes and adds them to the workspace. * * @param \SimpleXMLElement $parentXml * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $parentNode * @return void */ protected function parseNodes(\SimpleXMLElement $parentXml, \TYPO3\TYPO3CR\Domain\Model\NodeInterface $parentNode) { foreach ($parentXml->node as $childNodeXml) { $childNode = $parentNode->getNode((string) $childNodeXml['nodeName']); $contentTypeName = (string) $childNodeXml['type']; if (!$this->contentTypeManager->hasContentType($contentTypeName)) { $contentType = $this->contentTypeManager->createContentType($contentTypeName); } else { $contentType = $this->contentTypeManager->getContentType($contentTypeName); } if ($childNode === NULL) { $identifier = (string) $childNodeXml['identifier'] === '' ? NULL : (string) $childNodeXml['identifier']; $childNode = $parentNode->createSingleNode((string) $childNodeXml['nodeName'], $contentType, $identifier); } else { $childNode->setContentType($contentType); } $childNode->setHidden((bool) $childNodeXml['hidden']); $childNode->setHiddenInIndex((bool) $childNodeXml['hiddenInIndex']); if ($childNodeXml['hiddenBeforeDateTime'] != '') { $childNode->setHiddenBeforeDateTime(\DateTime::createFromFormat(\DateTime::W3C, (string) $childNodeXml['hiddenBeforeDateTime'])); } if ($childNodeXml['hiddenAfterDateTime'] != '') { $childNode->setHiddenAfterDateTime(\DateTime::createFromFormat(\DateTime::W3C, (string) $childNodeXml['hiddenAfterDateTime'])); } if ($childNodeXml->properties) { foreach ($childNodeXml->properties->children() as $childXml) { if (isset($childXml['__type']) && (string) $childXml['__type'] == 'object') { $childNode->setProperty($childXml->getName(), $this->xmlToObject($childXml)); } else { $childNode->setProperty($childXml->getName(), (string) $childXml); } } } if ($childNodeXml->accessRoles) { $accessRoles = array(); foreach ($childNodeXml->accessRoles->children() as $childXml) { $accessRoles[] = (string) $childXml; } $childNode->setAccessRoles($accessRoles); } if ($childNodeXml->node) { $this->parseNodes($childNodeXml, $childNode); } } }
/** * @return string */ public function render() { return implode("\n", array('window.T3Configuration = {};', 'window.T3Configuration.Schema = ' . json_encode($this->contentTypeManager->getFullConfiguration()) . ';', 'window.T3Configuration.UserInterface = ' . json_encode($this->settings['userInterface']) . ';', 'window.T3Configuration.phoenixShouldCacheSchema = ' . json_encode($this->bootstrap->getContext()->isProduction()) . ';', 'window.T3Configuration.enableAloha = ' . json_encode($this->settings['enableAloha']) . ';', 'window.T3Configuration.contentTypeGroups = ' . json_encode($this->settings['contentTypeGroups']) . ';')); }