Creating a new content type


Location

All the files related to a new content type are located in the WEB-INF/param/content-types directory (content-types directory is not created by default).

Directories structure

"content-types" directory structure :

"web" : plugin name. Usually set as "web", but can be changed. If changed, the rendering must be managed too. (TODO)
"resources" : contains resources of this content (images).
"stylesheets" : contains the view stylesheets of this content.
"simple-content.xml" : Configuration file of the content. "simple-content" will be the ID of this content.

"resources" directory structure : 

"img" : the directory containing all the images.

The 3 image files are the content type icons.
The only mandatory directory is "img". The path "content/<filename>" is defined in the xml configuration file.

"stylesheets" directory structure :

Under the directory "stylesheets", we must have a directory named with the ID of the content (to remind, the ID is defined by the name of the xml configuration file).
Under this directory, we have all the stylesheets representing the views of this content. These files must be named as follow : <content id>-<view name>.xsl (view names are defined in the xml configuration file)

Configuration file

This configuration file must start with

<?xml version="1.0" encoding="UTF-8" ?>
<cms:content-type
    xmlns:cms="http://www.ametys.org/schema/cms">

and end with

</cms:content-type>


Inside this cms:content-type tag, first a content type label must be defined, as follow :

<cms:label i18n="true">CONTENT_SIMPLE_LABEL</cms:label>

The i18n attribute specify whether the text is an i18n key. If set to "true", the i18n key must be defined in the default dictionary, located in WEB-INF/i18n.
The label is used when selecting the content type to insert it :

In this image, outlined in red.


Then, we must insert a description :

 <cms:description i18n="false">Contenu simple Ametys</cms:description>

with the same i18n attribute than in the label tag. Here set to "false" so the text is displayed directly, as seen in the image below.
Displayed in a tooltip in the content type selection window :


You add the content type icon :

<cms:icons>
        <cms:small>img/content/simple_16.png</cms:small>
        <cms:medium>img/content/simple_32.png</cms:medium>
        <cms:large>img/content/simple_50.png</cms:large>
</cms:icons>

Small : used when the content is inserted in the page :

Medium ?: used in the content type insertion window :

Large : Not used for the moment.


Now, you can add all the metadata of this content type. For example : 

<cms:metadata name="title" type="string">
    <label i18n="true">CONTENT_SIMPLE_TITLE</label>
    <description i18n="true">CONTENT_SIMPLE_TITLE_DESC</description>
    <validation>
        <mandatory />
    </validation>
</cms:metadata>

In this example, we add a string metadata named "title".
 -> Available metadata types are ?: binary, boolean, composite, date, double, file, long, reference, rich-text, string, user.
We still have an "i18n" attribute for label and description.
For the "validation" tag, we have different child tag possible :
   - mandatory : this metadata is mandatory
   - regexp : a regexp to validate the metadata input
   - custom-validator : a java class which must inherit org.ametys.runtime.util.parameter.Enumerator to validate the input


Now we define all the metadata-set.
The metadata-set are definitions of the content "views" ; it indicates which metadata to use for each content "view" :

<cms:metadata-set name="main" type="view">
    <cms:metadata-ref name="content" />
    <cms:metadata-ref name="seo">
        <cms:metadata-ref name="keywords" />
        <cms:metadata-ref name="subject" />
        <cms:metadata-ref name="description" />
    </cms:metadata-ref>
</cms:metadata-set>

In this example, we define the "main" view of this content ; "content", "seo" ("keyword", "subject" and "description") metadata will be accessible in this view.
NB : Please note that for a "composite" metadata (you can see in the full example below that "seo" is a composite metadata), we can define the accessibility of its sub-metadata too.
NB : All the metadata used in the view definitions must be created as seen above.


Finally, we have an edition metadata-set to defined. This metadata-set is used to define all the metadata which can be edited.

 <cms:metadata-set name="main" type="edition">
    <cms:metadata-ref name="title" />
    <cms:metadata-ref name="content" />
    <cms:metadata-ref name="seo">
        <cms:metadata-ref name="keywords" />
        <cms:metadata-ref name="subject" />
        <cms:metadata-ref name="description" />
    </cms:metadata-ref>
</cms:metadata-set>

The definition of this metadata-set is the same as the views metadata-set.
NB : "type" and "name" attributes must always keep the same value as in this example.



