class Context (View source)

Context

Properties

protected WorkspaceRepository $workspaceRepository
protected NodeDataRepository $nodeDataRepository
protected NodeFactory $nodeFactory
protected ContextFactoryInterface $contextFactory
protected LoggerInterface $systemLogger
protected Workspace $workspace
protected string $workspaceName
protected DateTime $currentDateTime
protected bool $invisibleContentShown

If true, invisible content elements will be shown.

protected bool $removedContentShown

If true, removed content elements will be shown, even though they are removed.

protected bool $inaccessibleContentShown

If true, even content elements will be shown which are not accessible by the currently logged in account.

protected array $dimensions
protected array $targetDimensions
protected FirstLevelNodeCache $firstLevelNodeCache

Methods

__construct(string $workspaceName, DateTimeInterface $currentDateTime, array $dimensions, array $targetDimensions, bool $invisibleContentShown, bool $removedContentShown, bool $inaccessibleContentShown)

Creates a new Context object.

getWorkspace(bool $createWorkspaceIfNecessary = true)

Returns the current workspace.

void
validateWorkspace(Workspace $workspace)

This method is called in order to check if a workspace is accessible.

string
getWorkspaceName()

Returns the name of the workspace.

getCurrentDateTime()

Returns the current date and time in form of a \DateTime object.

getRootNode()

Convenience method returns the root node for this context workspace.

getNode(string $path)

Returns a node specified by the given absolute path.

NodeInterface
getNodeByIdentifier(string $identifier)

Get a node by identifier and this context

getNodeVariantsByIdentifier(string $identifier)

Get all node variants for the given identifier

getNodesOnPath(mixed $startingPoint, mixed $endPoint)

Finds all nodes lying on the path specified by (and including) the given starting point and end point.

adoptNode(NodeInterface $node, bool $recursive = false)

Adopts a node from a (possibly) different context to this context

emitBeforeAdoptNode(NodeInterface $node, Context $context, $recursive)

No description

emitAfterAdoptNode(NodeInterface $node, Context $context, $recursive)

No description

bool
isInvisibleContentShown()

Tells if nodes which are usually invisible should be accessible through the Node API and queries

bool
isRemovedContentShown()

Tells if nodes which have their "removed" flag set should be accessible through the Node API and queries

bool
isInaccessibleContentShown()

Tells if nodes which have access restrictions should be accessible through the Node API and queries even without the necessary roles / rights

array
getDimensions()

An indexed array of dimensions with ordered list of values for matching nodes by content dimensions

array
getTargetDimensions()

An indexed array of dimensions with a set of values that should be applied when updating or creating

array
getTargetDimensionValues()

An indexed array of dimensions with a set of values that should be applied when updating or creating

array
getProperties()

Returns the properties of this context.

Details

__construct(string $workspaceName, DateTimeInterface $currentDateTime, array $dimensions, array $targetDimensions, bool $invisibleContentShown, bool $removedContentShown, bool $inaccessibleContentShown)

Creates a new Context object.

NOTE: This is for internal use only, you should use the ContextFactory for creating Context instances.

Parameters

string $workspaceName

Name of the current workspace

DateTimeInterface $currentDateTime

The current date and time

array $dimensions

Array of dimensions with array of ordered values

array $targetDimensions

Array of dimensions used when creating / modifying content

bool $invisibleContentShown

If invisible content should be returned in query results

bool $removedContentShown

If removed content should be returned in query results

bool $inaccessibleContentShown

If inaccessible content should be returned in query results

See also

ContextFactoryInterface

Workspace getWorkspace(bool $createWorkspaceIfNecessary = true)

Returns the current workspace.

Parameters

bool $createWorkspaceIfNecessary

DEPRECATED: If enabled, creates a workspace with the configured name if it doesn't exist already. This option is DEPRECATED, create workspace explicitly instead.

Return Value

Workspace

The workspace or NULL

Exceptions

IllegalObjectTypeException

void validateWorkspace(Workspace $workspace)

This method is called in order to check if a workspace is accessible.

