Developer forum

Forum » Development » How to use Items API?

How to use Items API?

Morten Bengtson
Reply
I have some questions related to the Items API as I am using it on a project that I am currently working on...
  • How can we implement a creation rule to prevent certain items types from being created on a paragraph?
  • How can we add a list property on our custom item class? I'm trying to add an EditableList.
  • How can we implement/add configuration options for custom field editors?
  • How can we use the API to search for items, e.g. find all items of a given type where "MyField" contains a specific value?
  • How can we import/export items and item types - e.g. export items for translation then import again, create new item types defined in external source?

 


Replies

 
Morten Bengtson
Reply

... And how can we select a default template for a given item type?

 
Pavel Volgarev
Reply
This post has been marked as an answer

Hi Morten,

 

How can we implement a creation rule to prevent certain items types from being created on a paragraph?

 

There's currently no way of doing so. The context object that is passed to creation rule's "CanCreate" method contains a "StructureType" property which indicates whether the item is about to be created for page, paragraph or website. But this property is only set when creating items for websites. Furthermore the paragraph Id is not passed along with the context (you can probably get it from the query-string but that's not a recommended way).

 

How can we add a list property on our custom item class? I'm trying to add an EditableList.

 

The property must be a declared as "public IList<string> [property name]":

 

public class Article : ItemEntry
{
    public IList<string> Tags { get; set; }
}

 

How can we implement/add configuration options for custom field editors?

 

This is not possible yet.

 

How can we use the API to search for items, e.g. find all items of a given type where "MyField" contains a specific value?

 

All currently available query methods are exposed by "Dynamicweb.Content.Items.Queries.Repository". We plan to implement a comprehensive query model in a near future (I see it as LINQ provider).

 

How can we import/export items and item types - e.g. export items for translation then import again, create new item types defined in external source? And how can we select a default template for a given item type?

 

If you have items in DB, you can just translate them and move the DB tables with translated data into Dynamicweb. It will create item types based on table schema. If you're translating field names, you can edit schema files (.xml files inside /Files/System/Items) and move them afterwards. Metadata is fully represented in the API and can be accessed and manipulated via "Dynamicweb.Content.Items.ItemManager.Metadata" object.

 

-- Pavel

 

Votes for this answer: 1
 
Morten Bengtson
Reply

Hi Pavel,

 

Thanks for all your answers. Adding a LINQ provider sounds like great idea. If this could be implemented for all content in Dynamicweb it would be even better :) I know that we can use LINQ to Objects almost anywhere, but that doesn't beat an actual LINQ provider.

 

I'm not sure I understand your answer regarding import/export. What we really need is the possibility to export items (not item types) as XML, which we then send to another company that will translate text content into other languages and finally we import the translated versions of the items back into Dynamicweb. We don't need new item types for this. It's just like the import/export under websites (which unfortunately does not include items).

 

And how can we select a default layout template for a given item type? Is it not possible?

 

/Morten

 

 
Kristian Knudsen
Reply
This post has been marked as an answer

About the default layout template question, you can define the default layout for all your item types under the website settings. 

 

DefaultLayout.png
Votes for this answer: 1
 
Morten Bengtson
Reply

Thanks Kristian, that was exactly what I needed :)

 
Jonas Dam
Reply
This post has been marked as an answer

Hi Morten,

I can try to answer the Import/export question for you.

 

As I understand your question, you have an itemtype defined, and you have created an item of that type in danish. You wish to export this item, have it translated to english, and import the result as a new item in the database, resulting in two items, one in english and one in danish.

When a new item is created as a page or a pragraph, a row is added to both the itemType_*** table, and to the page/paragraph table.

If you are accessing the items programatically, the page/paragraph row is not needed.

This means that in order to import items, you have to ad rows to two tables, both the itemType table and the page/paragraph table.

in the Page table, you must add values to (at least) the following columns:

PageParentPageID,PageActive,PageMenuText,PageItemType,PageItemId.

 

And similarly, in the Paragraph table, you must add values to (at least) the following columns:

ParagraphPageID,ParagraphItemId, ParagraphHeader, ParagraphItemType

 

 

I expect that we'll add an itemProvider to the Data Integration module before too long, since items appear to be the new black :-)

However, if you need to do the import/export right now, you will have to handle the page/paragraph creation manually, either by adding it to the input data, or by creating a custom provider to handle it for you.

/Jonas

 

Votes for this answer: 1
 
Morten Bengtson
Reply

Hi Jonas,

Thanks. I guess I'm just too lazy and don't want to spend time developing my own import/export when that should have been provided by standard functionality. A new standard ItemProvider sounds like what we need. I have created a feature request here: http://developer.dynamicweb-cms.com/forum.aspx?ThreadID=31517

 

 

You must be logged in to post in the forum