class NodeType (View source)

A Node Type

Although methods contained in this class belong to the public API, you should not need to deal with creating or managing node types manually. New node types should be defined in a NodeTypes.yaml file.

Properties

protected string $name

Name of this node type. Example: "ContentRepository:Folder"

protected array $localConfiguration

Configuration for this node type, can be an arbitrarily nested array. Does not include inherited configuration.

protected array $fullConfiguration

Full configuration for this node type, can be an arbitrarily nested array. Includes any inherited configuration.

protected bool $abstract

Is this node type marked abstract

protected bool $final

Is this node type marked final

protected NodeType[] $declaredSuperTypes

node types this node type directly inherits from

protected ObjectManagerInterface $objectManager
protected NodeTypeManager $nodeTypeManager
protected NodeLabelGeneratorInterface $nodeLabelGenerator
protected bool $initialized

Whether or not this node type has been initialized (e.g. if it has been postprocessed)

Methods

__construct(string $name, array $declaredSuperTypes, array $configuration)

Constructs this node type

void
initialize()

Initializes this node type

array
buildFullConfiguration()

Builds the full configuration by merging configuration from the supertypes into the local configuration.

static array
getFlattenedSuperTypes(NodeType $nodeType)

Returns a flat list of super types to inherit from.

array
applyPostprocessing(array $fullConfiguration)

Iterates through configured postprocessors and invokes them

string
getName()

Returns the name of this node type

bool
isAbstract()

Return boolean true if marked abstract

bool
isFinal()

Return boolean true if marked final

getDeclaredSuperTypes()

Returns the direct, explicitly declared super types of this node type.

bool
isAggregate()

Returns whether this node type (or any parent type) is an aggregate.

bool
isOfType(string $nodeType)

If this node type or any of the direct or indirect super types has the given name.

array
getLocalConfiguration()

Get the local configuration of the node type. Should only be used internally.

array
getFullConfiguration()

Get the full configuration of the node type. Should only be used internally.

bool
hasConfiguration(string $configurationPath)

Checks if the configuration of this node type contains a setting for the given $configurationPath

mixed
getConfiguration(string $configurationPath)

Returns the configuration option with the specified $configurationPath or NULL if it does not exist

string
getLabel()

Get the human-readable label of this node type

array
getOptions()

Get additional options (if specified)

getNodeLabelGenerator()

Return the node label generator class for the given node

array
getProperties()

Return the array with the defined properties. The key is the property name, the value the property configuration. There are no guarantees on how the property configuration looks like.

string
getPropertyType(string $propertyName)

Returns the configured type of the specified property

array
getDefaultValuesForProperties()

Return an array with the defined default values for each property, if any.

getAutoCreatedChildNodes()

Return an array with child nodes which should be automatically created

bool
hasAutoCreatedChildNode(NodeName $nodeName)

No description

NodeType|null
getTypeOfAutoCreatedChildNode(NodeName $nodeName)

No description

bool
allowsChildNodeType(NodeType $nodeType)

Checks if the given NodeType is acceptable as sub-node with the configured constraints, not taking constraints of auto-created nodes into account. Thus, this method only returns the correct result if called on NON-AUTO-CREATED nodes!

bool
allowsGrandchildNodeType(string $childNodeName, NodeType $nodeType)

Checks if the given $nodeType is allowed as a childNode of the given $childNodeName (which must be auto-created in $this NodeType).

bool
isNodeTypeAllowedByConstraints(NodeType $nodeType, array $constraints)

Internal method to check whether the passed-in $nodeType is allowed by the $constraints array.

bool
isNodeTypeAllowedByDirectConstraints(NodeType $nodeType, array $constraints)

No description

bool|null
isNodeTypeAllowedByInheritanceConstraints(NodeType $nodeType, array $constraints)

This method loops over the constraints and finds node types that the given node type inherits from. For all matched super types, their super types are traversed to find the closest super node with a constraint which is used to evaluated if the node type is allowed. It finds the closest results for true and false, and uses the distance to choose which one wins (lowest). If no result is found the node type is allowed.

int
traverseSuperTypes(NodeType $currentNodeType, string $constraintNodeTypeName, int $distance)

This method traverses the given node type to find the first super type that matches the constraint node type.

void
setFullConfiguration(array $fullConfiguration)

No description

string
__toString()

Alias for getName().

Details

__construct(string $name, array $declaredSuperTypes, array $configuration)

Constructs this node type

Parameters

string $name

Name of the node type

array $declaredSuperTypes

Parent types of this node type

array $configuration

the configuration for this node type which is defined in the schema

Exceptions

InvalidArgumentException

protected void initialize()

Initializes this node type

Return Value

void

Exceptions

InvalidNodeTypePostprocessorException
Exception

protected array buildFullConfiguration()

Builds the full configuration by merging configuration from the supertypes into the local configuration.

Return Value

array

static protected array getFlattenedSuperTypes(NodeType $nodeType)

Returns a flat list of super types to inherit from.

Parameters

NodeType $nodeType

Return Value

array

protected array applyPostprocessing(array $fullConfiguration)

Iterates through configured postprocessors and invokes them

Parameters

array $fullConfiguration

Return Value

array

Exceptions

InvalidNodeTypePostprocessorException

string getName()

Returns the name of this node type

Return Value

string

bool isAbstract()

Return boolean true if marked abstract

Return Value

bool

bool isFinal()

Return boolean true if marked final

Return Value

bool

NodeType[] getDeclaredSuperTypes()

Returns the direct, explicitly declared super types of this node type.

Note: NULL values are skipped since they are used only internally.

Return Value

