Written by The Jahia Team
   Estimated reading time:

How to create my own new picker that only allow to pick a type of node?



Imagine that we want to create a picker that only allow to pick nodes with the mixin jmix:testNodeType

So first, let's declare this mixin:

[jmix:testNodeType] mixin

And let's declare a few components that use this mixin

[jnt:nodeType1] > jnt:content, jmix:basicContent, jmix:testNodeType, jmix:editorialContent
 - prop1 (string)

[jnt:nodeType2] > jnt:content, jmix:basicContent, jmix:testNodeType, jmix:editorialContent
 - prop2 (string)

[jnt:nodeType3] > jnt:content, jmix:basicContent, jmix:testNodeType, jmix:editorialContent
 - prop3 (string)

Now, we want to declare a new component with a weakreference property that only allow us to pick nodes with the mixin jmix:testNodeType.

[jnt:nodeTypePicker] > jnt:content, jmix:basicContent
 - nodeTypeRef (weakreference, picker[type='testNodeType'])

To do that, we first need to create a new picker with this name testNodeType.

In the module spring file, we can declare a new bean testNodeTypepicker.  Note that the ID of the bean need to be an aggregation of the name of the picker (testNodeType) followed by "picker".

Let's set the editorialpicker as the parent, so we can browse all the folderTypes from the editorial picker.
And then, we will redefine the list of nodeTypes we want to allow in our testNodeType picker:

So this new picker will look like this:

 <bean id="testNodeTypepicker" parent="editorialpicker">
    <property name="nodeTypes">

Note that the editorial picker will only allow you to browse the following list of nodes. This list is defined in the applicationcontext-contentpicker.xml 

  • jnt:page
  • jnt:navMenuText
  • jnt:virtualsite
  • jnt:contentList
  • jnt:contentFolder
  • nt:folder
  • jmix:siteContent
  • jmix:browsableInEditorialPicker

So maybe you will need to add the jmix:browsableInEditorialPicker mixin to some of your definitions if you need to browse them (open from the left panel).