Neos\Neos\Controller\Module\Management\WorkspacesController::createAction PHP Method

createAction() public method

Create a workspace
public createAction ( string $title, Workspace $baseWorkspace, string $visibility, string $description = '' ) : void
$title string Human friendly title of the workspace, for example "Christmas Campaign"
$baseWorkspace Neos\ContentRepository\Domain\Model\Workspace Workspace the new workspace should be based on
$visibility string Visibility of the new workspace, must be either "internal" or "shared"
$description string A description explaining the purpose of the new workspace
return void
    public function createAction($title, Workspace $baseWorkspace, $visibility, $description = '')
    {
        $workspace = $this->workspaceRepository->findOneByTitle($title);
        if ($workspace instanceof Workspace) {
            $this->addFlashMessage($this->translator->translateById('workspaces.workspaceWithThisTitleAlreadyExists', [], null, null, 'Modules', 'Neos.Neos'), '', Message::SEVERITY_WARNING);
            $this->redirect('new');
        }
        $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5);
        while ($this->workspaceRepository->findOneByName($workspaceName) instanceof Workspace) {
            $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5);
        }
        if ($visibility === 'private') {
            $owner = $this->userService->getCurrentUser();
        } else {
            $owner = null;
        }
        $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
        $workspace->setTitle($title);
        $workspace->setDescription($description);
        $this->workspaceRepository->add($workspace);
        $this->redirect('index');
    }