final class WorkspaceService (View source)

Central authority to interact with Content Repository Workspaces within Neos

Methods

__construct(ContentRepositoryRegistry $contentRepositoryRegistry, WorkspaceMetadataAndRoleRepository $metadataAndRoleRepository, UserService $userService, ContentRepositoryAuthorizationService $authorizationService, Context $securityContext, SoftRemovalGarbageCollector $softRemovalGarbageCollector)

No description

getWorkspaceMetadata(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName)

Load metadata for the specified workspace

void
setWorkspaceTitle(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $newWorkspaceTitle)

Update/set title metadata for the specified workspace

void
setWorkspaceDescription(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceDescription $newWorkspaceDescription)

Update/set description metadata for the specified workspace

getPersonalWorkspaceForUser(ContentRepositoryId $contentRepositoryId, UserId $userId)

Retrieve the personal workspace for the specified user, if no workspace exist an exception is thrown.

void
createRootWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceRoleAssignments $assignments)

Create a new root (aka base) workspace with the specified metadata

void
createPersonalWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspaceName, UserId $ownerId)

Create a new, personal, workspace for the specified user (fails if the user already owns a workspace)

void
createSharedWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspaceName, WorkspaceRoleAssignments $assignments)

Create a new, potentially shared, workspace

void
createPersonalWorkspaceForUserIfMissing(ContentRepositoryId $contentRepositoryId, User $user)

Create a new, personal, workspace for the specified user if none exists yet

void
assignWorkspaceRole(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceRoleAssignment $assignment)

Assign a workspace role to the given user/user group

void
unassignWorkspaceRole(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceRoleSubject $subject)

Remove a workspace role assignment for the given subject

void
deleteWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName)

Deletes a content repository workspace and also all role assignments and metadata

getWorkspaceRoleAssignments(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName)

Get all role assignments for the specified workspace

getUniqueWorkspaceName(ContentRepositoryId $contentRepositoryId, string $candidate)

Builds a workspace name that is unique within the specified content repository.

Details

__construct(ContentRepositoryRegistry $contentRepositoryRegistry, WorkspaceMetadataAndRoleRepository $metadataAndRoleRepository, UserService $userService, ContentRepositoryAuthorizationService $authorizationService, Context $securityContext, SoftRemovalGarbageCollector $softRemovalGarbageCollector)

No description

Parameters

ContentRepositoryRegistry $contentRepositoryRegistry
WorkspaceMetadataAndRoleRepository $metadataAndRoleRepository
UserService $userService
ContentRepositoryAuthorizationService $authorizationService
Context $securityContext
SoftRemovalGarbageCollector $softRemovalGarbageCollector

WorkspaceMetadata getWorkspaceMetadata(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName)

Load metadata for the specified workspace

Note: If no metadata exists for the specified workspace, metadata with title based on the name and classification according to the content repository workspace is returned. Root workspaces are of classification ROOT whereas simple ones will yield UNKNOWN. {\Neos\Neos\Domain\Model\WorkspaceClassification::UNKNOWN}

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName

Return Value

WorkspaceMetadata

void setWorkspaceTitle(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $newWorkspaceTitle)

Update/set title metadata for the specified workspace

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceTitle $newWorkspaceTitle

Return Value

void

void setWorkspaceDescription(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceDescription $newWorkspaceDescription)

Update/set description metadata for the specified workspace

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceDescription $newWorkspaceDescription

Return Value

void

Workspace getPersonalWorkspaceForUser(ContentRepositoryId $contentRepositoryId, UserId $userId)

Retrieve the personal workspace for the specified user, if no workspace exist an exception is thrown.

Parameters

ContentRepositoryId $contentRepositoryId
UserId $userId

Return Value

Workspace

void createRootWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceRoleAssignments $assignments)

Create a new root (aka base) workspace with the specified metadata

To ensure that editors can publish to the live workspace and to allow everybody to view it an assignment like {\Neos\Neos\Domain\Model\WorkspaceRoleAssignments::createForLiveWorkspace} needs to be specified:

$this->workspaceService->createRootWorkspace( $contentRepositoryId, WorkspaceName::forLive(), WorkspaceTitle::fromString('Public live workspace'), WorkspaceDescription::empty(), WorkspaceRoleAssignments::createForLiveWorkspace() );

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceTitle $title
WorkspaceDescription $description
WorkspaceRoleAssignments $assignments

Return Value

void

Exceptions

WorkspaceAlreadyExists

void createPersonalWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspaceName, UserId $ownerId)

Create a new, personal, workspace for the specified user (fails if the user already owns a workspace)

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceTitle $title
WorkspaceDescription $description
WorkspaceName $baseWorkspaceName
UserId $ownerId

Return Value

void

void createSharedWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceTitle $title, WorkspaceDescription $description, WorkspaceName $baseWorkspaceName, WorkspaceRoleAssignments $assignments)

Create a new, potentially shared, workspace

To ensure that the user can manage the shared workspace and to enable collaborates an assignment like {\Neos\Neos\Domain\Model\WorkspaceRoleAssignments::createForSharedWorkspace} needs to be specified:

$this->workspaceService->createWorkspace(
    ...,
    assignments: WorkspaceRoleAssignments::createForSharedWorkspace(
        $currentUser->getId()
    )
);

NOTE: By default - if no role assignments are specified - only administrators can manage workspaces without role assignments.

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceTitle $title
WorkspaceDescription $description
WorkspaceName $baseWorkspaceName
WorkspaceRoleAssignments $assignments

Return Value

void

void createPersonalWorkspaceForUserIfMissing(ContentRepositoryId $contentRepositoryId, User $user)

Create a new, personal, workspace for the specified user if none exists yet

Parameters

ContentRepositoryId $contentRepositoryId
User $user

Return Value

void

void assignWorkspaceRole(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceRoleAssignment $assignment)

Assign a workspace role to the given user/user group

Without explicit workspace roles, only administrators can change the corresponding workspace. With this method, the subject (i.e. a Neos user or group represented by a Flow role identifier) can be granted a {\Neos\Neos\Domain\Model\WorkspaceRole} for the specified workspace

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceRoleAssignment $assignment

Return Value

void

void unassignWorkspaceRole(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, WorkspaceRoleSubject $subject)

Remove a workspace role assignment for the given subject

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName
WorkspaceRoleSubject $subject

Return Value

void

See also

\Neos\Neos\Domain\Service\self::assignWorkspaceRole()

void deleteWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName)

Deletes a content repository workspace and also all role assignments and metadata

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName

Return Value

void

WorkspaceRoleAssignments getWorkspaceRoleAssignments(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName)

Get all role assignments for the specified workspace

NOTE: This should never be used to evaluate permissions, instead {\Neos\Neos\Security\Authorization\ContentRepositoryAuthorizationService::getWorkspacePermissions()} should be used!

Parameters

ContentRepositoryId $contentRepositoryId
WorkspaceName $workspaceName

Return Value

WorkspaceRoleAssignments

WorkspaceName getUniqueWorkspaceName(ContentRepositoryId $contentRepositoryId, string $candidate)

Builds a workspace name that is unique within the specified content repository.

If $candidate already refers to a workspace name that is not used yet, it will be used (with transliteration to enforce a valid format) Otherwise a counter "-n" suffix is appended and increased until a unique name is found, or the maximum number of attempts has been reached (in which case an exception is thrown)

Parameters

ContentRepositoryId $contentRepositoryId
string $candidate

Return Value

WorkspaceName