SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler offline
Drupal Advanced Theming
  DrupalCamp Estonia



      Kaido Toomingas
       14.June 2012
Problem
●   You need more than Drupal theme can offer you out of box
●   You dont need some stuff wich Drupal offers You out of box
Solutions
●   Lets just put this into templates ;) What does Your designer would
    say?
●   What should I do then?
●   Template.php
●   Custom module
How can I implement this?
●   Hooks? Examples...?
●   TEMPLATE_preprocess(&$variables, $hook)
●   HOOK_form_alter(&$form, &$form_state, $form_id)
●   theme($hook, $variables = array())
●   THEMEHOOK_settings() in theme-settings.php
●   THEMENAME_form_system_theme_settings_alter(&$form,
    $form_state)
●   hook_theme_registry_alter()
Hooks

Hooks in drupal are functions
wich will help you to change or
extend default functionality.
Preprocess
●       TEMPLATE_preprocess(&$variables, $hook)
●       TEMPLATE_preprocess_HOOK(&$variables)
●   Manipulate or create variables. Example page variables. You
    can add these into template.php.
    Example:
    function template_preprocess_foo(&$variables) {
        $variables['foo_list'] = array(
         'list item 1',
         'list item 2',
         'list item 3',
        );
    }
Modify forms
●       HOOK_form_alter(&$form, &$form_state, $form_id)
●       hook_form_FORM_ID_alter
    ●   Change existing form elements by changing or adding
        some arrays.
    ●   Create new form elements – There is better way.

Example:

function example_form_alter(&$form, &$form_state, $form_id) {
  dsm($form_id); // print form ID to messages You need devel
module switched for using dsm() function
  dsm($form); // pretty print array using Krumo to messages
}
Theme some data
●   theme($hook, $variables = array())
●   Usecase: You want to create a table, image or some other element
    from you data. You should use theme function for that.
●   Usage: Can be used in template.php or custom modules.
    Example:

    theme('table', array(
      'header' => $header,
      'rows' => $options,
      'attributes' => array('class' => array('mytable'))
    ));
hook_theme_registry_alter()
●   This is the most powerful themer helper wich should be used only
    when can't find any way to change your theme.
●   You can use this when there is module wich doesnt have proper theme
    fuctions wich could be overwritten.
Advanced theming

Mais conteúdo relacionado

Mais procurados

Drupal Theming
Drupal ThemingDrupal Theming
Drupal Theming
takrin54
 

Mais procurados (11)

Js c1 best practices
Js c1 best practicesJs c1 best practices
Js c1 best practices
 
Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8Mikhail Kraynuk. Form api. Drupal 8
Mikhail Kraynuk. Form api. Drupal 8
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子
 
WordPress REST API: Expert Advice & Practical Use Cases
WordPress REST API: Expert Advice & Practical Use CasesWordPress REST API: Expert Advice & Practical Use Cases
WordPress REST API: Expert Advice & Practical Use Cases
 
Drupal Theming
Drupal ThemingDrupal Theming
Drupal Theming
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06
 
10 useful WordPress functions (and maybe more)
10 useful WordPress functions (and maybe more)10 useful WordPress functions (and maybe more)
10 useful WordPress functions (and maybe more)
 
Advanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your ViewAdvanced Drupal Views: Theming your View
Advanced Drupal Views: Theming your View
 
DBIC 2 - Resultsets
DBIC 2 - ResultsetsDBIC 2 - Resultsets
DBIC 2 - Resultsets
 
Table through php
Table through phpTable through php
Table through php
 

Semelhante a Advanced theming

Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
drubb
 
Atomicant Drupal 6 Theming
Atomicant Drupal 6 ThemingAtomicant Drupal 6 Theming
Atomicant Drupal 6 Theming
Marek Sotak
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
Emma Jane Hogbin Westby
 
Drupal 7 Theming - what's new
Drupal 7 Theming - what's newDrupal 7 Theming - what's new
Drupal 7 Theming - what's new
Marek Sotak
 

Semelhante a Advanced theming (20)

D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
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: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
 
Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoring
 
Fapi
FapiFapi
Fapi
 
Drupal Front End PHP
Drupal Front End PHPDrupal Front End PHP
Drupal Front End PHP
 
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
 
