Adding functions to admin

I've been trying to add a new function on admin/show. I've added:

<?php echo link_to_item(__('NewFunction'), array('class'=>'big green button'), 'newfunction'); ?>

This successfully tries to call: http://baseurl/admin/items/newfunction/(item number)

But it comes back with a 404 error. I've added newfunction.php to the items folder under admin, what else do I need to do to make it route correctly?

What variable will the inputed item number come in under?


What it looks like you are trying to do would also require hacking in a new function on the Item Controller, in this pattern it would be newfunctionAction(). The way the link_to_item function works, it only relates to the controller, not to any attempt to add new functions in a separate PHP file.

Since that degree of changing the core is generally not needed, could you tell more about what functionality you are trying to achieve? I suspect that a small plugin might work better.

I want to add a copy function that creates a new item but takes some information from an existing item.

Still learning how all the plugin stuff works together.

My other thought for an approach is to extend the AddItem function to take an old item as an input.

Then use something like this pseudo code:

if($olditem != null)
   foreach($element in $olditem.GetMetadata('Item Type Metadata'))
   $newitem.Addrelationship('derives from', $;


But I'm coming from a C# background so omeka and php are all new to me.

That definitely sounds like a plugin, and a use case we have heard before.

It shouldn't take any changes to existing code. It would just mean getting all the data you want to duplicate, then using insert_item to add the sorta-clone.

Ok, I'm getting closer. I've added this to my plugin:

public function hookAdminItemsPanelButtons($args)
    	$view = $args['view'];
    	//echo $view;
    	$record = $args['record'];
    	if($record != null)
    	    echo $view->formSubmit('clone', __('Clone Item '.$record->id), array('id'=>'clone-item', 'class'=>'submit big green button'));


So now it saves the item and calls hookAfterSaveItem.

Now I'm getting to the point where I have this:

if (isset($post['clone'])) {
          // do clone

but how can I tell what post data to expect from the save form? after_save_record isn't real clear on what will be in the array.

Ok, I'm almost there. I have created the new item. insert returns $newitem. Is there anyway to redirect to edit the new item?

This doesn't work in hookAfterSaveItem:

Where should I be putting the redirect? and if I can't put it in the hook, how do I pass the id on to where I can call it?


I'm pretty sure that that helper is only there in controllers, not in the plugin class.

An alternate approach would be for your plugin to have a controller with something like cloneAction, and have your button link to that action, including the original item id. Then, that action would just dig up the item from the database and do the same cloning. From there, you should be able to redirect back to the new item's edit page.

Kobei -- I'd be interested in seeing your plugin. I can definitely see deriving items as being a time saver.