How to add custom attributes to content

I want to attach some custom attributes for e.g. weight (numeric) which uploading content using the DAM admin console. I also want to be able to fire a range query on this numeric field. From the 'Edit' section of the content, I could not find any way to add this custom field. Could you please suggest some way to do this? I may have to add multiple such attributes in future. Any help is really appreciated.

0 votes

1 answers

1701 views

ANSWER



To add custom attributes you need to load your own “layouts” which contains your desired attributes. You can add as many fields as u want.

Create a file layout-contrib.xml file. You can define ur fields through widgets. In nuxeo, each field/attribute is defined through widget. Write your widget in layout-contrib.xml. For example,

    <extension target="org.nuxeo.ecm.platform.forms.layout.WebLayoutManager"
    point="layouts">
    <layout name="My_layout">

        <templates>
            <template mode="any">/layouts/layout_default_template.xhtml
            </template>
        </templates>

        <rows>
            <row>
                <widget>weight_widget</widget>
            </row>

     <widget name="weight_widget" type="int">
        <labels>
                <label mode="any">Weight </label>
        </labels>
            <translated>false</translated>
            <fields>
                <field>lds:int_field</field>
            </fields>
        _   <properties widgetMode="edit">
                <property name="required">true</property>
            </properties>_
        </widget>

    </layout>

</extension>

Define your own schema, for example layout_demo_schema and declare it in core_types-contrib.xml as below.

<schema name="layout_demo_schema" prefix="lds"
        src="schema/layout_demo_schema.xsd" />

You need to define int_field type in layout_demo_schema.

In ui-types-contrib.xml file define your custom document type and dont forget to declare the layout for document. Consider the below,

    <type id="Custom_file_type">
        <icon>/icons/file.gif</icon>
        <bigIcon>/icons/file_100.png</bigIcon>
        <label>Custom_file_type</label>
        <description />
        <category>SimpleDocument</category>
        <default-view>view_documents</default-view>
        <layouts mode="any">
            <layout>My_layout</layout>
        </layouts>
    </type>

I got the solution like this. Hope you will find this helpful.

0 votes