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.

eZ debug

Timing: Jan 18 2025 02:05:13
Script start
Timing: Jan 18 2025 02:05:13
Module start 'layout'
Timing: Jan 18 2025 02:05:13
Module start 'content'
Warning: PHP: E_WARNING Jan 18 2025 02:05:14
DOMDocument::loadXML(): PCDATA invalid Char value 29 in Entity, line: 4 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 02:05:14
DOMDocument::loadXML(): PCDATA invalid Char value 29 in Entity, line: 9 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 02:05:14
DOMDocument::loadXML(): PCDATA invalid Char value 29 in Entity, line: 10 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 02:05:14
DOMDocument::loadXML(): PCDATA invalid Char value 29 in Entity, line: 2 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 02:05:14
DOMDocument::loadXML(): PCDATA invalid Char value 29 in Entity, line: 8 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 02:05:14
DOMDocument::loadXML(): PCDATA invalid Char value 29 in Entity, line: 9 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Timing: Jan 18 2025 02:05:14
Module end 'content'
Timing: Jan 18 2025 02:05:14
Script end

Main resources:

Total runtime0.9678 sec
Peak memory usage4,096.0000 KB
Database Queries63

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0124 589.0313152.6250
Module start 'layout' 0.01240.0059 741.656339.4688
Module start 'content' 0.01830.9483 781.1250585.5547
Module end 'content' 0.96660.0012 1,366.679721.6719
Script end 0.9677  1,388.3516 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3536160.0002
Check MTime0.00140.1443160.0001
Mysql Total
Database connection0.00150.159710.0015
Mysqli_queries0.906093.6223630.0144
Looping result0.00070.0735610.0000
Template Total0.922695.320.4613
Template load0.00210.212920.0010
Template processing0.920595.119020.4603
Template load and register function0.00020.018210.0002
states
state_id_array0.00110.115710.0011
state_identifier_array0.00150.151620.0007
Override
Cache load0.00180.1822350.0001
Sytem overhead
Fetch class attribute can translate value0.00070.075820.0004
Fetch class attribute name0.00150.152560.0002
XML
Image XML parsing0.00070.072620.0004
class_abstraction
Instantiating content class attribute0.00000.002560.0000
General
dbfile0.00090.0924160.0001
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 16
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs