class WorkspaceManager implements WorkspaceManagerInterface (View source)

Provides the workspace manager.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected string[] $supported

An array of which entity types are supported.

protected RequestStack $requestStack

The request stack.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected MemoryCacheInterface $entityMemoryCache

The entity memory cache service.

protected AccountProxyInterface $currentUser

The current user.

protected StateInterface $state

The state service.

protected LoggerInterface $logger

A logger instance.

protected ClassResolverInterface $classResolver

The class resolver.

protected WorkspaceAssociationInterface $workspaceAssociation

The workspace association service.

protected array $negotiatorIds

The workspace negotiator service IDs.

protected WorkspaceInterface|false $activeWorkspace

The current active workspace or FALSE if there is no active workspace.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $entity_memory_cache, AccountProxyInterface $current_user, StateInterface $state, LoggerInterface $logger, ClassResolverInterface $class_resolver, WorkspaceAssociationInterface $workspace_association, array $negotiator_ids)

Constructs a new WorkspaceManager.

bool
isEntityTypeSupported(EntityTypeInterface $entity_type)

Returns whether an entity type can belong to a workspace or not.

getSupportedEntityTypes()

Returns an array of entity types that can belong to workspaces.

bool
hasActiveWorkspace()

Determines whether a workspace is active in the current request.

getActiveWorkspace()

Gets the active workspace.

$this
setActiveWorkspace(WorkspaceInterface $workspace)

Sets the active workspace via the workspace negotiators.

$this
switchToLive()

Unsets the active workspace via the workspace negotiators.

doSwitchWorkspace(WorkspaceInterface|null $workspace)

Switches the current workspace.

mixed
executeInWorkspace(string $workspace_id, callable $function)

Executes the given callback function in the context of a workspace.

mixed
executeOutsideWorkspace(callable $function)

Executes the given callback function without any workspace context.

bool
shouldAlterOperations(EntityTypeInterface $entity_type)

Determines whether runtime entity operations should be altered.

purgeDeletedWorkspacesBatch()

Deletes the revisions associated with deleted workspaces.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $entity_memory_cache, AccountProxyInterface $current_user, StateInterface $state, LoggerInterface $logger, ClassResolverInterface $class_resolver, WorkspaceAssociationInterface $workspace_association, array $negotiator_ids)

Constructs a new WorkspaceManager.

Parameters

RequestStack $request_stack

The request stack.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

MemoryCacheInterface $entity_memory_cache

The entity memory cache service.

AccountProxyInterface $current_user

The current user.

StateInterface $state

The state service.

LoggerInterface $logger

A logger instance.

ClassResolverInterface $class_resolver

The class resolver.

WorkspaceAssociationInterface $workspace_association

The workspace association service.

array $negotiator_ids

The workspace negotiator service IDs.

bool isEntityTypeSupported(EntityTypeInterface $entity_type)

Returns whether an entity type can belong to a workspace or not.

Parameters

EntityTypeInterface $entity_type

The entity type to check.

Return Value

bool

TRUE if the entity type can belong to a workspace, FALSE otherwise.

EntityTypeInterface[] getSupportedEntityTypes()

Returns an array of entity types that can belong to workspaces.

Return Value

EntityTypeInterface[]

The entity types what can belong to workspaces.

bool hasActiveWorkspace()

Determines whether a workspace is active in the current request.

Return Value

bool

TRUE if a workspace is active, FALSE otherwise.

WorkspaceInterface getActiveWorkspace()

Gets the active workspace.

Return Value

WorkspaceInterface

The active workspace entity object.

$this setActiveWorkspace(WorkspaceInterface $workspace)

Sets the active workspace via the workspace negotiators.

Parameters

WorkspaceInterface $workspace

The workspace to set as active.

Return Value

$this

Exceptions

WorkspaceAccessException

$this switchToLive()

Unsets the active workspace via the workspace negotiators.

Return Value

$this

protected doSwitchWorkspace(WorkspaceInterface|null $workspace)

Switches the current workspace.

Parameters

WorkspaceInterface|null $workspace

The workspace to set as active or NULL to switch out of the currently active workspace.

Exceptions

WorkspaceAccessException

mixed executeInWorkspace(string $workspace_id, callable $function)

Executes the given callback function in the context of a workspace.

Parameters

string $workspace_id

The ID of a workspace.

callable $function

The callback to be executed.

Return Value

mixed

The callable's return value.

mixed executeOutsideWorkspace(callable $function)

Executes the given callback function without any workspace context.

Parameters

callable $function

The callback to be executed.

Return Value

mixed

The callable's return value.

bool shouldAlterOperations(EntityTypeInterface $entity_type)

Determines whether runtime entity operations should be altered.

Parameters

EntityTypeInterface $entity_type

The entity type to check.

Return Value

bool

TRUE if the entity operations or queries should be altered in the current request, FALSE otherwise.

purgeDeletedWorkspacesBatch()

Deletes the revisions associated with deleted workspaces.