hook                              HOOK   Ramu Ramakesavan  Phoenix Drupal User Group         January 2012
Client Side             Server SideHTML                    Apache WebserverCSS Style Sheets        PHP, PerlJavaScripts   ...
•   Display of data on the webpage    •   Structured presentation    •   Site specific modifications to presentation•   Cr...
themes/bartik/bartik.info                            Option „Demo block regions‟ under                            structur...
•modules/system/page.tpl.php•themes/bartik/templates/page.tpl.php                                        •modules/system/h...
•   template_preprocess; template_preprocess_<theme_element>    •   (web/includes/theme.inc)    •   default variables for ...
•   template_process; template_process_<theme_element>    •   (web/includes/theme.inc)    •   default variables for all th...
   If implemented using a real function instead of page.tpl.php then only    XXXX_preprocess_<theme_element>    XXXX_proc...
•   Display of data on the webpage    •   Structured presentation    •   Site specific modifications to presentation•   Cr...
   A web-page is created when a    http://www.ramustores.com/?q=examples/theming_example    is entered at the URL box in ...
function <mymodule>_menu() {    $items[examples/theming_example] =    array(        title => Theming Example,        descr...
function theming_example_page() {     $content[0] = t(Some examples of pages and forms that are run       through theme fu...
1,    User enters URL      _http://localhost/web/?q=examples/theming_example2.     Drupal executes code in web/index.php  ...
1.      drupal_render_page($MainContent) (common.inc) does the following:     1.    Copies the $MainContent into $page[„cu...
1.     Drupal_render($page) (common.inc) hands over to the presentation       layer (ie. Theming)     1.   Recursively inv...
   Searchable & editable array with key-     $page = array(    value pairs. Keys are searchable                #show_mess...
   _http://chicago2011.drupal.org/sessions/render-api-drupal-7    (franz heinzmann)   _http://www.archive.org/details/Pa...
Questions?
Drupal 7 Theming - Behind the scenes
Upcoming SlideShare
Loading in …5
×

Drupal 7 Theming - Behind the scenes

11,357 views

Published on

Drupal 7 Theming - Behind the Scenes: PHP control flow starting from entering URL to browser displaying webpage. Covers Theme info file, regions, an Rendear Arrays (Phoenix User Group 1/25/2012)

Published in: Education, Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
11,357
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
65
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Drupal 7 Theming - Behind the scenes

  1. 1. hook HOOK Ramu Ramakesavan Phoenix Drupal User Group January 2012
  2. 2. Client Side Server SideHTML Apache WebserverCSS Style Sheets PHP, PerlJavaScripts MySQL Drupal FrameworkAJAX Themes, Regions, Blocks Forms, Views, Panels Drupal Administration Installation Module, Hooks Updates/ Upgrades Caching Crawlers Debug
  3. 3. • Display of data on the webpage • Structured presentation • Site specific modifications to presentation• Creation of data for the webpage • Drupal7 mechanism for data creation • flow of control during data creation (PHP code) • Site specific modifications to data creation • Searchable and editable data format
  4. 4. themes/bartik/bartik.info Option „Demo block regions‟ under structure/block in adminstration
  5. 5. •modules/system/page.tpl.php•themes/bartik/templates/page.tpl.php •modules/system/html.tpl.php
  6. 6. • template_preprocess; template_preprocess_<theme_element> • (web/includes/theme.inc) • default variables for all theme element/ specific theme elements • theme_element: page, html, block, region, maintenance_page• <mymod>_preprocess; <mymod>_preprocess_<theme_element> • (web/sites/all/modules/<mymod>) • modules that didnt define the theme hook can alter the variables.• <ENGINE>_engine_preprocess;<ENGINE>_engine_preprocess_<them e_element> • (web/themes/engines/phptemplate/phptemple.engine) • Drupal uses PHPTemplate as default engine• <THEME>_preprocess; <THEME>_preprocess_ <theme_element> • (web/sites/all/theme/template.php) • Theme Bartik can set variables
  7. 7. • template_process; template_process_<theme_element> • (web/includes/theme.inc) • default variables for all theme element/ specific theme elements • theme_element: page, html, block, region, maintenance_page• <mymod>_process; <mymod>_process_<theme_element> • (web/sites/all/modules/<mymod>) • modules that didnt define the theme hook can alter the variables.• <ENGINE>_engine_process;<ENGINE>_engine_process_<theme_ele ment> • (web/themes/engines/phptemplate/phptemple.engine) • Drupal uses PHPTemplate as default engine• <THEME>_process; <THEME>_process_ <theme_element> • (web/sites/all/theme/template.php) • Theme Bartik can set variables
  8. 8.  If implemented using a real function instead of page.tpl.php then only XXXX_preprocess_<theme_element> XXXX_process_<theme_element> routines are executed Pre_process/process functions can define theme_hook_suggestion and s theme_hook_suggestion that can override current theme implementation links_contextual_node defines fallback implementations for named objects / contexts  Function a_b_c  Function a_b  Function aQuestion: When should these capabilities be used?
  9. 9. • Display of data on the webpage • Structured presentation • Site specific modifications to presentation• Creation of data for the webpage • Drupal7 mechanism for data creation • flow of control during data creation (PHP code) • Site specific modifications to data creation • Searchable and editable data format
  10. 10.  A web-page is created when a http://www.ramustores.com/?q=examples/theming_example is entered at the URL box in a browser A web-page is updated when a Menu item that is assigned http://www.ramustores.com/?q=examples/theming_example is selected Modules register path-CBfunction mapping that are stored in menu_router table Simplified URL works on top of this?
  11. 11. function <mymodule>_menu() { $items[examples/theming_example] = array( title => Theming Example, description => Some theming examples., page callback => theming_example_page, access callback => TRUE, access arguments => array(access content), ); $items[examples/theming_example/theming_example_list_page] = array( title => Theming a list, page callback => theming_example_list_page, access arguments => array(access content), weight => 1, ); return $items;}
  12. 12. function theming_example_page() { $content[0] = t(Some examples of pages and forms that are run through theme functions.); $content[1] = l(t(Simple page with a list), examples/theming_example/theming_example_list_page); $content[2] = l(t(Simple form 1), examples/theming_example/theming_example_order_form); $content[3] = l(t(Simple form 2), examples/theming_example/theming_example_text_form); $content[#theme_wrappers] = array(theming_example_content_array); return $content;}
  13. 13. 1, User enters URL _http://localhost/web/?q=examples/theming_example2. Drupal executes code in web/index.php  invokes function menu_execute_active_handler3. menu_execute_active_handler (menu.inc) does the following  searches menu_router for (examples/theming_example) and gets corresponding CallBackFunction.  MainContent=CBfunction(“examples/theming_example”)  drupal_deliver_page(MainContent, HTML (not AJAX or XML)) defined in menu.inc4. Drupal_deliver_page (common.inc) does the following:  drupal_deliver_html_page (MainContent)5. Drupal_deliver_html_page (common.inc) does the following:  drupal_render_page(MainContent)
  14. 14. 1. drupal_render_page($MainContent) (common.inc) does the following: 1. Copies the $MainContent into $page[„current‟] 2. Invokes <module>_page_build ($page)  each modules adds its data 3. Invokes drupal_alter( $page)  Your custom module can alter the contents of $page 4.Invokes drupal_render($page) ================================================block_page_build(„html page‟) (defined in block.module) does the following 1. $all_regions = system_region_list($theme); 2. for each ($region in $all_regions) { if ($blocks = block_get_block_by_regions($region)) { $page[$region] = $blocks; endif endfordrupal_alter (module.inc) does the following: 1. Invokes each module that has defined <module>_page_alter.
  15. 15. 1. Drupal_render($page) (common.inc) hands over to the presentation layer (ie. Theming) 1. Recursively invokes „theme()‟ to generate HTML code  First it calls page.tpl.php for Bartik  Next it calls html.tpl.php from system module
  16. 16.  Searchable & editable array with key- $page = array( value pairs. Keys are searchable #show_messages => TRUE, „#theme_wrappers‟=> „html‟ the data used to build a page is kept #theme => page, as render_array until they are ready to #type => page, be displayed using user selected content => array( theme system_main => array(...), another_block => array(...), Allows flexibility in changing the #sorted => TRUE, layout or content of a page ), sidebar_first => array( ... Alter and preprocess functions work ), with Render Array sidebar_second => array( ...Rendering = transforming render array ), into HTML footer => array( ...render([page[„content‟]) = ) drupal_render(page[„content‟]);
  17. 17.  _http://chicago2011.drupal.org/sessions/render-api-drupal-7 (franz heinzmann) _http://www.archive.org/details/PageRenderDrillDownInDrupal7 (moshe wiseman) _http://pingv.com/blog/a-peek-at-drupal-7-theme-system-changes _http://pingv.com/blog/grok-drupal-7-theming-update (Laura Scott) _http://drupal.org/node/930760 (render arrays in Drupal 7)
  18. 18. Questions?

×