HTTP content service makeover

Enonic CMS 4.4 offers an overhauled version of the content service in the HTTP Services API; A modify content-operation is introduced, the support for handling advanced custom content has been improved and the documentation has been refreshed and further detailed.

The content service is used to create, update or delete custom content in the content repository.  While most of the HTTP Service API - operations have been reviewed in the 4.4 release, this service has undergone the most notable changes:

Supported custom content input types

With the exception of the type "Multiple Choice", all custom content input types are now fully supported through the content HTTP-service.

Grouped content support

Its now possible to create, update and modify custom content with grouped content input types through the HTTP Services API.

To submit grouped content-values, the input elements must be named on the format:

<block group name>[<index>].<content data input name>

E.g., for a group named "myGroup" containing 3 input-types "fish", "cheese" and "onion", the input name for three group-entries should be:

myGroup[1].fish
myGroup[1].cheese
myGroup[1].onion

myGroup[2].fish
myGroup[2].cheese
myGroup[2].onion

myGroup[3].fish
myGroup[3].cheese
myGroup[3].onion

Modify operation

A modify custom content operation is introduced, replacing the undocumented, limited modify-operation available in earlier versions. This makes it possible to submit only the values to be changed, while other data remains unchanged. As an example, consider this form:

<form action="portal:createServicesUrl('content','update', portal:createPageUrl(portal:getPageKey(), ('success', 'true')), ())"
     method="post">
    <input type="hidden" name="categorykey" value="{$category-key}"/>
    <input type="hidden" name="key" value="{$selected-content/@key}"/>
    
    <input name="title" type="hidden" value="{contentdata/title}"/>
    <xsl:value-of select="contentdata/title"/>
    <input name="descr" type="hidden" value="{contentdata/descr}"/>
    <xsl:value-of select="contentdata/descr"/>
    <input name="startdate" type="hidden" value="{contentdata/startdate}"/>
    <xsl:value-of select="contentdata/startdate"/>
    <input name="enddate" type="hidden" value="{contentdata/enddate}"/>
    <xsl:value-of select="contentdata/enddate"/>

    <input name="status" type="text" value="{contentdata/status}"/>
    <input type="submit" value="Update" />
</form>

The input named "status" is the only value to be changed by the user of this form, the other fields are just submitted to preserve the existing values. This form can be rewritten using the "modify" - operation:

<form action="portal:createServicesUrl('content','modify', portal:createPageUrl(portal:getPageKey(), ('success', 'true')), ())"
     method="post">
    <input type="hidden" name="categorykey" value="{$category-key}"/>
    <input type="hidden" name="key" value="{$selected-content/@key}"/>

    <xsl:value-of select="contentdata/title"/>    
    <xsl:value-of select="contentdata/descr"/>
    <xsl:value-of select="contentdata/startdate"/>
    <xsl:value-of select="contentdata/startdate"/>            

    <input name="status" type="text" value="{contentdata/status}"/> 
    <input type="submit" value="Modify" />
</form>

Uploadfile type input

Submitting values to uploadfile-inputs has been changed:

  • New binaries should be submitted in a key named "<inputname>_new"
  • Existing binaries should be submitted in a key named "<inputname>"

Consider this sample form, submitting values to the custom content input entry named "myuploadfile":

<form action="portal:createServicesUrl('content','update', portal:createPageUrl(portal:getPageKey(), ('success', 'true')), ())"
     method="post">
    <input type="hidden" name="categorykey" value="{$category-key}"/>
    <input type="hidden" name="key" value="{$selected-content/@key}"/>    

    <input name="title" type="text" value="{contentdata/title}"/>
    <input name="myuploadfile" type="text" value="{contentdata/myuploadfile/binarydata/@key}"/>
    <input name="myuploadfile_new" type="file" />        

    <input type="submit" value="Update" />              
</form>

If a value exists in the "myuploadfile_new" input, this will overwrite any value in the "myuploadfile" input. To remove an existing binary from the content, the "myuploadfile" input should be submitted empty.

Updated documentation

The online documentation available at the community contains detailed instructions on how to use the content HTTP service to manipulate custom content.

Comments

If you want to comment on this article you need to be logged in.

Published in 2011

2010

2009

2008

2007