SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Render API

                          Pavel Makhrinsky



e-mail: gumanistius@gmail.com
skype: gumanista
drupal.org: http://drupal.org/user/773216
facebook: https://www.facebook.com/gumanist
Overview
● Form API successor
● Drupal 6 ‘theme’ replacement
● System to build structured arrays into content
● The way to build presentation layer
Theming ways
● Noob way
● Drupal 6 way
● Drupal 7 way
Noob way
           1 <div class="nav">
● Inline   2 <ul class="topnav">
           3 <li id="lefttopnav" <?php if($levelone == 'home') echo "class="current"";?>><?php echo $menu1;?></li>
           4 <li <?php if($levelone == "item-2") echo "class="current"";?>> <?php echo $menu2;?></li>
● Inline   5 <li <?php if($levelone == "item-3") echo "class="current"";?>> <?php echo $menu4;?></li>
           6 <li <?php if($levelone == "item-4") echo "class="current"";?>> <?php echo $menu6;?></li>
           7 <li <?php if($levelone == "item-5") echo "class="current"";?>> <?php echo $menu5;?></li>
● Inline   8 <li <?php if($levelone == 'item-6') echo "class="current"";?>> <?php echo $menu7;?></li>
           9 </ul>
           10 </div>
● Inline
● Inline
Drupal 6 way
 ● Use theme functions
 ● Implement hook_theme
 ● Move large markup to templates


1 $items = array('item-1', 'item-2', 'item-3', 'item-4', 'item-5');
2 $output = theme('item_list', $items);
Drupal 6 way - advantages
● Common way to render elements
● Reusable functions
● Predictable markup
● Possibility to change generation
● Output altering
Drupal 6 way - disadvantages
● Slower performance
● Caching difficulties
● Different parameters
Drupal 7 way
 ● Use renderable arrays
 ● Alter content you need



1 $items = array('item-1', 'item-2', 'item-3', 'item-4', 'item-5');
2 $output = array(
3 '#items' => $items,
4 '#theme' => 'item_list'
5 );
Drupal 7 way advantages
● Content alterable in a common way
● All the renderable elements have preprocess
  and process functions
● Transparent caching
● Resources could be attached to elements
Render API details
● hook_theme
● Renderable array structure
● Content altering
● #type, #theme, #theme_wrappers
● #states
● Resources
● Performance and caching
hook_theme()
● hook_theme
 ○ variables | render element
 ○ file
 ○ path
 ○ template
 ○ function
 ○ preprocess functions
Renderable array structure
● ‘#’ elements
● system elements
  ○ #children
  ○ #access
  ○ #printed
  ○ #sorted
Content altering
● #pre_render
● #post_render
● preprocess and process functions
#type
 ● Loads defaults from hook_element_info()
1 // If the default values for this element have not been loaded yet, populate
2 // them.
3 if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) {
4 $elements += element_info($elements['#type']);
5}




1 function module_template_element_info() {
2 return array(
3 'file_template' => array(
4 '#name' => 'misc',
5 '#fileinfo' => array(
6 'filename' => '[module_name].[name].[extension]',
7 'path' => 'includes',
8 'extension' => 'inc'
9)
10 )
11 );
11 }
#theme
 ● Invokes theme() function
1 // Get the children of the element, sorted by weight.
2 $children = element_children($elements, TRUE);
3
4 // Initialize this element's #children, unless a #pre_render callback already
5 // preset #children.
6 if (!isset($elements['#children'])) {
7 $elements['#children'] = '';
8}
9 // Call the element's #theme function if it is set. Then any children of the
10 // element have to be rendered there.
11 if (isset($elements['#theme'])) {
12 $elements['#children'] = theme($elements['#theme'], $elements);
13 }
14 // If #theme was not set and the element has children, render them now.
15 // This is the same process as drupal_render_children() but is inlined
16 // for speed.
17 if ($elements['#children'] == '') {
18 foreach ($children as $key) {
19 $elements['#children'] .= drupal_render($elements[$key]);
20 }
21 }
#theme_wrappers
 ● Wrap #children element with code
