本文整理汇总了PHP中TYPO3\Neos\Domain\Repository\SiteRepository::add方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteRepository::add方法的具体用法?PHP SiteRepository::add怎么用?PHP SiteRepository::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Neos\Domain\Repository\SiteRepository
的用法示例。
在下文中一共展示了SiteRepository::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSiteByNodeName
/**
* Updates or creates a site with the given $siteNodeName
*
* @param string $siteNodeName
* @return Site
*/
protected function getSiteByNodeName($siteNodeName)
{
$site = $this->siteRepository->findOneByNodeName($siteNodeName);
if ($site === null) {
$site = new Site($siteNodeName);
$this->siteRepository->add($site);
return $site;
}
$this->siteRepository->update($site);
return $site;
}
示例2: createCommand
/**
* Create a new site
*
* This command allows to create a blank site with just a single empty document in the default dimension.
* The name of the site, the packageKey must be specified.
*
* If no ``nodeType`` option is specified the command will use `TYPO3.Neos.NodeTypes:Page` as fallback. The node type
* must already exists and have the superType ``TYPO3.Neos:Document``.
*
* If no ``nodeName` option is specified the command will create a unique node-name from the name of the site.
* If a node name is given it has to be unique for the setup.
*
* If the flag ``activate` is set to false new site will not be activated.
*
* @param string $name The name of the site
* @param string $packageKey The site package
* @param string $nodeType The node type to use for the site node. (Default = TYPO3.Neos.NodeTypes:Page)
* @param string $nodeName The name of the site node. If no nodeName is given it will be determined from the siteName.
* @param boolean $inactive The new site is not activated immediately (default = false).
* @return void
*/
public function createCommand($name, $packageKey, $nodeType = 'TYPO3.Neos.NodeTypes:Page', $nodeName = null, $inactive = false)
{
if ($nodeName === null) {
$nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $name);
}
if ($this->siteRepository->findOneByNodeName($nodeName)) {
$this->outputLine('<error>A site with siteNodeName "%s" already exists</error>', [$nodeName]);
$this->quit(1);
}
if ($this->packageManager->isPackageAvailable($packageKey) === false) {
$this->outputLine('<error>Could not find package "%s"</error>', [$packageKey]);
$this->quit(1);
}
$siteNodeType = $this->nodeTypeManager->getNodeType($nodeType);
if ($siteNodeType === null || $siteNodeType->getName() === 'TYPO3.Neos:FallbackNode') {
$this->outputLine('<error>The given node type "%s" was not found</error>', [$nodeType]);
$this->quit(1);
}
if ($siteNodeType->isOfType('TYPO3.Neos:Document') === false) {
$this->outputLine('<error>The given node type "%s" is not based on the superType "%s"</error>', [$nodeType, 'TYPO3.Neos:Document']);
$this->quit(1);
}
$rootNode = $this->nodeContextFactory->create()->getRootNode();
// We fetch the workspace to be sure it's known to the persistence manager and persist all
// so the workspace and site node are persisted before we import any nodes to it.
$rootNode->getContext()->getWorkspace();
$this->persistenceManager->persistAll();
$sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH);
if ($sitesNode === null) {
$sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH));
}
$siteNode = $sitesNode->createNode($nodeName, $siteNodeType);
$siteNode->setProperty('title', $name);
$site = new Site($nodeName);
$site->setSiteResourcesPackageKey($packageKey);
$site->setState($inactive ? Site::STATE_OFFLINE : Site::STATE_ONLINE);
$site->setName($name);
$this->siteRepository->add($site);
$this->outputLine('Successfully created site "%s" with siteNode "%s", type "%s", packageKey "%s" and state "%s"', [$name, $nodeName, $nodeType, $packageKey, $inactive ? 'offline' : 'online']);
}