For a website I installed Ubercart. Now I would like to add an extra field to the attribute-options-form of Ubercart. I succeeded with adding a field (I implemented hook_form_FORM_ID_alter()), but now I would like to adjust the view of the form, because the view isn't viewed correct on the following page:
admin/store/products/classes/testproduct/options
The added fields don't appear within the table, but underneath.
I already discovered that the view can be adjusted bij calling theme_FORM_ID(), where FORM_ID is the id of the form. The problem is that the function theme_uc_object_options_form() is already defined in uc_attribute.admin.inc. Now I'm looking for a way to override this function, because I don't prefer to adjust original code.
On the Drupal Form API I read that I needed to add '#theme' to the form-array and give the name of the function to be called:
http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
(look for the first bullet underneath the header 'Theming Forms').
I tried this, but the function I had given, doesn't seem to be called. The view of the form is different however and the function theme_uc_object_options_form() doesn't get called anymore after adding '#theme' to the form-array.
Code:
<?php
/**
* Implementation of hook_form_FORM_ID_alter()
* @param array $p_aForm
* @param array $p_aFormState
* @return void
*/
function uc_attribute_variable_price_form_uc_object_options_form_alter(&$p_aForm, $p_aFormState)
{
// Code for adding the field
// (...)
// Add submit function
$p_aForm['#submit'][] = 'uc_attribute_variable_price_form_uc_object_options_form_submit';
// Custom theme-function
$p_aForm['#theme'] = 'justatest';
}
// Just a few testfunctions, to test which function got called
/**
* theme_justatest()
*/
function theme_justatest($p_aForm)
{
die('theme_justatest called');
}
/**
* theme_justatest_form()
*/
function theme_justatest_form($p_aForm)
{
die('theme_justatest_form called');
}
/**
* justatest()
*/
function justatest($p_aForm)
{
die('justatest called');
}
/**
* justatest_form()
*/
function justatest_form($p_aForm)
{
die('justatest_form called');
}
?>How can I use an own function for the view of the form? None of the functions in the code example got called.
Comments
in your hook_form_alter(),
in your hook_form_alter(), you can add a theming function;
You will have to call hook_theme() to register this theme, then define the theme function as well.
Contact me to contract me for D7 -> D10/11 migrations.
Thanks for your reply. It
Thanks for your reply. It took a while before I figured out how to register a theme correctly. I had defined the theme function in the module-file, but it seems I only could use the name of the module as the name of the theme. Not handy if I want to overwrite multiple theme functions.
Code:
Is this the only correct way for overriding theme functions (with the overriding-functions defined in the module-file)? Using an other string then 'uc_attribute_variable_price' didn't seem to work. I had cleared all caches after modifying.
EDIT: never mind, my mistake was that I had changed the name of the implementation-function of hook_theme() as well (I shouldn't have changed the function name of uc_attribute_variable_price_theme()).