Blog» Adding cross-reference data to object relations

Adding cross-reference data to object relations

By Xavier Cousin  | September 19, 2012  |  eZ Publish development tips

The object relations datatype is one of the most powerful datatypes in eZ Publish. In some cases, it is useful to associate data not to either of the objects involved in the relation, but to the relation itself. For example, you might want to mark a person as an author on one book, a contributor on another book, and an editor on another book, all while maintaining only one record for that author. Mugo has created an extension to add cross-reference data to object relations.

Creating a new class with the "Mugo object relations" datatype

The extension Mugo Object Relations provides a new datatype:

Once an attribute of the new datatype is added, it will show the familiar options as for a standard "Object relations" attribute but with an area to configure the cross-reference information:

As shown in the screenshot above, you can allow the cross-reference data to be entered via a text field or you can define a set of options for a dropdown list.

Using a "Mugo object relations" attribute

When you create a new object that has a "Mugo object relations" attribute, you can select the cross reference information...

... or if it was configured as such, you can type it in:

Displaying the cross reference data

The data associated with the relation can be accessed in your templates via the "xrefoptionaldata" key within the "relation_list" attribute. Here is a simple code sample that fetches an object with a "Mugo object relations" attribute and lists the related object names along with the data associated with each relation:

{set $node = fetch( 'content', 'node', hash( 'node_id', 75 ))}
relations for {$} object:<br/><br/>
{def $relation_node = null}
{foreach $node.data_map.relations.content.relation_list as $relation}
    {set $relation_node = fetch( 'content', 'node', hash( 'node_id', $relation.node_id ))}
    {$}: "{$relation.xrefoptionaldata}"<br/>

eZ Find search ready

The extension comes with a simple eZ Find PHP class for storing the datatype's data in a Solr search index.

Download and contribute to Mugo Object Relations on GitHub:

Join our mailing list for news, events, tips, and tools


blog comments powered by Disqus

Hi, we're Mugo Web - Nice to meet you!

We're a group of web experts who solve complex web problems.

Learn more about us »



Yes - we can do that.

Many years of experience with complex websites allows us to offer total solutions.

Learn more about what we can do »

We love our clients (and they love us too)

We've solved problems across North America and around the world.

Learn more about what we've done »

We tweet too

Follow us on Twitter for the latest Mugo happenings

mugo twitter page @mugo

© 2008 - 2019 Mugo Web. All rights reserved.