Forums / Setup & design / Object relations attribute

Object relations attribute

Author Message

Andy Woods

Wednesday 20 April 2011 8:02:22 am

I've added an Object relations attribute to the User class.

It allows users to select sub-folders that exist under an 'Events' folder in the content structure. The sub-folders are 'categories' of events.

The users are currently able to select and de-select their "categories" when they edit their Profile.

As you know from this page they're able to edit their various profile details such as First Name, Last Name, Password etc

I'd like to display a page that ONLY displays their "categories" with the facility to change them.

Can you tell me what code I need to use to display the Object relations attribute and enable the user to submit their selection so that their profile is updated?

Thanks,

Andy

Marko Žmak

Wednesday 20 April 2011 11:39:07 pm

Hm, you could use the attribute edit gui only for this object relation attribute, and put hidden input fields for all other attributes.

Note that for every attribute you'll need two hidden fields, look at the html of the user edit form in admin interface and you'll figure it out.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Thursday 21 April 2011 9:04:02 am

Hi Marko,

Thanks for your suggestion.

Can you point me to any info that explains how to use the attribute edit gui preferably step by step?

Thanks,

Andy

Marko Žmak

Thursday 21 April 2011 11:36:12 pm

"

Hi Marko,

Thanks for your suggestion.

Can you point me to any info that explains how to use the attribute edit gui preferably step by step?

"

Actually it's really simple to use attribute_edit_gui, look at the docs:

  • http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-functions/Visualization/attribute_edit_gui

But what's a little bit more complicated is to make this hidden inputs for other attributes. The syntax of this input fields is something like this:

<input type="hidden" name="ContentObjectAttribute_id[]" value="#id_of_the_attribute#" />
<input type="text" name="ContentObjectAttribute_ezstring_data_text_#id_of_the_attribute#" value="#value_of_the_attribute#" />

(note that you need both this inputs for every attribute)

Here the "ezstring_data_text" part is not the same for every attribute, it depends of the type of attribute.

Take a look at the edit templates in "admin2" or "standard" design and you should get it.

I know that is not easy and requires a little bit of digging through the templates but it's the best solution I can think of.

An alternative way could be to create a custom module that changes only this one attribute, but this would be a little bit of an overkill.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Tuesday 26 April 2011 6:25:25 am

Hi Marko,

I'm not 100% sure of what to do yet.

I've created a page that includes the following so far:

<form name="editform" id="editform" enctype="multipart/form-data" method="post" action={concat( '/content/edit/', $object.id, '/', $edit_version, '/', $edit_language|not|choose( concat( $edit_language, '/' ), '/' ), $is_translating_content|not|choose( concat( $from_language, '/' ), '' ) )|ezurl}>

{include uri='design:content/edit_validation.tpl'}
more code to insert here (as per questions below)
</form>

In order to display the Object relations attribute I assume I need to include the code within design/standard/templates/content/datatype/edit/ezobjectrelationlist.tpl

Am I right in thinking that I need to include the following code for each item that is displayed within the 'Edit Profile' page, ie. First name, Last name, Username, Password, Confirm Password, Email address etc.?

<input type="hidden" name="ContentObjectAttribute_id[]" value="#id_of_the_attribute#" />
<input type="text" name="ContentObjectAttribute_ezstring_data_text_#id_of_the_attribute#" value="#value_of_the_attribute#" />

Andy

Andy Woods

Thursday 28 April 2011 5:31:25 am

Can anyone reply to my question please?

Thanks,

Andy

Marko Žmak

Friday 29 April 2011 8:05:27 am

The simplest way to display the edit fields for the object relation attribute is to use attribute_edit_gui.

As for other attributes, yes you'll have to usehe hidden input fields you described, but, as I already mentioned, the "ezstring_data_text" is not always the same. You'll use it for the first name and last name, but for username, email, pasword it's different.

Go and edit a user in the admin interface and then inspect the html of the edit page.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Wednesday 11 May 2011 8:33:54 am

I've only just got round to trying to get attribute_edit_gui working

