Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Dipping Your Toe into Drupal 8 Module Development

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Chargement dans…3
×

Consultez-les par la suite

1 sur 22 Publicité

Dipping Your Toe into Drupal 8 Module Development

Maybe you consider yourself a Drupal site builder or front-end developer. As soon as someone starts talking object-oriented PHP, you run for the hills. This makes the prospect of building a module for Drupal 8 scary. But on many projects, site building and theming can get you 95% of the way there, and you just need a tiny bit of code to get the job done.

In this session, I'll walk through a couple simple examples of code you can add to your project to fill in these types of gaps. We'll cover some really essential concepts and code snippets that will help you understand how to read Drupal 8 code and write that 'glue module' to get the website finished.

Maybe you consider yourself a Drupal site builder or front-end developer. As soon as someone starts talking object-oriented PHP, you run for the hills. This makes the prospect of building a module for Drupal 8 scary. But on many projects, site building and theming can get you 95% of the way there, and you just need a tiny bit of code to get the job done.

In this session, I'll walk through a couple simple examples of code you can add to your project to fill in these types of gaps. We'll cover some really essential concepts and code snippets that will help you understand how to read Drupal 8 code and write that 'glue module' to get the website finished.

Publicité
Publicité

Plus De Contenu Connexe

Diaporamas pour vous (20)

Similaire à Dipping Your Toe into Drupal 8 Module Development (20)

Publicité

Plus par Suzanne Dergacheva (20)

Plus récents (20)

Publicité

Dipping Your Toe into Drupal 8 Module Development

  1. 1. evolvingweb.ca @evolvingweb Dipping Your Toe into Drupal 8 Module Development WITH SUZANNE DERGACHEVA
  2. 2. • Co-founded Evolving Web in 2007 • Experienced Drupal themer, developer, project lead • Loves teaching DrupalSuzanne Dergacheva CO-FOUNDER AND FRONT-END LEAD
  3. 3. Creating great websites with Drupal TRAINING WEB DEVELOPMENT WEB CONSULTING
  4. 4. Some of our happy clients
  5. 5. Should I Create a Module? PROS • You get a flexible solution • Might be simpler than installing a complex module CONS • Takes time/skills to develop • You have to maintain the code • Can introduce bugs
  6. 6. Simple Module Examples • Change a form • Add a programmatic block • Add a programmatic page • Add a menu link • Create a field formatter • Add custom validation
  7. 7. Before You Start • Use the local.settings.php file and development.services.yml files (https://www.drupal.org/node/2598914) • Enables errors and warnings • Disables some caching • Disables aggregation of CSS/JS • Install the Devel module • Make sure your editor has syntax highlighting set up
  8. 8. Step 1: Research • Is there already a module that does this? • If not, is there something similar. Look for an example: • Drupal core • Contrib modules • Examples module • Try and find the code that does the thing you want • Figure out how it integrates with Drupal (usually a hook or a Class)
  9. 9. Step 2: Create the Scaffolding • Use the Drupal Console to write the scaffolding code or use examples from other modules to see what structure you need • Create a module folder, and an .info.yml file • Then, add a Class or hook to your module drupal generate:module drupal generate:controller
  10. 10. Step 3: Fill in the Custom Code • Write the logical part of your code that does the custom work • Look for exmaples of what you’re trying to do • You can copy and paste code snippets • … But make sure you read/understand each line of code!
  11. 11. Step 4: Testing • Easy to forget to test when you’re doing something simple • QA Tips: • Read error messages • Make sure you understand what you’re testing (what is supposed to change on the site) • Also test that your code doesn’t break other use cases. You might need to add an ‘if’ statement
  12. 12. Essential Terminology • Yml - File format used to define modules/theme, permissions, paths, menu items, and exported configuration • Class - Group of properties and methods that define an object. Used to extend parts of Drupal so you can create your own Forms, Blocks, Fields, Entities, Webform Elements, etc. • Plugin - Class that is ‘discoverable’ by Drupal. Examples: Blocks, Fields • Hook - Function that allows you to alter how something works in Drupal. Examples: altering forms, emails, adding things to cron
  13. 13. Let’s Build a Module
  14. 14. Real Example Module
  15. 15. Link to the Edit Account Page
  16. 16. Link to the Edit Account Page • Define a new path • The path points to a Controller • The controller redirects you to the path /user/[uid] but fills in the uid of the current User drupal generate:controller drupal generate:module
  17. 17. Changing a Form
  18. 18. Changing a Form • Find the form ID • Implement hook_form_alter • Add/remove/update elements of the form • Use this reference: https://api.drupal.org/api/drupal/elements/8.2.x drupal generate:form:alter drupal generate:module
  19. 19. Useful Code Snippets http://bit.ly/d8-snippets
  20. 20. Next Steps • Drupal Docs for Creating Custom Modules: https://www.drupal.org/ docs/8/creating-custom-modules • Try this tutorial: https://www.drupal.org/docs/8/creating-custom- modules/a-hello-world-custom-page-module • Download the Examples module: http://drupal.org/project/examples
  21. 21. Upcoming Drupal Trainings MAY 7-11, IN-PERSON
 Drupal 8 Training in Princeton NJ FEB 5-8, ONLINE
 Drupal 8 Module Development FEB 20-23, ONLINE
 Migrate to Drupal 8 MARCH 1-2, ONLINE
 Drupal 8 Site Building MARCH 12-15, ONLINE
 Drupal 8 Theming evolvingweb.ca/training training@evolvingweb.ca
  22. 22. @suzanne_kennedy evolvingweb.ca @evolvingweb Thank you!

×