How to let users add content objects

Author Message

Chirag Patel

Monday 21 February 2011 12:04:36 pm

I want to accomplish following:

I want to provide a link or button on simple article page.
When user clicks that, it should take him to a form that lets him add a particular content object. This object is of a custom class (imaginary!) that I have already created.

TestClass - FullName, EmailAddress.

Later on, I would like to use these objects to display the list and also particular object on a single details page.

My Questions based on lot of time I spent on documentation:

1) What is it that I am looking for? Is it "Edit" or "Create"? Is "edit" also used for "create"??

2) What kind of template should I use for "Create"? System or Node template?

At one point it looked like Node. But basic node templates did not have anything for "create". There was a system template for "create".

3) How do I create a link or button for letting the user click it and reach a web form to create the object / submit his entry? I was hoping the article editor should have this facility.

(I do not want to use the ez toolbar.)

4) I looked at Edit templates. Specially the one that is used by comment page from an article page. But I couldn't understand it. As the template uses object id. In case of adding a new object, there wouldn't be any object id. Is it? How does edit template works then?

I hope someone can point me to a step-by-step article. Or clarify some of these questions. Eventually I am poised to write such article due to all the pain I have gone through :)

Thanks!

Nicolas Pastorino

Tuesday 22 February 2011 2:30:17 pm

Hi Chirag, and welcome aboard the eZ Community,

Here is a late reply which i hope will help you. From looking at the website toolbar example (which serves the functionality you are looking for), there are a couple of interesting code snippets, which once reworked, end-up in :

{def $current_node = $node
     $content_object = $current_node.object
     $can_edit_languages = $content_object.can_edit_languages
     $can_manage_location = fetch( 'content', 'access', hash( 'access', 'manage_locations', 'contentobject', $current_node ) )
     $can_create_languages = $content_object.can_create_languages
     $is_container = $content_object.content_class.is_container
     $content_object_language_code = ''}

<!-- eZ website toolbar: START -->

<div id="ezwt">
<div class="tl"><div class="tr"><div class="tc"></div></div></div>
<div class="mc"><div class="ml"><div class="float-break mr">

<!-- eZ website toolbar content: START -->


<div id="ezwt-standardactions">

<form method="post" action={"content/action"|ezurl} class="left">
{if and( $content_object.can_create, $is_container )}
<label for="ezwt-create" class="hide">Create:</label>
{def $can_create_class_list = ezcreateclasslistgroups( $content_object.can_create_class_list )}
  {if $can_create_class_list|count()}
  <select name="ClassID" id="ezwt-create">
  {foreach $can_create_class_list as $group}
    <optgroup label="{$group.group_name}">
    {foreach $group.items as $class}
        <option value="{$class.id}">{$class.name|wash}</option>
    {/foreach}
    </optgroup>
  {/foreach}
  </select>
  {/if}
  <input type="hidden" name="ContentLanguageCode" value="{ezini( 'RegionalSettings', 'ContentObjectLocale', 'site.ini')}" />
  <input type="image" src={"websitetoolbar/ezwt-icon-new.gif"|ezimage} name="NewButton" title="{'Create here'|i18n('design/standard/parts/website_toolbar')}" />
{/if}

{if $content_object.can_edit}
    <input type="hidden" name="ContentObjectLanguageCode" value="{ezini( 'RegionalSettings', 'ContentObjectLocale', 'site.ini')}" />
    <input type="image" src={"websitetoolbar/ezwt-icon-edit.gif"|ezimage} name="EditButton" title="{'Edit: %node_name [%class_name]'|i18n( 'design/standard/parts/website_toolbar', , hash( '%node_name', $current_node.name|wash(), '%class_name', $content_object.content_class.name|wash() ) )}" />
{/if}

{if $content_object.can_remove}
    <input type="image" src={"websitetoolbar/ezwt-icon-remove.gif"|ezimage} name="ActionRemove" title="{'Remove'|i18n('design/standard/parts/website_toolbar')}" />
{/if}

  <input type="hidden" name="HasMainAssignment" value="1" />
  <input type="hidden" name="ContentObjectID" value="{$content_object.id}" />
  <input type="hidden" name="NodeID" value="{$current_node.node_id}" />
  <input type="hidden" name="ContentNodeID" value="{$current_node.node_id}" />
  {* If a translation exists in the siteaccess' sitelanguagelist use default_language, otherwise let user select language to base translation on. *}
  {def $avail_languages = $content_object.available_languages
       $default_language = $content_object.default_language}
  {if and( $avail_languages|count|ge( 1 ), $avail_languages|contains( $default_language ) )}
    {set $content_object_language_code = $default_language}
  {else}
    {set $content_object_language_code = ''}
  {/if}
  <input type="hidden" name="ContentObjectLanguageCode" value="{$content_object_language_code}" />
</form>
</div>

<!-- eZ website toolbar content: END -->

</div></div></div>
<div class="bl"><div class="br"><div class="bc"></div></div></div>
</div>

<!-- eZ website toolbar: END -->

Do not mind the markup here, make it yours. You can safely embed this code in a self-contained template, included from any node template (a template used to display a content node, from which the $node variable is available).

This code actually is an essential create/edit toolbox.

I hope this helped you,
Let us know how you grasp this,
Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Chirag Patel

Tuesday 22 February 2011 8:02:42 pm

Hi Nicolas,

First of all, thanks for taking time to answer my post.

But unfortunately, I couldn't get the answers I am looking for. It would really help each of the ones I have listed.

Here's my confusion. Your code or other code for "create" or "edit" buttons code I have looked at would pass a ClassID to either /content/create or /content/edit. But I do not see any code in create.tpl or edit.tpl which uses such ClassID. It just submits to /content/action. I have represented this in Question no. 4.

I have an assumption that if my listed questions are addressed separately, it might solve my confusion.

Chirag Patel

Thursday 24 February 2011 11:45:10 am

Chirag Patel

Thursday 24 February 2011 1:42:03 pm

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.