category picker Jahia 7.3

Specific category picker

Question

Is it possible to have a category picker, which shows a subtree of categories instead the full tree?

Answer

A possibility is to define an own category picker, with a specific startPath. This can be done in a module.

First you have to define an custom workspace with the correct startPath in the spring config of your module like:

      <bean id="repository.category.companies" class="org.jahia.services.uicomponents.bean.contentmanager.Repository">
        <property name="key" value="companyCategoryRepository"/>
        <property name="paths" value="$systemsite/categories/companies"/>
        <property name="titleKey"
                  value="repository.categoryCompaniesRepository.label@resources.pickerexample"/>
      </bean> 

In this example the startPath $systemsite/categories/companies is used (which is from categories, from the example digitall webproject).

Also you have to specify a titleKey. In the example it is "repository.categoryCompaniesRepository.label", as you can see the label, can be added in the resource bundles of the module where you define this repostory. With @resources.pickerexample you specify the right bundle in my case it is the resource bundle from the pickerexample module.

The id (and also the key property) of this repository must be unique. So it is recommended to add path specific prefix or suffix (in example above company or companies is added).

Next step is to define the picker itself. For that you can inherit from the default category picker, and just change the titleKey and the used repository. So it looks like:

    <bean id="companyCategorypicker" parent="categorypicker">
         <property name="titleKey"
                  value="label.companyCategorypicker@resources.pickerexample"/>
        <property name="repositories">
            <list>
                <ref bean="repository.category.companies"/>
            </list>
        </property>    
    </bean> 

Again, the titleKey could be stored in the module. You have to use again a unique id for this picker.

 

After that the new picker can be used in your field definitions like:

  - j:myCategory (weakreference, picker[type='companyCategory']) facetable hierarchical multiple 

You have to specify the picker and as type the id of your picker (without suffix picker).

Now for this field the new category picker is used.