Improve theming with (Twitter) Bootstrap
Improve theming with  (Twitter) BootstrapImprove theming with  (Twitter) Bootstrap
Improve theming with (Twitter) Bootstrap
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
Design Patterns and Usage
Design Patterns and UsageDesign Patterns and Usage
Design Patterns and Usage
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Atomicant Drupal 6 Theming
Atomicant Drupal 6 ThemingAtomicant Drupal 6 Theming
Atomicant Drupal 6 Theming
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
 
Drupal 7 Theming - what's new
Drupal 7 Theming - what's newDrupal 7 Theming - what's new
Drupal 7 Theming - what's new
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Plugins
 
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 Render API
Drupal Render APIDrupal Render API
Drupal Render API
 

Mais de drupalcampest

Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
drupalcampest
 

Mais de drupalcampest (11)

Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Welcome to Drupalcamp Estonia 2012
Welcome to Drupalcamp Estonia 2012Welcome to Drupalcamp Estonia 2012
Welcome to Drupalcamp Estonia 2012
 
Implementing Drupalcamp sites
Implementing Drupalcamp sitesImplementing Drupalcamp sites
Implementing Drupalcamp sites
 
Designing Drupalcamp sites
Designing Drupalcamp sitesDesigning Drupalcamp sites
Designing Drupalcamp sites
 
Drupal vs. the Others
Drupal vs. the OthersDrupal vs. the Others
Drupal vs. the Others
 
Migrating University of Tartu websites to Drupal
Migrating University of Tartu websites to DrupalMigrating University of Tartu websites to Drupal
Migrating University of Tartu websites to Drupal
 
Drupalcamp Tallinn - Drupal 8
Drupalcamp Tallinn - Drupal 8Drupalcamp Tallinn - Drupal 8
Drupalcamp Tallinn - Drupal 8
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Drupalcamp Estonia - Drupal 7
Drupalcamp Estonia - Drupal 7Drupalcamp Estonia - Drupal 7
Drupalcamp Estonia - Drupal 7
 
Drupalcamp Estonia - Introduction to Drupal
Drupalcamp Estonia - Introduction to DrupalDrupalcamp Estonia - Introduction to Drupal
Drupalcamp Estonia - Introduction to Drupal
 
Drupalcamp Estonia 2011 - Welcome
Drupalcamp Estonia 2011 - WelcomeDrupalcamp Estonia 2011 - Welcome
Drupalcamp Estonia 2011 - Welcome
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 

Advanced theming

  • 1. Drupal Advanced Theming DrupalCamp Estonia Kaido Toomingas 14.June 2012
  • 2. Problem ● You need more than Drupal theme can offer you out of box ● You dont need some stuff wich Drupal offers You out of box
  • 3. Solutions ● Lets just put this into templates ;) What does Your designer would say? ● What should I do then? ● Template.php ● Custom module
  • 4. How can I implement this? ● Hooks? Examples...? ● TEMPLATE_preprocess(&$variables, $hook) ● HOOK_form_alter(&$form, &$form_state, $form_id) ● theme($hook, $variables = array()) ● THEMEHOOK_settings() in theme-settings.php ● THEMENAME_form_system_theme_settings_alter(&$form, $form_state) ● hook_theme_registry_alter()
  • 5. Hooks Hooks in drupal are functions wich will help you to change or extend default functionality.
  • 6. Preprocess ● TEMPLATE_preprocess(&$variables, $hook) ● TEMPLATE_preprocess_HOOK(&$variables) ● Manipulate or create variables. Example page variables. You can add these into template.php. Example: function template_preprocess_foo(&$variables) { $variables['foo_list'] = array( 'list item 1', 'list item 2', 'list item 3', ); }
  • 7. Modify forms ● HOOK_form_alter(&$form, &$form_state, $form_id) ● hook_form_FORM_ID_alter ● Change existing form elements by changing or adding some arrays. ● Create new form elements – There is better way. Example: function example_form_alter(&$form, &$form_state, $form_id) { dsm($form_id); // print form ID to messages You need devel module switched for using dsm() function dsm($form); // pretty print array using Krumo to messages }
  • 8. Theme some data ● theme($hook, $variables = array()) ● Usecase: You want to create a table, image or some other element from you data. You should use theme function for that. ● Usage: Can be used in template.php or custom modules. Example: theme('table', array( 'header' => $header, 'rows' => $options, 'attributes' => array('class' => array('mytable')) ));
  • 9. hook_theme_registry_alter() ● This is the most powerful themer helper wich should be used only when can't find any way to change your theme. ● You can use this when there is module wich doesnt have proper theme fuctions wich could be overwritten.