I see that the attribute needs to be specified within: {attribute_edit_gui attribute=attribute}

Can you tell me how I can fetch the 'attribute' value please so that I can specify it?

The Object relations attribute within the User class has an identifer of: subscribed_categories

Thanks,

Andy

Marko Žmak

Wednesday 11 May 2011 8:46:10 am

"

Can you tell me how I can fetch the 'attribute' value please so that I can specify it?

The Object relations attribute within the User class has an identifer of: subscribed_categories

"

{attribute_edit_gui attribute=$user_object.data_map.subscribed_categories}

Where $user_object is the content object (ezcontentobject) of the user. See also here:

  • http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Objects/ezuser

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Wednesday 11 May 2011 9:21:37 am

Hi Marko,

Thanks for your quick reply.

I've added {attribute_edit_gui attribute=$user_object.data_map.subscribed_categories} into my template file but nothing is displayed.

Do I need to add anything else to see the object relations attribute displayed?

Also - what code should I use to output the correct <form method=... action=... >

Thanks,

Andy

Andy Woods

Thursday 12 May 2011 6:09:02 am

Can anyone help me with my previous question please?

Marko Žmak

Thursday 12 May 2011 6:38:04 am

What's the content of your $user_object variable?

Do you have some usefull info in debug info on the bottom of the page?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Thursday 12 May 2011 6:58:05 am

The Object Relations Attribute is linked to sub-folders that are located under a folder in the Content structure.

You explained how to set it up within the following post http://share.ez.no/content/view/full/108692

The following error message is displayed when I browse the page containing the {attribute_edit_gui:...}

Unknown template variable 'user_object' in namespace ''

I assume I need to define $user_object but I don't know how to.

Andy

Andy Woods

Friday 13 May 2011 1:15:41 am

Marko,

Do I need a line like the following:

{def $user_object=fetch( 'user', 'current_user' )}

Andy

Marko Žmak

Friday 13 May 2011 1:31:30 am

"

Marko,

Do I need a line like the following:

{def $user_object=fetch( 'user', 'current_user' )}

"

Something similar. With that you will fetch the user as ezuser object, and then you need it's content object. See the doc link for the ezuser object in the post above.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Friday 13 May 2011 2:39:41 am

Hi Marko,

Thanks for your help - I added the following code and I the checkboxes are now displayed.

{def $current_user=fetch('user', 'current_user')}

{def $user_object=$current_user.contentobject}
{def $user_object=$current_user.contentobject}

{attribute_edit_gui attribute=$user_object.data_map.subscribed_categories}

Can you tell me if the following lines are what I need to begin the form with please?

<form enctype="multipart/form-data" method="post" action={concat( "/content/edit/", $object.id, "/", $edit_version, "/", $edit_language|not|choose( concat( $edit_language, "/" ), '' ) )|ezurl}>
{include uri='design:content/edit_validation.tpl'}

Marko Žmak

Friday 13 May 2011 10:19:01 am

Yes, this should be it.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Andy Woods

Friday 13 May 2011 11:20:57 am

OK Marko,

I really appreciate your help.

Hopefully this is the last question ;-)

Can you tell me what code I need to use to fetch the value to use with the following line:

<input type="text" name="ContentObjectAttribute_ezstring_data_text_269" value="value_to_fetch" />

Thanks,

Andy

Andy Woods

Saturday 14 May 2011 9:21:41 am

I've just realised that the number I quoted above '269' is only used for a specific user. The same field for a different user has a different number.

Can someone tell me how I can fetch the appropriate number please to append to the <input type=hidden name="ContentObjectAttribute_ezstring_data_text_xxx

I still also need to know how to fetch the value of the field to use in the hidden form field.

Thanks,

Andy

Marko Žmak

Saturday 14 May 2011 10:16:02 am

Use something like this:

$user_object.data_map.subscribed_categories.id

You get the picture?

P.S. And note that it's not always "ezstring_data_text", it depends on the type of attribute. Take a look at the object edit form in the admin interface.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth