SlideShare uma empresa Scribd logo
1 de 26
Developing for Drupal:
first steps, tips & tricks
    Drupal Camp Portugal 2012
             Luís Carneiro
    http://drupal.org/user/780690
          eltugis@gmail.com
Resources

• The example sandbox module
  – http://tinyurl.com/portocamp-module
Agenda

•   First steps
•   Some basics of the Drupal API
•   Presentation of coding examples
•   Questions and Discussion
Set your Developing Environment
•   Netbeans
•   Eclipse      Look for:
                 • Debugger integration
•   Aptana       • Function list view
•   Komodo IDE   • Jump to function
                 • Source control integration
•   Coda         • Ability to search across files
                 • Ability to configure syntax style
•   Vim            (follow coding standards)
•   …
Debugger is your friend
            See how the information flows
            Track bugs and understand code
Follow the coding standards
• drupal.org/coding-standards

• http://tinyurl.com/configuring-netbeans

• Use the coder module to validate your code
What is assumed

  You know the basic components of Drupal


Content
                Blocks       Taxonomies       Users
 Types


      Modules            Themes      Fields
Drupal Stack
              Drupal Theme

Contributed Modules    Custom Modules



          Drupal Core
Drupal API family
Module      Theme
                       Form API
System      System

                       Schema
Field API   DB Layer
                         API

 Menu       Search
                           …
System       API
Hook concept
• “Event listeners”
• Possibility to act in certain points of a page
  execution
  – To add our custom functionalities
  – To alter other’s functionalities


     • Drupal Moto: Don’t hack Core or
       others code!
Hooks

   hook_init       hook_menu

                                    Drupal Core has
hook_form_alter    hook_theme
                                    about 250 hooks!
                                    See the full list:
                                    http://tinyurl.com/drupal-hooks

  hook_mail       hook_field_info




 hook_schema            …
It all resumes to…


     module_invoke_all(‘hook_name’)
                  or
module_invoke(‘module_name’,’hook_name’)
What you need for a module
Files created in:
sites/all/modules/custom/yourmodule




       yourmodule.info            yourmodule.module




        yourmodule.install            README.txt
               (optional)             (good practice)
.info File

name = Your module name
description = Line description about module purpose
package = Group of modules it should belong
core = 7.x (or other version of Drupal)
files[] = yourmodule.module (and all other files which
code should run of every page)
Module Purpose
•   Create blocks
•   Create pages and forms
•   Create a new field type
•   Extend/customize Drupal core
•   Extend/customize Contributed modules
•   …
Form API
• drupal_get_form($form_id)
   – $form_id usually is <module_name>_<description>_form
   – Builds a form structure


• Many form elements
   – textfield, select, checkbox, radio, password…
   – The full reference list http://tinyurl.com/drupal-form-api

• validate and submit handlers
   – <form_id>_validate(&$form, &$form_state)
   – <form_id>_submit(&form, &$form_state)
Cache in Drupal
• Internal cache
  – Menu, Form, Path, Filter, Field…
  – Cache Page (specific for anonymous users)
     • The one you activate in “Performance” settings


• Custom cache
  – Two simple functions:
     • cache_set($cid, $data, $bin, $expire)
     • cache_get($cid, $bin)
Database Access

    Static                      Dynamic
   Queries                      queries
• Usually simple queries     • OOP query object
• Only Select queries may    • Database agnostic
  be static                  • Possibility to alter query
                               elements
db_query($sql_query)



             Full database API documentation
       http://drupal.org/developing/api/database
Theme System

Template File            or     Template Function


                Preprocessing
                  Functions

         • Set the variables for the templates
         • Define the logic
Theme Simple Example

                                               function theme_custom_output($variables) {
function yourmodule_theme() {                    …
  return array(                                  return $output;
    'custom_output' => array(                  }
      'variables' => array('node' => NULL),
    ),
  );                                           Function template_custom_output($variables) {
}                                                …
                                                 return $output;
                                               }

…
print theme('custom_output', array('node' =>   function yourtheme_custom_output($variables) {
                                                 …
$node));
                                                 return $output;
…                                              }



                                                    All valid theme definitions!
Theming tips
• Use devel themer module to find the theming
  elements on your page
• Clear theme registry cache when setting new
  templates

               Useful Resources:
               http://tinyurl.com/drupal-theme-implementations
               http://tinyurl.com/render-arrays
I see a lot of arrays!
$page = array(
  '#show_messages' => TRUE,
  '#theme' => 'page',                In many cases, the data used to
  '#type' => 'page',
  'content' => array(                build a page (and all parts of it) is
    'system_main' => array(...),     kept as structured arrays until the
    'another_block' => array(...),
    '#sorted' => TRUE,               rendering stage
  ),
  'sidebar_first' => array(
    ...                              Enormous flexibility in changing
  ),
  'footer' => array(                 the layout or content of a page
    ...                              and its components!
  ),
  ...
);
Use Drupal’s utility functions
• Function l(): Formats an internal or external URL link
  as an HTML anchor tag.
• Function t(): wrap text to be translated.
• Function drupal_set_message(): status message for
  user performed operations
• Function watchdog(): logs system messages to drupal
  log.
Simplify with Drush
• Command line tool to do common Drupal
  actions
    – Possibility to create your own drush
      commands…writing hooks!

Clear caches                               $ drush
Download/Enable modules                    $ drush help <command>
Synchronize dev and production databases
Check the log messages
…
Version Control Everything
• Code + Configurations (in database)
  – Code, easy to version control
  – Configurations… there comes Features +
    Strongarm module!
     • Database configurations exported to code
     • Tip: Keep your features small
Learning Resources
• Web
   – http://api.drupal.org
   – http://drupal.org/project/examples
   – http://drupal.org/developing/api
• Training
   – http://drupalize.me
   – http://buildamodule.com/
• Books
   – Drupal 7 Module Development
   – Pro Drupal 7 Development
   – Using Drupal 7

Mais conteúdo relacionado

Mais procurados

Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Balázs Tatár
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Formsdrubb
 
Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbaivibrantuser
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Themingdrubb
 
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
 
Puppet DSL gotchas, and understandiing Roles & Profiles pattern
Puppet DSL gotchas, and understandiing Roles & Profiles patternPuppet DSL gotchas, and understandiing Roles & Profiles pattern
Puppet DSL gotchas, and understandiing Roles & Profiles patternAlex Simenduev
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?Alexandru Badiu
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Balázs Tatár
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2Mizanur Rahaman Mizan
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
PuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, Puppet
PuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, PuppetPuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, Puppet
PuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, PuppetPuppet
 
YAG - Yet another gallery (2012)
YAG - Yet another gallery (2012)YAG - Yet another gallery (2012)
YAG - Yet another gallery (2012)Daniel Lienert
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of LithiumNate Abele
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkExove
 
Ant_quick_guide
Ant_quick_guideAnt_quick_guide
Ant_quick_guideducquoc_vn
 
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 WorkshopWordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 WorkshopCurtiss Grymala
 
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
 

Mais procurados (20)

Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Forms
 
Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbai
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Puppet DSL gotchas, and understandiing Roles & Profiles pattern
Puppet DSL gotchas, and understandiing Roles & Profiles patternPuppet DSL gotchas, and understandiing Roles & Profiles pattern
Puppet DSL gotchas, and understandiing Roles & Profiles pattern
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2WordPress Theme Design and Development Workshop - Day 2
WordPress Theme Design and Development Workshop - Day 2
 
Theme API
Theme APITheme API
Theme API
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
PuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, Puppet
PuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, PuppetPuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, Puppet
PuppetConf 2017: Hiera 5: The Full Data Enchilada- Hendrik Lindberg, Puppet
 
YAG - Yet another gallery (2012)
YAG - Yet another gallery (2012)YAG - Yet another gallery (2012)
YAG - Yet another gallery (2012)
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a Framework
 
Ant_quick_guide
Ant_quick_guideAnt_quick_guide
Ant_quick_guide
 
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 WorkshopWordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 Workshop
 
Any tutor
Any tutorAny tutor
Any tutor
 
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
 

Semelhante a Drupal Camp Porto - Developing with Drupal: First Steps

Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentationhtyson
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS DrupalMumbai
 
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 2009Emma Jane Hogbin Westby
 
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
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Drupalcon Paris
 
Drupal: an Overview
Drupal: an OverviewDrupal: an Overview
Drupal: an OverviewMatt Weaver
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Angela Byron
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2Confiz
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Eugenio Minardi
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaGábor Hojtsy
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareOpevel
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet CampPuppet
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011camp_drupal_ua
 
Your first d8 module
Your first d8 moduleYour first d8 module
Your first d8 moduletedbow
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security rightGábor Hojtsy
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 

Semelhante a Drupal Camp Porto - Developing with Drupal: First Steps (20)

Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentation
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
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
 
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
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Drupal: an Overview
Drupal: an OverviewDrupal: an Overview
Drupal: an Overview
 
Drupal theming
Drupal themingDrupal theming
Drupal theming
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp Bratislava
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshare
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
 
Your first d8 module
Your first d8 moduleYour first d8 module
Your first d8 module
 
Doing Drupal security right
Doing Drupal security rightDoing Drupal security right
Doing Drupal security right
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 

Último

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 FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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...DianaGray10
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
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, ...apidays
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
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 SavingEdi Saputra
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 

Último (20)

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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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, ...
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

