I was wondering if anybody can help to get other parameters to the theme_name_form function ?

Example : I fill the form variable with the item I want. I call the theme_name_form which render the form correctly.

How can I have another variable which come from name_form into my theme_name_form() ??

This is what I tried :
in the .module file (hook_theme) :

    'macommande_formulaire' => array(
	'arguments' => array('commandes' => array(), 'total_commandes' => null ),
	'file' => 'macommande.page.php')

and in macommande.Page.php

function theme_macommande_formulaire($form) {
	if ($total_commandes) output.= "Yess :-) ";

And I can't access to the value of $total_commandes... :-(

I assume the second function doesn't know at all about my variable $total_commandes... but how can I pass this value (without a static variable of course ;-) )

Thanks !

Comments

thijsvdanker’s picture

I think the arguments that you set in hook_theme are passed to the theme function.
Your function should thus be:

//both the arguments should be in the function statement
function theme_macommande_formulaire($commandes, $total_commandes = null) {
  if ($total_commandes) output.= "Yess :-) ";
}

Correct me if I'm wrong!

Good luck,
Thijs

svergeylen’s picture

Thanks for your response !
If I add the parameters in the description of the function like this :

function theme_macommande_formulaire($form, $commandes=>array(), $total_commande=>null, $commandes_existent=>null, $aconfirmer=>TRUE, $total_livraison=>null, $livraison=>array() ) { ... }

I get this error : Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ')' in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line

It seems that Drupa doesn'ot want me to use "=>" in the declaration ???

If I remove the initialisation of the parameter in the function :

function theme_macommande_formulaire($form, $commandes, $total_commande, $commandes_existent, $aconfirmer, $total_livraison, $livraison ) { ... }

Then, I get this error :

* warning: Missing argument 2 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 3 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 4 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 5 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 6 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 7 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.

no more on a white screen, but in the messages from drupal (drupal_set_message). It seems that these variables are not initialize but how can I solve this ?? ;-)

Thanks for helping !

Stéphane

jaypan’s picture

When theming forms, you can only pass the $form variable to the theme function. Any extra data needs to be added to the form element, and can then be accessed in the theme function.

$form['id'] = array
(
  '#type' => 'value',
  '#value' => $id;
);
$form['name'] = array
(
  '#type' => 'textfield',
  '#title' => t('Name'),
);
$form['#theme'] = 'myform';

function theme_myform($form)
{
  $id = $form['id']['#value'];
}

Contact me to contract me for D7 -> D10/11 migrations.

svergeylen’s picture

OK, thank you for your precise answer. I tought it was like this but because I come from a template with a lot of array of variables, I was wondering if it was possible.

Do you know if I can add an array to your #value of 'id' or of I can only add a string ?

Thanks,

Stéphane

jaypan’s picture

Honestly, testing it on your own would be faster than waiting for me to reply.

But the answer is yes, you can pass an array.

Contact me to contract me for D7 -> D10/11 migrations.