Date post: | 22-Apr-2015 |
Category: |
Education |
Upload: | ramakesavan |
View: | 6,434 times |
Download: | 1 times |
Ramu Ramakesavan Phoenix Drupal User Group
January 2012
hook
HOOK
HTML
CSS Style Sheets
JavaScripts
PHP, Perl
Themes, Regions, Blocks Forms, Views, Panels Administration Module, Hooks Caching Debug
MySQL
Drupal Framework
Apache Webserver
AJAX
Client Side Server Side
Drupal Installation
Updates/ Upgrades Crawlers
• 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
themes/bartik/bartik.info
Option „Demo block regions‟ under structure/block in adminstration
•modules/system/page.tpl.php •themes/bartik/templates/page.tpl.php
•modules/system/html.tpl.php
• 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 didn't define the theme hook can alter the variables.
• <ENGINE>_engine_preprocess;<ENGINE>_engine_preprocess_<theme_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
• 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 didn't define the theme hook can alter the variables.
• <ENGINE>_engine_process;<ENGINE>_engine_process_<theme_element> • (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
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
theme_hook_suggestions that can override current theme implementation
links_contextual_node defines fallback implementations for named
objects / contexts Function a_b_c Function a_b Function a
Question: When should these capabilities be used?
• 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
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?
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;
}
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;
}
1, User enters URL _http://localhost/web/?q=examples/theming_example
2. Drupal executes code in web/index.php
invokes function menu_execute_active_handler
3. 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.inc
4. 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)
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
endfor
drupal_alter (module.inc) does the following:
1. Invokes each module that has defined <module>_page_alter.
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
$page = array(
'#show_messages' => TRUE,
„#theme_wrappers‟=> „html‟
'#theme' => 'page',
'#type' => 'page',
'content' => array( 'system_main' => array(...), 'another_block' => array(...), '#sorted' => TRUE,
),
'sidebar_first' => array( ... ),
'sidebar_second' => array( ... ),
'footer' => array( ... )
Searchable & editable array with key-value pairs. Keys are searchable
the data used to build a page is kept as render_array until they are ready to be displayed using user selected theme
Allows flexibility in changing the layout or content of a page
Alter and preprocess functions work with Render Array
Rendering = transforming render array into HTML
render([page[„content‟]) = drupal_render(page[„content‟]);
_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)
Questions?