2011-12-30 6 views
1

hook_themeを使用して特定のフォームのラジオボタンをカスタマイズする際に問題があります。以下は私のモジュール上にあるコードです。私が遭遇した問題を起草、私のコメントを参照してください:あなたが行ったらDrupal 7で変更したテーマについて

function mymodule_theme() { 
    return array(
    'custom_radios' => array(
     'render element' => 'element', 
    ), 
); 
} 

:フォーム要素は、新しいrender arrayキーの代わりに、テーマ定義でvariablesを使用する必要があるのDrupal 7用

// Implementation of hook_form_alter(). 
function mymodule_form_alter(&$form, $form_state, $form_id){ 
    // e.g form id: commerce_cart_add_to_cart_form_u6onPJSgS7pOgw0Tlo7zHy42LTQzbV913taANkYQKTo 
    if (strpos($form_id, 'commerce_cart_add_to_cart_form') !== FALSE) { 
    // Alter add to cart form 
    mymodule_commerce_cart_add_to_cart_form_alter($form, $form_state, $form_id); 
    } 
} 

function mymodule_commerce_cart_add_to_cart_form_alter(&$form, $form_state, $form_id) {  
    // Change the field type to radios. 
    $form['attributes']['field_artwork_ref']['#type'] = 'radios'; 
    // Apply my custom theme for radios. 
    $form['attributes']['field_artwork_ref']['#theme'] = array('custom_radios');  
} 

// Implementation of hook_theme(). 
function mymodule_theme() { 
    return array(
    'custom_radios' => array(
     'variables' => array('element' => NULL), 
    ), 
); 
} 

function theme_custom_radios($variables) { 
    // Custom theme should go here. 
    // However, $variables are empty, print_r gives me "Array ([element] =>)." 
    // I am at least expecting to see my radio element here. 
    print_r($variables);  
} 

答えて

7

テーマClear Drupalのキャッシュを変更して、あなたのコードがうまくいくはずです(私はちょうど上記をテストしたところ、うまくいきます)。

+0

私はこれについて知らなかった、私は行って、彼らの文書を読み直さなければならない。ありがとうございました。 – Marvzz

関連する問題