Magnolia 5.7 reached extended end of life on May 31, 2022. Support for this branch is limited, see End-of-life policy. Please note that to cover the extra maintenance effort, this EEoL period is a paid extension in the life of the branch. Customers who opt for the extended maintenance will need a new license key to run future versions of Magnolia 5.7. If you have any questions or to subscribe to the extended maintenance, please get in touch with your local contact at Magnolia.
This page provides an overview of all ways to define custom JCR node types and create new workspaces with Magnolia.
Even though it has always been possible to define node types and create workspaces within Magnolia Maven modules, the Content Types module brings this functionality also to the light modules. Both approaches are valid.
Whichever approach you choose, we recommend not to develop and refine these definitions in a productive environment.
Editing node type and workspace definitions can lead to new node type definitions and workspaces which are registered again, whereas the system keeps the "old" ones which become obsolete.
With content types
By utilizing the magnolia-content-types
module you can define custom JCR content types and workspaces within light modules.
Defining content types within light modules can be accomplished on a running Magnolia system without redeploying the WAR file of your Magnolia instances and without restarting the instance or a module. This makes it a perfect approach if you have a Magnolia Cloud subscription package.
A content type definition in one file
You can define all of the following in just one file:
- JCR workspace
- JCR nodetype
This node type inherits from the Magnolia node typemgnl:content
. To define more sophisticated node types, you can create a node type definition file in a light module. - JCR namespace
Example
datasource: workspace: tourguides namespaces: mt: https://www.magnolia-travel.com/jcr/1.0/mt autoCreate: true model: nodeType: mt:tourGuide properties: - name: birthday type: Date - name: gender - name: shortBio
Defining and using a node type definition
You can define an XML-based node type definition. Since this definition must be readable as a Magnolia Resource, it can be a file in a light module or in a JAR file or in the resources
JCR workspace.
The XML node type definition resource is loaded only if the XML resource is referenced in the Content type Data source definition of a Content type definition.
Example:
Create an XML-based node type definition file in your light module:
/content-type-examples/jcr-node-type-files/travellers-node-types.xml<nodeTypes xmlns:mgnl="http://www.magnolia.info/jcr/mgnl" xmlns:mt="https://www.magnolia-travel.com/jcr/1.0/mt"> <nodeType name="mt:traveller" isMixin="false" hasOrderableChildNodes="true" primaryItemName=""> <supertypes> <supertype>mgnl:content</supertype> </supertypes> </nodeType> <nodeType name="mt:tourGuide" isMixin="false" hasOrderableChildNodes="true" primaryItemName=""> <supertypes> <supertype>mt:traveller</supertype> </supertypes> </nodeType> <nodeType name="mt:happyCustomer" isMixin="false" hasOrderableChildNodes="true" primaryItemName=""> <supertypes> <supertype>mt:traveller</supertype> </supertypes> </nodeType> </nodeTypes>
Reference the node type definition from a content type definition:
Line 4: References the node type definition resource via/content-type-examples/contentTypes/happyCustomer.yamldatasource: workspace: happycustomers autoCreate: true nodeTypeDefinition: /content-type-examples/jcr-node-type-files/travellers-node-types.xml model: nodeType: mt:happyCustomer properties: - name: country - name: age type: Double
nodeTypeDefinition
.
With a Magnolia Maven module descriptor
With Magnolia Maven modules you can register new JCR workspaces and node types. The registration involves the XML-based module descriptor.
Magnolia registers workspaces and node types during a module's start-up phase in case they have not yet been registered.
Example of a module descriptor:
Workspaces
In the XML-based module descriptor you can add a <workspace />
section in /repositories/repository/workspaces
.
<workspaces> <workspace>products</workspace> </workspaces>
Node types
To define and register new node types requires two things:
Creating an XML-based node type definition where you define the required node types and name spaces. Create the XML file in the
my-maven-module/src/main/resources/mgnl-nodetypes/
folder.
Example:my-maven-module/src/main/resources/mgnl-nodetypes/my-node-types.xml<nodeTypes xmlns:mgnl="http://www.magnolia.info/jcr/mgnl" xmlns:mgnld="https://www.magnolia-cms.com/jcr/mgnld"> <nodeType name="mgnld:product" isMixin="false" hasOrderableChildNodes="true" primaryItemName=""> <supertypes> <supertype>mgnl:content</supertype> </supertypes> </nodeType> </nodeTypes>
Referencing the node type file in the XML-based module descriptor:
Example:my-maven-module/src/main/resources/META-INF/magnolia/my-module.xml (fragment)<nodeTypeFile>/mgnl-nodetypes/my-node-types.xml</nodeTypeFile>