Building a plugin: override classes

So, I'm trying to build a (what I thought would be a) reasonably simple plugin, to get familiar with the way Omeka is put together.

The idea is to make it possible to be able to make certain values disputed. (So to make elements disputable).

My plugin creates a table "disputable" (to indicate which elements can be disputed) and adds a row "disputed" to element_texts to indicate if the element text is disputed.

The settings part works fine, but I can't figure out how to modify the code so that is shows a checkbox for the disputable elements.

My idea was to override application/helpers/ElementForm.php. So I created a directory Myplugin/helpers/ElementForm.php and set it to extend the original one (this is where my php/Zend/Omeka knowledge gets a bit dodgy). How do I make Omeka see that I put this code here, and thereby override the original code (adding a checkbox for disputables)?

Thanks a bunch!

ElementForm is a Zend "view helper."

You can tell Zend (and therefore Omeka) that you have view helpers in a particular path. Zend has documentation on how to do this. You're looking for addHelperPath.

Ah, that was simple. Thanks! I guess I'll have to read up on Zend stuff.

That was too early. Where to I have to tell Zend that I have view helpers in a particular path? I'm confused about the difference between helpers and views.

Ok, this doesn't seem to be the right way to ask questions. Here is some more context:

I have written an extension to elementForm.php (plugin_directory/helpers/ElementForm.php), managed to make it so that is loaded in plugin.php:

public static function initialize(){
$view = new Zend_View();
$view->addHelperPath(DISPUTABLEDATA_HELPERS_DIR, 'DisputableData_View_Helper');
}

To activate the elementForm I execute it below this code: $view->elementForm(); but now it needs arguments.

I guess I need to call a different view somewhere. How do I tap into the right view? is there a hook or something I can use? Am I actually allowed to mess around here?

Thanks in advance.

Well, your goal is to make it so that the built-in code will use your view, with its different helper path.

Setting your altered view on the ViewRenderer object should do the trick:

$view = new Omeka_View;
$view->addHelperPath(DISPUTABLEDATA_HELPERS_DIR, 'DisputableData_View_Helper');
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view);

My goal is to add a simple checkbox into the /admin/items/add form by means of a plugin (to make it available to the Omeka community). I thought this would be a piece of cake but after 4 days of not understanding I think I will simply hack it into the Omeka code itself.

Thanks for the help but I think I will give up for now.

PS:

the error I'm getting after your suggestion is:

Zend_View_Exception
script 'items/add.php' not found in path (/Applications/MAMP/htdocs/verhalenbank_omeka/application/views/scripts/)

#0 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/View/Abstract.php(884): Zend_View_Abstract->_script('items/add.php')
#1 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Action/Helper/ViewRenderer.php(900): Zend_View_Abstract->render('items/add.php')
#2 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Action/Helper/ViewRenderer.php(921): Zend_Controller_Action_Helper_ViewRenderer->renderScript('items/add.php', NULL)
#3 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Action/Helper/ViewRenderer.php(960): Zend_Controller_Action_Helper_ViewRenderer->render()
#4 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#5 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Action.php(527): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#6 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('addAction')
#7 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#9 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#10 /Applications/MAMP/htdocs/verhalenbank_omeka/application/libraries/Omeka/Core.php(165): Zend_Application->run()
#11 /Applications/MAMP/htdocs/verhalenbank_omeka/admin/index.php(44): Omeka_Core->run()
#12 {main}