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
|