Drupal Camp Porto - Developing with Drupal: First Steps

  • 1. Developing for Drupal: first steps, tips & tricks Drupal Camp Portugal 2012 Luís Carneiro http://drupal.org/user/780690 eltugis@gmail.com
  • 2. Resources • The example sandbox module – http://tinyurl.com/portocamp-module
  • 3. Agenda • First steps • Some basics of the Drupal API • Presentation of coding examples • Questions and Discussion
  • 4. Set your Developing Environment • Netbeans • Eclipse Look for: • Debugger integration • Aptana • Function list view • Komodo IDE • Jump to function • Source control integration • Coda • Ability to search across files • Ability to configure syntax style • Vim (follow coding standards) • …
  • 5. Debugger is your friend See how the information flows Track bugs and understand code
  • 6. Follow the coding standards • drupal.org/coding-standards • http://tinyurl.com/configuring-netbeans • Use the coder module to validate your code
  • 7. What is assumed You know the basic components of Drupal Content Blocks Taxonomies Users Types Modules Themes Fields
  • 8. Drupal Stack Drupal Theme Contributed Modules Custom Modules Drupal Core
  • 9. Drupal API family Module Theme Form API System System Schema Field API DB Layer API Menu Search … System API
  • 10. Hook concept • “Event listeners” • Possibility to act in certain points of a page execution – To add our custom functionalities – To alter other’s functionalities • Drupal Moto: Don’t hack Core or others code!
  • 11. Hooks hook_init hook_menu Drupal Core has hook_form_alter hook_theme about 250 hooks! See the full list: http://tinyurl.com/drupal-hooks hook_mail hook_field_info hook_schema …
  • 12. It all resumes to… module_invoke_all(‘hook_name’) or module_invoke(‘module_name’,’hook_name’)
  • 13. What you need for a module Files created in: sites/all/modules/custom/yourmodule yourmodule.info yourmodule.module yourmodule.install README.txt (optional) (good practice)
  • 14. .info File name = Your module name description = Line description about module purpose package = Group of modules it should belong core = 7.x (or other version of Drupal) files[] = yourmodule.module (and all other files which code should run of every page)
  • 15. Module Purpose • Create blocks • Create pages and forms • Create a new field type • Extend/customize Drupal core • Extend/customize Contributed modules • …
  • 16. Form API • drupal_get_form($form_id) – $form_id usually is <module_name>_<description>_form – Builds a form structure • Many form elements – textfield, select, checkbox, radio, password… – The full reference list http://tinyurl.com/drupal-form-api • validate and submit handlers – <form_id>_validate(&$form, &$form_state) – <form_id>_submit(&form, &$form_state)
  • 17. Cache in Drupal • Internal cache – Menu, Form, Path, Filter, Field… – Cache Page (specific for anonymous users) • The one you activate in “Performance” settings • Custom cache – Two simple functions: • cache_set($cid, $data, $bin, $expire) • cache_get($cid, $bin)
  • 18. Database Access Static Dynamic Queries queries • Usually simple queries • OOP query object • Only Select queries may • Database agnostic be static • Possibility to alter query elements db_query($sql_query) Full database API documentation http://drupal.org/developing/api/database
  • 19. Theme System Template File or Template Function Preprocessing Functions • Set the variables for the templates • Define the logic
  • 20. Theme Simple Example function theme_custom_output($variables) { function yourmodule_theme() { … return array( return $output; 'custom_output' => array( } 'variables' => array('node' => NULL), ), ); Function template_custom_output($variables) { } … return $output; } … print theme('custom_output', array('node' => function yourtheme_custom_output($variables) { … $node)); return $output; … } All valid theme definitions!
  • 21. Theming tips • Use devel themer module to find the theming elements on your page • Clear theme registry cache when setting new templates Useful Resources: http://tinyurl.com/drupal-theme-implementations http://tinyurl.com/render-arrays
  • 22. I see a lot of arrays! $page = array( '#show_messages' => TRUE, '#theme' => 'page', In many cases, the data used to '#type' => 'page', 'content' => array( build a page (and all parts of it) is 'system_main' => array(...), kept as structured arrays until the 'another_block' => array(...), '#sorted' => TRUE, rendering stage ), 'sidebar_first' => array( ... Enormous flexibility in changing ), 'footer' => array( the layout or content of a page ... and its components! ), ... );
  • 23. Use Drupal’s utility functions • Function l(): Formats an internal or external URL link as an HTML anchor tag. • Function t(): wrap text to be translated. • Function drupal_set_message(): status message for user performed operations • Function watchdog(): logs system messages to drupal log.
  • 24. Simplify with Drush • Command line tool to do common Drupal actions – Possibility to create your own drush commands…writing hooks! Clear caches $ drush Download/Enable modules $ drush help <command> Synchronize dev and production databases Check the log messages …
  • 25. Version Control Everything • Code + Configurations (in database) – Code, easy to version control – Configurations… there comes Features + Strongarm module! • Database configurations exported to code • Tip: Keep your features small
  • 26. Learning Resources • Web – http://api.drupal.org – http://drupal.org/project/examples – http://drupal.org/developing/api • Training – http://drupalize.me – http://buildamodule.com/ • Books – Drupal 7 Module Development – Pro Drupal 7 Development – Using Drupal 7

Notas do Editor

  1. Referirquemais a diantevãoserapresentadosexemplos da utilidade do Debugger.
  2. Apresentarmodule_invoke_all(&apos;init&apos;); no ficheiro “common.inc”
  3. Mostrar a form de administraçãocontruída.Mostrar a página da form apiAproveitarparafalar do “hook_menu” e “hook_permission”
  4. Aproveitarestetópicoparafalar no módulo “examples”.
  5. Apresentar a página de sandbox com uma query muito simples feita.Aproveitarparafalar do restante código.
  6. Exemplos: page, item_list, table, select list, etcEach theme can take control over most of Drupal&apos;s output, and has complete control over the CSS.Utilizar Debugger parafazer debug nafunção: “portocamp_theme_registry_alter” e mostrarosdiversoselementos de theme definidos.
  7. Mostrarexemplo do hook_themecriado.
  8. Show command line with drush and execute simple commands.