Drupal 7 で theme.inc で発生する Fatal error の対処方法
Drupal 7 で次のようなエラーに遭遇することがあります。
Fatal error: Unsupported operand types in /PATH/TO/DRUPAL_ROOT/includes/theme.inc on line 637
原因
問題の原因は関数 _theme_process_registry()
の中で連想配列とその他の何か(たいてい NULL
)の加算が行なわれていることです。
そしてそれが起こるのは hook_theme()
の戻り値が正しく指定されていないことが原因です。
次のような hook_theme()
を書いていると発生します。
function mymodule_theme($existing, $type, $theme, $path) {$themes = array('special_element' => array('variables' => array('something_special' => NULL,),),););
対策
hook_theme()
の戻り値を正しく指定します。
上の例でいえば return $themes
を追加すれば OK です。
function mymodule_theme($existing, $type, $theme, $path) {$themes = array('special_element' => array('variables' => array('something_special' => NULL,),),);return $themes;);
私は return
をつい書き忘れて数ヶ月に一度は遭遇します。