1 // Let the theme functions in #theme_wrappers add markup around the rendered
2 // children.
3 if (isset($elements['#theme_wrappers'])) {
4 foreach ($elements['#theme_wrappers'] as $theme_wrapper) {
5 $elements['#children'] = theme($theme_wrapper, $elements);
6}
7}
#states
● Adds JavaScript to change the state of an
  element based on another element
1 $form['toggle_me'] = array(
2 '#type' => 'checkbox',
3 '#title' => t('Tick this box to type'),
4 );
5 $form['settings'] = array(
6 '#type' => 'textfield',
7 '#states' => array(
8 // Only show this field when the 'toggle_me' checkbox is enabled.
9 'visible' => array(
10 ':input[name="toggle_me"]' => array('checked' => TRUE),
11 ),
12 ),
13 );
Resources
● #attached property
● Allow attach
  ○ CSS
  ○ JavaScript
  ○ Libraries
● Not cached
Performance and caching
● Setting cache for renderable arrays
● Some cache usage tips
#cache
● 'keys' => an array of keys which will be
  concatenated to form the cache key.
● 'bin' => the name of the cache bin to be used
  (as in 'cache' or 'cache_page', etc.
● 'expire' => a Unix timestamp indicating the
  expiration time of the cache.
● 'granularity' => a bitmask indicating the cache
  type. This should be
  DRUPAL_CACHE_PER_PAGE,
  DRUPAL_CACHE_PER_ROLE, or
  DRUPAL_CACHE_PER_USER
Some cache usage tips
● Don’t cache small items
● Items from #attached not stored with rendered
Elements            5      100          500
   items
With #cache
Without #cache
                    3211
                    747
                           3276
                           4257
                                        3235
                                        18336
● Use cache targeting
● Cache items will not be expired until cron runs,
   regardless of the expiration time used
Summary
● Don’t use direct call of theme() function
● Generate HTML as later as possible
Links
● Render API
     ○ http://drupal.org/node/933976
     ○ http://drupal.org/node/930760
     ○ http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_render/7
● States
     ○ http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_process_states/7
● Drupal API
     ○ http://api.drupal.org
● Examples module
     ○ http://drupal.org/project/examples
● Cache backends
     ○ http://drupal.org/project/apc
     ○ http://drupal.org/project/memcache
     ○ http://drupal.org/project/filecache
Thank you




e-mail: gumanistius@gmail.com
skype: gumanista
drupal.org: http://drupal.org/user/773216
facebook: https://www.facebook.com/gumanist

Contenu connexe

Tendances

The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the BeastBastian Feder
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownpartsBastian Feder
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixturesBill Chang
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09Bastian Feder
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON APIpodsframework
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3markstory
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needKacper Gunia
 

Tendances (20)

The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09The Beauty And The Beast Php N W09
The Beauty And The Beast Php N W09
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON API
 
CakeFest 2013 keynote
CakeFest 2013 keynoteCakeFest 2013 keynote
CakeFest 2013 keynote
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 

En vedette

Revistă bibliografică: Suveranitatea, Independență, Democrație și Libertate
Revistă bibliografică: Suveranitatea, Independență, Democrație și LibertateRevistă bibliografică: Suveranitatea, Independență, Democrație și Libertate
Revistă bibliografică: Suveranitatea, Independență, Democrație și LibertateTatiana Dontu
 
IAP&IAB Cash Testing
IAP&IAB Cash TestingIAP&IAB Cash Testing
IAP&IAB Cash TestingIssis Tsai
 
Photography Presentation
Photography PresentationPhotography Presentation
Photography Presentationbtecmediasdc
 
Visually impaired
Visually impairedVisually impaired
Visually impairedCachelle
 
Techpetually speaking: How Tech is Transforming the Pet Industry
Techpetually speaking: How Tech is Transforming the Pet IndustryTechpetually speaking: How Tech is Transforming the Pet Industry
Techpetually speaking: How Tech is Transforming the Pet IndustryBarkWorld Expo
 
Tajuk sejarah spm 2012
Tajuk sejarah spm 2012Tajuk sejarah spm 2012
Tajuk sejarah spm 2012eppy25
 
Hoja de vida corporativa
Hoja de vida corporativaHoja de vida corporativa
Hoja de vida corporativaSTEPHI05
 
Baking & Pastry - Bread Making Process
Baking & Pastry -  Bread Making ProcessBaking & Pastry -  Bread Making Process
Baking & Pastry - Bread Making ProcessPhaik Leng Oh
 
Bahasa Malaysia Kertas 1(Teknik Menjawab)
Bahasa Malaysia Kertas 1(Teknik Menjawab)Bahasa Malaysia Kertas 1(Teknik Menjawab)
Bahasa Malaysia Kertas 1(Teknik Menjawab)C.K.Peng
 

En vedette (12)

Revistă bibliografică: Suveranitatea, Independență, Democrație și Libertate
Revistă bibliografică: Suveranitatea, Independență, Democrație și LibertateRevistă bibliografică: Suveranitatea, Independență, Democrație și Libertate
Revistă bibliografică: Suveranitatea, Independență, Democrație și Libertate
 
Survival
SurvivalSurvival
Survival
 
IAP&IAB Cash Testing
IAP&IAB Cash TestingIAP&IAB Cash Testing
IAP&IAB Cash Testing
 
Photography Presentation
Photography PresentationPhotography Presentation
Photography Presentation
 
Visually impaired
Visually impairedVisually impaired
Visually impaired
 
Techpetually speaking: How Tech is Transforming the Pet Industry
Techpetually speaking: How Tech is Transforming the Pet IndustryTechpetually speaking: How Tech is Transforming the Pet Industry
Techpetually speaking: How Tech is Transforming the Pet Industry
 
Tajuk sejarah spm 2012
Tajuk sejarah spm 2012Tajuk sejarah spm 2012
Tajuk sejarah spm 2012
 
Hoja de vida corporativa
Hoja de vida corporativaHoja de vida corporativa
Hoja de vida corporativa
 
Asic pd
Asic pdAsic pd
Asic pd
 
Baking & Pastry - Bread Making Process
Baking & Pastry -  Bread Making ProcessBaking & Pastry -  Bread Making Process
Baking & Pastry - Bread Making Process
 
Presentation.ai
Presentation.aiPresentation.ai
Presentation.ai
 
Bahasa Malaysia Kertas 1(Teknik Menjawab)
Bahasa Malaysia Kertas 1(Teknik Menjawab)Bahasa Malaysia Kertas 1(Teknik Menjawab)
Bahasa Malaysia Kertas 1(Teknik Menjawab)
 

Similaire à Render API guide to building structured arrays

Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011camp_drupal_ua
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - LondonMarek Sotak
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel MakhrinskyDrupalCampDN
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8Logan Farr
 
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal APIAlexandru Badiu
 
Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.Samuel Solís Fuentes
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes ramakesavan
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Siva Epari
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Developmentipsitamishra
 
Drupal 8 Every Day: An Intro to Developing With Drupal 8
Drupal 8 Every Day: An Intro to Developing With Drupal 8Drupal 8 Every Day: An Intro to Developing With Drupal 8
Drupal 8 Every Day: An Intro to Developing With Drupal 8Acquia
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsLuís Carneiro
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionPhilip Norton
 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESDrupalCamp Kyiv
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsPierre MARTIN
 
Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attributeRichard Martens
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developersDream Production AG
 
Drupal 8. Search API. Facets. Customize / combine facets
Drupal 8. Search API. Facets. Customize / combine facetsDrupal 8. Search API. Facets. Customize / combine facets
Drupal 8. Search API. Facets. Customize / combine facetsAnyforSoft
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration managementAlexander Tkachev
 

Similaire à Render API guide to building structured arrays (20)

Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
 
Learning the basics of the Drupal API
Learning the basics of the Drupal APILearning the basics of the Drupal API
Learning the basics of the Drupal API
 
Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.Drupal 8 simple page: Mi primer proyecto en Drupal 8.
Drupal 8 simple page: Mi primer proyecto en Drupal 8.
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Drupal 8 Every Day: An Intro to Developing With Drupal 8
Drupal 8 Every Day: An Intro to Developing With Drupal 8Drupal 8 Every Day: An Intro to Developing With Drupal 8
Drupal 8 Every Day: An Intro to Developing With Drupal 8
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First Steps
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attribute
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
Drupal 8. Search API. Facets. Customize / combine facets
Drupal 8. Search API. Facets. Customize / combine facetsDrupal 8. Search API. Facets. Customize / combine facets
Drupal 8. Search API. Facets. Customize / combine facets
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration management
 

Dernier

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Dernier (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Render API guide to building structured arrays

  • 1. Render API Pavel Makhrinsky e-mail: gumanistius@gmail.com skype: gumanista drupal.org: http://drupal.org/user/773216 facebook: https://www.facebook.com/gumanist
  • 2. Overview ● Form API successor ● Drupal 6 ‘theme’ replacement ● System to build structured arrays into content ● The way to build presentation layer
  • 3. Theming ways ● Noob way ● Drupal 6 way ● Drupal 7 way
  • 4. Noob way 1 <div class="nav"> ● Inline 2 <ul class="topnav"> 3 <li id="lefttopnav" <?php if($levelone == 'home') echo "class="current"";?>><?php echo $menu1;?></li> 4 <li <?php if($levelone == "item-2") echo "class="current"";?>> <?php echo $menu2;?></li> ● Inline 5 <li <?php if($levelone == "item-3") echo "class="current"";?>> <?php echo $menu4;?></li> 6 <li <?php if($levelone == "item-4") echo "class="current"";?>> <?php echo $menu6;?></li> 7 <li <?php if($levelone == "item-5") echo "class="current"";?>> <?php echo $menu5;?></li> ● Inline 8 <li <?php if($levelone == 'item-6') echo "class="current"";?>> <?php echo $menu7;?></li> 9 </ul> 10 </div> ● Inline ● Inline
  • 5. Drupal 6 way ● Use theme functions ● Implement hook_theme ● Move large markup to templates 1 $items = array('item-1', 'item-2', 'item-3', 'item-4', 'item-5'); 2 $output = theme('item_list', $items);
  • 6. Drupal 6 way - advantages ● Common way to render elements ● Reusable functions ● Predictable markup ● Possibility to change generation ● Output altering
  • 7. Drupal 6 way - disadvantages ● Slower performance ● Caching difficulties ● Different parameters
  • 8. Drupal 7 way ● Use renderable arrays ● Alter content you need 1 $items = array('item-1', 'item-2', 'item-3', 'item-4', 'item-5'); 2 $output = array( 3 '#items' => $items, 4 '#theme' => 'item_list' 5 );
  • 9. Drupal 7 way advantages ● Content alterable in a common way ● All the renderable elements have preprocess and process functions ● Transparent caching ● Resources could be attached to elements
  • 10. Render API details ● hook_theme ● Renderable array structure ● Content altering ● #type, #theme, #theme_wrappers ● #states ● Resources ● Performance and caching
  • 11. hook_theme() ● hook_theme ○ variables | render element ○ file ○ path ○ template ○ function ○ preprocess functions
  • 12. Renderable array structure ● ‘#’ elements ● system elements ○ #children ○ #access ○ #printed ○ #sorted
  • 13. Content altering ● #pre_render ● #post_render ● preprocess and process functions
  • 14. #type ● Loads defaults from hook_element_info() 1 // If the default values for this element have not been loaded yet, populate 2 // them. 3 if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) { 4 $elements += element_info($elements['#type']); 5} 1 function module_template_element_info() { 2 return array( 3 'file_template' => array( 4 '#name' => 'misc', 5 '#fileinfo' => array( 6 'filename' => '[module_name].[name].[extension]', 7 'path' => 'includes', 8 'extension' => 'inc' 9) 10 ) 11 ); 11 }
  • 15. #theme ● Invokes theme() function 1 // Get the children of the element, sorted by weight. 2 $children = element_children($elements, TRUE); 3 4 // Initialize this element's #children, unless a #pre_render callback already 5 // preset #children. 6 if (!isset($elements['#children'])) { 7 $elements['#children'] = ''; 8} 9 // Call the element's #theme function if it is set. Then any children of the 10 // element have to be rendered there. 11 if (isset($elements['#theme'])) { 12 $elements['#children'] = theme($elements['#theme'], $elements); 13 } 14 // If #theme was not set and the element has children, render them now. 15 // This is the same process as drupal_render_children() but is inlined 16 // for speed. 17 if ($elements['#children'] == '') { 18 foreach ($children as $key) { 19 $elements['#children'] .= drupal_render($elements[$key]); 20 } 21 }
  • 16. #theme_wrappers ● Wrap #children element with code 1 // Let the theme functions in #theme_wrappers add markup around the rendered 2 // children. 3 if (isset($elements['#theme_wrappers'])) { 4 foreach ($elements['#theme_wrappers'] as $theme_wrapper) { 5 $elements['#children'] = theme($theme_wrapper, $elements); 6} 7}
  • 17. #states ● Adds JavaScript to change the state of an element based on another element 1 $form['toggle_me'] = array( 2 '#type' => 'checkbox', 3 '#title' => t('Tick this box to type'), 4 ); 5 $form['settings'] = array( 6 '#type' => 'textfield', 7 '#states' => array( 8 // Only show this field when the 'toggle_me' checkbox is enabled. 9 'visible' => array( 10 ':input[name="toggle_me"]' => array('checked' => TRUE), 11 ), 12 ), 13 );
  • 18. Resources ● #attached property ● Allow attach ○ CSS ○ JavaScript ○ Libraries ● Not cached
  • 19. Performance and caching ● Setting cache for renderable arrays ● Some cache usage tips
  • 20. #cache ● 'keys' => an array of keys which will be concatenated to form the cache key. ● 'bin' => the name of the cache bin to be used (as in 'cache' or 'cache_page', etc. ● 'expire' => a Unix timestamp indicating the expiration time of the cache. ● 'granularity' => a bitmask indicating the cache type. This should be DRUPAL_CACHE_PER_PAGE, DRUPAL_CACHE_PER_ROLE, or DRUPAL_CACHE_PER_USER
  • 21. Some cache usage tips ● Don’t cache small items ● Items from #attached not stored with rendered Elements 5 100 500 items With #cache Without #cache 3211 747 3276 4257 3235 18336 ● Use cache targeting ● Cache items will not be expired until cron runs, regardless of the expiration time used
  • 22. Summary ● Don’t use direct call of theme() function ● Generate HTML as later as possible
  • 23. Links ● Render API ○ http://drupal.org/node/933976 ○ http://drupal.org/node/930760 ○ http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_render/7 ● States ○ http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_process_states/7 ● Drupal API ○ http://api.drupal.org ● Examples module ○ http://drupal.org/project/examples ● Cache backends ○ http://drupal.org/project/apc ○ http://drupal.org/project/memcache ○ http://drupal.org/project/filecache
  • 24. Thank you e-mail: gumanistius@gmail.com skype: gumanista drupal.org: http://drupal.org/user/773216 facebook: https://www.facebook.com/gumanist