At the time of this writing, it is not possible in Flow to restrict access to Workspace through Entity Privileges because Workspaces are used at a very early stage during routing where the security context is not yet initialized. As a workaround, we use a Method Privilege which protects this validateWorkspace() method and thus prevents unauthorized access to a workspace when calling this context's getWorkspace() method.

Since some privilege definitions check the "owner" property of a Workspace, we need a real Workspace object and not just the name - hence this method.

Parameters

Workspace $workspace

The workspace to check

Return Value

void

string getWorkspaceName()

Returns the name of the workspace.

Return Value

string

DateTime getCurrentDateTime()

Returns the current date and time in form of a \DateTime object.

If you use this method for getting the current date and time everywhere in your code, it will be possible to simulate a certain time in unit tests or in the actual application (for realizing previews etc).

Return Value

DateTime

The current date and time - or a simulated version of it

NodeInterface getRootNode()

Convenience method returns the root node for this context workspace.

Return Value

NodeInterface

NodeInterface getNode(string $path)

Returns a node specified by the given absolute path.

Parameters

string $path

Absolute path specifying the node

Return Value

NodeInterface

The specified node or NULL if no such node exists

Exceptions

InvalidArgumentException

NodeInterface getNodeByIdentifier(string $identifier)

Get a node by identifier and this context

Parameters

string $identifier

The identifier of a node

Return Value

NodeInterface

The node with the given identifier or NULL if no such node exists

NodeInterface[] getNodeVariantsByIdentifier(string $identifier)

Get all node variants for the given identifier

A variant of a node can have different dimension values and path (for non-aggregate nodes). The resulting node instances might belong to a different context.

Parameters

string $identifier

The identifier of a node

Return Value

NodeInterface[]

NodeInterface[] getNodesOnPath(mixed $startingPoint, mixed $endPoint)

Finds all nodes lying on the path specified by (and including) the given starting point and end point.

Parameters

mixed $startingPoint

Either an absolute path or an actual node specifying the starting point, for example /sites/mysitecom

mixed $endPoint

Either an absolute path or an actual node specifying the end point, for example /sites/mysitecom/homepage/subpage

Return Value

NodeInterface[]

The nodes found between and including the given paths or an empty array of none were found

NodeInterface adoptNode(NodeInterface $node, bool $recursive = false)

Adopts a node from a (possibly) different context to this context

Checks if a node variant matching the exact dimensions already exists for this context and return it if found. Otherwise a new node variant for this context is created.

In case the node already exists in the context but does not match the target dimensions a new, more specific node is created and returned.

Parameters

NodeInterface $node

The node with a different context. If the context of the given node is the same as this context the operation will have no effect.

bool $recursive

If true also adopt all descendant nodes which are non-aggregate

Return Value

NodeInterface

A new or existing node that matches this context

protected emitBeforeAdoptNode(NodeInterface $node, Context $context, $recursive)

No description

Parameters

NodeInterface $node
Context $context
$recursive

protected emitAfterAdoptNode(NodeInterface $node, Context $context, $recursive)

No description

Parameters

NodeInterface $node
Context $context
$recursive

bool isInvisibleContentShown()

Tells if nodes which are usually invisible should be accessible through the Node API and queries

Return Value

bool

See also

NodeFactory->filterNodeByContext()

bool isRemovedContentShown()

Tells if nodes which have their "removed" flag set should be accessible through the Node API and queries

Return Value

bool

See also

Node->filterNodeByContext()

bool isInaccessibleContentShown()

Tells if nodes which have access restrictions should be accessible through the Node API and queries even without the necessary roles / rights

Return Value

bool

array getDimensions()

An indexed array of dimensions with ordered list of values for matching nodes by content dimensions

Return Value

array

array getTargetDimensions()

An indexed array of dimensions with a set of values that should be applied when updating or creating

Return Value

array

array getTargetDimensionValues()

An indexed array of dimensions with a set of values that should be applied when updating or creating

Return Value

array

array getProperties()

Returns the properties of this context.

Return Value

array

FirstLevelNodeCache getFirstLevelNodeCache()

Not public API!

Return Value

FirstLevelNodeCache