Standard "Create here" selection

Author Message

Muu Sle

Monday 19 June 2006 2:34:33 pm

Hi,

It would be very useful to add a ini setting were you could define the type of class you normally would create under a given node.

Takes this structure for example:

Ez publish (2)
. . . News (61)
. . . . . . National (62)
. . . . . . Local (63)
. . . Images (83)
. . . Attachments (68)

 

In this case it would be natural to create an article object under News, an image object under Images, a file under Attachments and so on...

This could easily be defined in <i>content.ini</i> like this using the <i>node_id</i> as the key:

[DefaultCreateHere]
#DefaultClassMap[node_id]=class_identifier
# /
DefaultClassMap[2]=menupage
# / News
DefaultClassMap[61]=article
# / Images
DefaultClassMap[83]=image
# / Attachments
DefaultClassMap[68]=file

And in the <i>design/admin/templates/children.tpl</i> [, override] we could use the <i>$node</i> var to do a "reverse dig" if the current node is not defined to check if the parent is specified in the <i>DefaultClassMap</i>.
First check if the current node is defined in the ini, if not; check if the parent node is, if not; check the parent parent node is, stop...
I don't think it would be relevant for further digging.

<select name="ClassID" onchange="updateLanguageSelector(this)" title="{'Use this menu to select the type of item you wish to create and click the "Create here" button. The item will be created within the current location.'|i18n( 'design/admin/node/view/full' )|wash()}">
       {def $DefaultClassMap=ezini('DefaultCreateHere','DefaultClassMap','content.ini')}

       {def $prefered_class=null}

       {if $DefaultClassMap[$node.node_id]}
           {set $prefered_class = $DefaultClassMap[$node.node_id]}

       {elseif $DefaultClassMap[$node.parent_node_id]}
           {set $prefered_class = $DefaultClassMap[$node.parent_node_id]}

       {elseif $DefaultClassMap[$node.parent.parent_node_id]}
           {set $prefered_class = $DefaultClassMap[$node.parent.parent_node_id]}
       {/if}

       {section var=CanCreateClasses loop=$can_create_classes}
           {if $CanCreateClasses.item.can_instantiate_languages}
               <option{eq($prefered_class, $CanCreateClasses.item.identifier)|choose( '', ' selected' )} value="{$CanCreateClasses.item.id}">{$CanCreateClasses.item.name|wash()}</option>
           {/if}
       {/section}
</select>

It is not a timesaver per say, just luxury :)
Just a suggestion,

Thanks!

PS! I have tested the code above, it works fine for me.

. muusle

Kristof Coomans

Monday 19 June 2006 11:25:43 pm

Hi

I suggested almost the same for eZ 3.9 :-) It could be done on class level too (for example images under each image gallery).

I'll definitely try your code. Thanks for sharing it with us!

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Tuesday 20 June 2006 12:01:36 am

A slightly modified version for eZ publish 3.7 of Muu Sle's code with support for defaults specified by the content class identifier:

    <select name="ClassID" title="{'Use this menu to select the type of item you wish to create and click the "Create here" button. The item will be created within the current location.'|i18n( 'design/admin/node/view/full' )|wash()}">
    {def $DefaultClassMapByNode=ezini('DefaultCreateHere','DefaultClassMapByNode','content.ini')
         $DefaultClassMapByClass=ezini('DefaultCreateHere','DefaultClassMapByClass','content.ini')
         $prefered_class=null}
        {if is_set($DefaultClassMapByClass[$node.class_identifier])}
            {set $prefered_class = $DefaultClassMapByClass[$node.class_identifier]}
        {/if}

        {if is_set($DefaultClassMapByNode[$node.node_id])}
            {set $prefered_class = $DefaultClassMapByNode[$node.node_id]}
        {elseif is_set($prefered_class)|not}
            {if is_set($DefaultClassMapByNode[$node.parent_node_id])}
                {set $prefered_class = $DefaultClassMapByNode[$node.parent_node_id]}
            {elseif is_set($DefaultClassMapByNode[$node.parent.parent_node_id])}
                {set $prefered_class = $DefaultClassMapByNode[$node.parent.parent_node_id]}
            {/if}
        {/if}
        {section var=CanCreateClasses loop=$can_create_classes}
              <option{eq($prefered_class, $CanCreateClasses.item.identifier)|choose( '', ' selected' )} value="{$CanCreateClasses.item.id}">{$CanCreateClasses.item.name|wash()}</option>
        {/section}
    {undef $DefaultClassMapByNode $prefered_class}
    </select>

Example INI settings:

[DefaultCreateHere]
DefaultClassMapByClass[gallery]=image
DefaultClassMapByClass[forum]=forum_topic
DefaultClassMapByClass[forum_topic]=forum_reply
DefaultClassMapByNode[]
DefaultClassMapByNode[2]=folder

First it looks for a default for the class of the current node, then this choice can be overriden for specific nodes. If then still no default is found, it will look for a node default of either the parent node, or the grandparent node.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Muu Sle

Tuesday 20 June 2006 4:33:51 am

Nice!
Agreed, it would be complete when adding support for doing this at class level, very handy!

. muusle

Guillaume Contival

Friday 27 October 2006 9:04:18 am

Hi,

Cool ! This is exactly what I was looking for. Do you know if this code exists as an extension ? Or if I have to create mine ?

Cheers.

SQLi
http://www.sqli.com

Kristof Coomans

Friday 27 October 2006 10:05:15 am

It's not in an extension yet, but feel free to create one and to post it as a contribution, as long as you give us some credits :-)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Guillaume Contival

Monday 30 October 2006 3:16:23 am

In fact, I was searching a way to limit available "create here" choices, not only suggest one.

I thought it was in eZ settings, but can't find where, then I found this post. I'll try to change this code a little to add a way to limit available classes as well in the "create here" function.

I know we can do this with roles & policies, but I want to do this in a more efficient and global manner. I think this is the way. But correct me if I'm wrong or if it already exists.

Cheers.

Guillaume Contival

Tuesday 31 October 2006 2:28:50 am

Apparently, I have 2 profiles with the same email ;)

By the way, I made the extension, with the possibility to define available classes by node or class.

SQLi
http://www.sqli.com

Kristof Coomans

Saturday 27 January 2007 6:48:38 am

I've packed the modified template for eZ 3.9.0 in an extension and it's in svn now:
http://pubsvn.ez.no/community/trunk/extension/defaultcreatehere

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

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 11:03:02
Script start
Timing: Jan 18 2025 11:03:02
Module start 'layout'
Timing: Jan 18 2025 11:03:03
Module start 'content'
Timing: Jan 18 2025 11:03:03
Module end 'content'
Timing: Jan 18 2025 11:03:03
Script end

Main resources:

Total runtime0.0214 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 587.9141152.6250
Module start 'layout' 0.00690.0046 740.539139.4453
Module start 'content' 0.01150.0074 779.9844105.4609
Module end 'content' 0.01890.0024 885.445346.3047
Script end 0.0214  931.7500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002913.6019140.0002
Check MTime0.00125.4721140.0001
Mysql Total
Database connection0.00114.962410.0011
Mysqli_queries0.004621.272030.0015
Looping result0.00000.083510.0000
Template Total0.00188.310.0018
Template load0.00104.531710.0010
Template processing0.00083.733810.0008
Override
Cache load0.00073.202910.0007
General
dbfile0.00177.869380.0002
String conversion0.00010.409540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs