Friday, March 19, 2010

Configuring the look of reference attributes in the HMC

So basically the question is this:
How can I change/configure the looks of reference attributes in the hmc if the reference is an item of my own type? I can only see the 'PK' in corresponding editors.

Suppose you have your own type named "MyType" and you have an attribute of this type in, for example, the Product's editor. If you have no hmc configuration whatsoever for your own type then the hmc will take the default configuration which is made for the "Item" type. And since "Item" has only one useful attribute - the PK - this attribute is by default configured to be shown in reference editors.

Now you only need to provide a configuration for your own type in your extension's hmc.xml file. For reference editors only the tag is needed, but it makes sense to at least provide similar configurations for the search and searchresult.

So if your type has an attribute named 'code' (the attribute you think is the most unique to your type) you could provide the following hmc.xml configuration snippet:

<type name="MyType" mode="append">
<organizer>
<search mode="replace">
<condition attribute="code"/>
</search>
<result>
<listview mode="replace">
<itemlayout>
<attribute name="code"/>
</itemlayout>
</listview>
</result>
</organizer>
<defaultreference searchattribute="code" mode="replace">
<itemlayout>
<attribute name="code"/>
</itemlayout>
</defaultreference>
</type>
For your request the relevant part is the tag in which you provide the 'searchattribute'.
Here you tell the hmc to use the attribute named 'code' to provide a reference editor (which then even allows for search-as-you-type functionality based on 'code').
The tag inside is responsible for the looks of item references in any non-editor context (for example inside display-only lists).

And, as I said, the configurations for and are actually not necessary for your intention, but if you ever want to search for instances of your type then they will be quite useful (or you will, again, be confronted with meaningless pk's).

No comments:

Post a Comment