开发者

a function from the drupal book module

              <?php
function template_preprocess_book_navigation(&$variables) {
  $book_link = $variables['book_link'];

 // Provide extra variables for themers. Not needed by default.
$variables['book_id'] = $book_link['bid'];
$variables['book_title'] = check_plain($book_link['link_title']);
$variables['book_url'] = 'node/' . $book_link['bid'];
$variables['current_depth'] = $book_link['depth'];

 $variables['tree'] = '';
 if ($book_link['mlid']) {
 $variables['tree'] = book_children($book_link);
}

i can't understand it well, anyone can explain it for me. thank you, what'开发者_开发百科s the aim of this line "$book_link = $variables['book_link'];" how should i know $book_link is an array.


Here's how I understand it: The argument $variables is an array passed into the function by reference. One of it's elements is $variables['book_link'], which has some additional information about the book.

That block of 4 lines is basically copying values from the $variables['book_link'] array and moving them up one level:

  • $variables['book_link']['bid'] -> $variables['book_id']
  • $variables['book_link']['link_title'] -> $variables['book_title']

etc.

Then the last block of code determines if there are any child items to show in the navigation. If so, place them into $variables['tree'].


The function sets up the variables that are available in book-navigation.tpl.php. The function is called (along with other preprocess functions) in response to a call of

theme('book-navigation', $variables);

See Setting up variables for use in a template for how this works.

My guess is, $variables['book_link'] is an array when the theme function is called. But to be sure, you will have to search the sources of Drupal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