Here is a full example of the configuration file :

 <?xml version="1.0" encoding="UTF-8" ?>

<cms:content-type
    xmlns:cms="http://www.ametys.org/schema/cms">

    <cms:label i18n="true">CONTENT_SIMPLE_LABEL</cms:label>

    <cms:description i18n="true">CONTENT_SIMPLE_DESCRIPTION</cms:description>

    <cms:icons>
        <cms:small>img/content/simple_16.png</cms:small>
        <cms:medium>img/content/simple_32.png</cms:medium>
        <cms:large>img/content/simple_50.png</cms:large>
    </cms:icons>

    <!-- Metadata of this content type -->
    <cms:metadata name="title" type="string">
        <label i18n="true">CONTENT_SIMPLE_TITLE</label>
        <description i18n="true">CONTENT_SIMPLE_TITLE_DESC</description>
        <validation>
            <mandatory />
        </validation>
    </cms:metadata>

    <cms:metadata name="content" type="rich-text">
        <label i18n="true">CONTENT_SIMPLE_CONTENT</label>
        <description i18n="true">CONTENT_SIMPLE_CONTENT_DESC</description>
        <validation>
            <mandatory />
        </validation>
    </cms:metadata>

    <cms:metadata name="seo" type="composite">
        <label i18n="true">CONTENT_SIMPLE_SEO</label>
        <description i18n="true">CONTENT_SIMPLE_SEO_DESC</description>
        <cms:metadata name="keywords" type="string" multiple="true">
            <label i18n="true">CONTENT_SIMPLE_SEO_KEYWORDS</label>
            <description i18n="true">CONTENT_SIMPLE_SEO_KEYWORDS_DESC</description>
        </cms:metadata>
        <cms:metadata name="subject" type="string">
            <label i18n="true">CONTENT_SIMPLE_SEO_SUBJECT</label>
            <description i18n="true">CONTENT_SIMPLE_SEO_SUBJECT_DESC</description>
        </cms:metadata>
        <cms:metadata name="description" type="string">
            <label i18n="true">CONTENT_SIMPLE_SEO_DESCRIPTION</label>
            <description i18n="true">CONTENT_SIMPLE_SEO_DESCRIPTION_DESC</description>
        </cms:metadata>
    </cms:metadata>
    <!-- End of metadata -->

    <!-- Edition dataset -->
    <!-- Used to defined what metadata can be edited -->
    <cms:metadata-set name="main" type="edition">
        <cms:metadata-ref name="title" />
        <cms:metadata-ref name="content" />
        <cms:metadata-ref name="seo">
            <cms:metadata-ref name="keywords" />
            <cms:metadata-ref name="subject" />
            <cms:metadata-ref name="description" />
        </cms:metadata-ref>
    </cms:metadata-set>
    

    <!-- VIEWS -->
    <cms:metadata-set name="main" type="view">
        <cms:metadata-ref name="content" />
        <cms:metadata-ref name="seo">
            <cms:metadata-ref name="keywords" />
            <cms:metadata-ref name="subject" />
            <cms:metadata-ref name="description" />
        </cms:metadata-ref>
    </cms:metadata-set>

    <cms:metadata-set name="abstract" type="view">
        <cms:metadata-ref name="content" />
    </cms:metadata-set>

    <cms:metadata-set name="link" type="view">
        <cms:metadata-ref name="content" />
    </cms:metadata-set>

</cms:content-type>

NOTE : For advanced use, you can see this xsd file : https://svn.ametys.org/trunk/runtime/trunk/main/kernel/src/org/ametys/runtime/plugin/plugin.xsd .

Indexation

By default, only the "rich-text" metadata are indexed.

If other metadata have to be indexed, a view "index" must be created. The configuration of this view is the same as the other views, adding only the metadata wich have to be indexed.

<!-- Indexation view -->
    <cms:metadata-set name="index" type="view">
        <cms:metadata-ref name="seo">
            <cms:metadata-ref name="keywords" />
            <cms:metadata-ref name="subject" />
            <cms:metadata-ref name="description" />
        </cms:metadata-ref>
    </cms:metadata-set>

In this example, "keywords", "subject" and "description" of the composite metadata "seo" will be indexed.

All the metadata type can be indexed except reference !

Back to top