NodeType[]

bool isAggregate()

Returns whether this node type (or any parent type) is an aggregate.

The most prominent aggregate is a Document and everything which inherits from it, like a Page.

If a node type is marked as aggregate, it means that:

  • the node type can "live on its own", i.e. can be part of an external URL
  • when moving this node, all node variants are also moved (across all dimensions)
  • Recursive copying only happens inside this aggregate, and stops at nested aggregates.

Return Value

bool

true if the node type is an aggregate

bool isOfType(string $nodeType)

If this node type or any of the direct or indirect super types has the given name.

Parameters

string $nodeType

Return Value

bool

true if this node type is of the given kind, otherwise false

array getLocalConfiguration()

Get the local configuration of the node type. Should only be used internally.

Note: post processing is not applied to this.

Return Value

array

array getFullConfiguration()

Get the full configuration of the node type. Should only be used internally.

Instead, use the hasConfiguration()/getConfiguration() methods to check/retrieve single configuration values.

Return Value

array

bool hasConfiguration(string $configurationPath)

Checks if the configuration of this node type contains a setting for the given $configurationPath

Parameters

string $configurationPath

The name of the configuration option to verify

Return Value

bool

mixed getConfiguration(string $configurationPath)

Returns the configuration option with the specified $configurationPath or NULL if it does not exist

Parameters

string $configurationPath

The name of the configuration option to retrieve

Return Value

mixed

string getLabel()

Get the human-readable label of this node type

Return Value

string

array getOptions()

Get additional options (if specified)

Return Value

array

NodeLabelGeneratorInterface getNodeLabelGenerator()

Return the node label generator class for the given node

array getProperties()

Return the array with the defined properties. The key is the property name, the value the property configuration. There are no guarantees on how the property configuration looks like.

Return Value

array

string getPropertyType(string $propertyName)

Returns the configured type of the specified property

Parameters

string $propertyName

Name of the property

Return Value

string

array getDefaultValuesForProperties()

Return an array with the defined default values for each property, if any.

The default value is configured for each property under the "default" key.

Return Value

array

NodeType[] getAutoCreatedChildNodes()

Return an array with child nodes which should be automatically created

Return Value

NodeType[]

the key of this array is the name of the child, and the value its NodeType.

bool hasAutoCreatedChildNode(NodeName $nodeName)

No description

Parameters

NodeName $nodeName

Return Value

bool

true if $nodeName is an autocreated child node, false otherwise

NodeType|null getTypeOfAutoCreatedChildNode(NodeName $nodeName)

No description

Parameters

NodeName $nodeName

Return Value

NodeType|null

Exceptions

NodeTypeNotFoundException

bool allowsChildNodeType(NodeType $nodeType)

Checks if the given NodeType is acceptable as sub-node with the configured constraints, not taking constraints of auto-created nodes into account. Thus, this method only returns the correct result if called on NON-AUTO-CREATED nodes!

Otherwise, allowsGrandchildNodeType() needs to be called on the parent node type.

Parameters

NodeType $nodeType

Return Value

bool

true if the $nodeType is allowed as child node, false otherwise.

bool allowsGrandchildNodeType(string $childNodeName, NodeType $nodeType)

Checks if the given $nodeType is allowed as a childNode of the given $childNodeName (which must be auto-created in $this NodeType).

Only allowed to be called if $childNodeName is auto-created.

Parameters

string $childNodeName

The name of a configured childNode of this NodeType

NodeType $nodeType

The NodeType to check constraints for.

Return Value

bool

true if the $nodeType is allowed as grandchild node, false otherwise.

Exceptions

InvalidArgumentException

protected bool isNodeTypeAllowedByConstraints(NodeType $nodeType, array $constraints)

Internal method to check whether the passed-in $nodeType is allowed by the $constraints array.

$constraints is an associative array where the key is the Node Type Name. If the value is "true", the node type is explicitly allowed. If the value is "false", the node type is explicitly denied. If nothing is specified, the fallback "*" is used. If that one is also not specified, we DENY by default.

Super types of the given node types are also checked, so if a super type is constrained it will also take affect on the inherited node types. The closest constrained super type match is used.

Parameters

NodeType $nodeType
array $constraints

Return Value

bool

protected bool isNodeTypeAllowedByDirectConstraints(NodeType $nodeType, array $constraints)

No description

Parameters

NodeType $nodeType
array $constraints

Return Value

bool

true if the passed $nodeType is allowed by the $constraints

protected bool|null isNodeTypeAllowedByInheritanceConstraints(NodeType $nodeType, array $constraints)

This method loops over the constraints and finds node types that the given node type inherits from. For all matched super types, their super types are traversed to find the closest super node with a constraint which is used to evaluated if the node type is allowed. It finds the closest results for true and false, and uses the distance to choose which one wins (lowest). If no result is found the node type is allowed.

Parameters

NodeType $nodeType
array $constraints

Return Value

bool|null

if no constraint matched

protected int traverseSuperTypes(NodeType $currentNodeType, string $constraintNodeTypeName, int $distance)

This method traverses the given node type to find the first super type that matches the constraint node type.

In case the hierarchy has more than one way of finding a path to the node type it's not taken into account, since the first matched is returned. This is accepted on purpose for performance reasons and due to the fact that such hierarchies should be avoided.

Parameters

NodeType $currentNodeType
string $constraintNodeTypeName
int $distance

Return Value

int

or NULL if no NodeType matched

protected void setFullConfiguration(array $fullConfiguration)

No description

Parameters

array $fullConfiguration

Return Value

void

string __toString()

Alias for getName().

Return Value

string