in Alfresco

Alfresco share – working with custom content types

Introduction

Previously we have showed how to create a module for alfresco and share , this will come handy for you here as you need to know how to deploy custom content types for alfresco and custom settings for share. You can find this blog posts :

In this post we are going to explain how to set up share so it would allow you to work with custom types, aspects and properties that you have defined in your custom model.

Previously we have created one aspect type with come custom properties, both aspect and model is listed below .

 

ab:invoice aspect represents an invoice in our system

 <aspect name="ab:invoice">
   <title>Invoice</title>
   <properties>
     <property name="ab:invDate">
       <type>d:datetime</type>
     </property>
     <property name="ab:invNumber">
       <type>d:int</type>
     </property>
     <property name="ab:Value">
       <type>d:float</type>
     </property> 
   </properties>
 </aspect>

ab:invoiceFolder is a custom type meant to hold a list of files with aspect ab:invoice and total values of invoices will be written in ab:total property.

 <type name="ab:invoiceFolder">
    <title>Invoice Folder</title>
    <parent>cm:folder</parent>
    <properties>
      <property name="ab:total">
        <type>d:float</type>
        <mandatory>true</mandatory>
        <default>0.0</default>
     </property>
   </properties>
  </type>

 

Share Custumization

After model has been deployed share UI must be set so it would allow user to manage aspect ab:invoice, to create rules that depend on this aspect . To change the folder type to our custom type cm:invoiceFolder .

In share module project and in share-config-custom.xml we need to add next xml in order to accomplish this .

<!-- Document Library config section -->
 <config evaluator="string-compare" condition="DocumentLibrary">

 <aspects>
   <!-- Aspects that a user can see -->
   <visible>
     <aspect name="ab:invoice" />
   </visible>

   <!-- Aspects that a user can add. Same as "visible" if left empty -->
   <addable>
   </addable>

   <!-- Aspects that a user can remove. Same as "visible" if left empty -->
   <removeable>
   </removeable>
 </aspects>
 <types>
   <type name="cm:folder">
     <subtype name="invoiceFolder" />
   </type>
 </types>
</config>

This xml allows share to show our custom type and aspect . Lets see list of images that demonstrate this.

a

Changing type of folder to Invoice Folder

b

Managing aspects

Setting aspect criteria when creating new rule

Setting aspect criteria when creating new rule

d

Performing adding aspect when rule is triggered

Form configuration

Aspects and types have properties of their own, it is important to allow this properties to be seen in share UI to ther user. There are two places where properties values can be seen and in the properties form and document details.

We will demonstrate this in ab:invoice aspect that we have previously added to one of the files. To add this three properties we will use next xml that is to be added to share-config-custom.xml.

<config evaluator="aspect" condition="ab:invoice">
 <forms>
   <form>
     <field-visibility>
       <show id="ab:invDate" />
       <show id="ab:invNumber" />
       <show id="ab:value" />
     </field-visibility>
     <appearance> 
      <field id="ab:invDate" label-id="prop.ab_invDate" />
      <field id="ab:invNumber" label-id="prop.ab_invNumber" />
      <field id="ab:value" label-id="prop.ab_value" />
     </appearance>
   </form>
 </forms>
</config>

Lets spend a moment to see the code, ab:invoice is an aspect therefore we have

<config evaluator="aspect" condition="ab:invoice">...

, we can see two things in form tag, field-visibility and appearance , first one defines list of properties that will be shown or hidden and other how are they rendered. Lets go through them in more details.

field-visibility tag
  • Field-visibility is not mandatory tag, if it is not listed then all of the properties will be shown
  • If there is one or more hide tags then rest of them not specified will be shown
  • If we have one show tag that will be the only properties that will remain visible

show tag

  • id(mandatory, string), represents unique identifier
  • for-mode( optional, comma separated) defines when this field should appear , possible values are “view”, “edit” and “create”

hide tag

  • id(mandatory, string), represents unique identifier
  • for-mode( optional, comma separated) defines when this field should not appear , possible values are “view”, “edit” and “create
Appearance

Appearance defines look and feel of visible fields, it can contain two types of tags, set and field.

Set

  • id(mandatory, string), specifies unique identification of the property
  • parent(optional, string), Allows sets to be nested, the value should reference the identifier of a valid set definition previously defined.
  • appearance, Specifies how the set will be rendered, currently the supported allowable values are “fieldset”, “panel”, “bordered-panel”, “title” and “whitespace”. If an appearance attribute is not supplied the set will not be rendered, whereas if it is set to “” (empty string) the set will be rendered, but without any decoration.
  • template(optional, string): Specifies the absolute path to the template to be used when the set is rendered, allowing the layout of the set’s fields to be customized.
  • label-id (optional, string): Specifies the resource bundle key of the string to use for the set’s label, this attribute takes precedence if the label attribute is also present.
  • label (optional, string): Specifies the set’s label.
   <set id="dublin-core" appearance="bordered-panel" label="Dublin Core" />

Field

  • id (mandatory, string): Specifies the field to be customized, the field id, however, does not have to be present within the field-visibility element.
  • label-id (optional, string): Specifies the resource bundle key of the string to use for the field’s label, this attribute takes precedence if the label attribute is also present.
  • label (optional, string): Specifies the field’s label.
  • description-id (optional, string): Specifies the resource bundle key of the string to use for the field’s tooltip, this attribute takes precedence if the description attribute is also present.
  • description (optional, string): Specifies the field’s tooltip.
  • help-id (optional, string): Specifies the resource bundle key of the string to use for the field’s help text, this attribute takes precedence if the help attribute is also present.
  • help (optional, string): Specifies the field’s help text.
  • read-only (optional, boolean): Informs the form UI generation template whether the field should be rendered as editable when the form is in “edit” or “create” mode.
  • mandatory (optional, boolean): Marks the field as mandatory, this will add a mandatory validation handler to the form so that the form can only be submitted once all data has been provided. A required field marker will normally be rendered as well. Note that if a field is returned from the server marked as mandatory, setting this attribute has no effect, the field will always be mandatory.
  • set (optional, string): Specifies the id of a previously defined set. If the attribute is omitted the field belongs to the default set.
Summary

This concludes this short tutorial on how to set share to allow you to manage aspects and types in rules and forms.

Don't be shellfish...Tweet about this on TwitterShare on LinkedInShare on Google+Share on RedditShare on Facebook

Was this helpful ?

  1. Why there is no ‘Invoice Folder’ label displayed in Change Type popup? It’s showing type.invoiceFolder. What needs to be done if I want to see title over there?