Recent changes

2013-04-14 2013-04-02 2013-02-17 2013-01-29 2013-01-20 2013-01-18 2012-12-08 2012-11-06 2012-09-04 2012-08-02

drupal/functions/theme

theme

結構キモになる関数。

function theme() {                                                              
  static $functions;
  $args = func_get_args();
  $function = array_shift($args);
 
  if (!isset($functions[$function])) {
    $functions[$function] = theme_get_function($function);
  }
  if ($functions[$function]) {
    return call_user_func_array($functions[$function], $args);
  }
}

func_get_argsで自分自身の引数を受け取る為、引数はいくつでも指定できる。 最初に指定した引数の値が関数名($function)。

theme_get_functionでtheme用の関数を拾ってきて、その結果をセット。

theme用関数をcall_user_func_arrayで実行。

つまり、theme関数の第一引数に指定された関数を第二引数以降の変数を渡して実行する。ってことっぽい。

関数のオーバーライド

例えば、

theme("pager", $data, $data);

ってなってる時、通常はtheme_pager関数が呼ばれるんだけど、これが$theme_engineで指定されたテーマエンジンの方で[テーマエンジンの名前]_pagerっていう関数が存在するとそっちを優先して返す。

つまり、engine側でtheme用の関数を上書きできる(ように見せる事ができる)

ちなみに、phptemplate_で始まる関数は以下。

  • phptemplate_init
  • phptemplate_templates
  • phptemplate_regions
  • phptemplate_features
  • phptemplate_page
  • phptemplate_node
  • phptemplate_comment
  • phptemplate_block
  • phptemplate_box