SlideShare a Scribd company logo
Becoming A Drupal
Master Builder
Philip Norton
Blog at #! code (www.hashbangcode.com)
@philipnorton42 on Twitter
Technical Lead at
Philip Norton
Creator of Vlad Helps run NWDUG
==
https://www.flickr.com/photos/chrish_99/6730952349/
http://buytaert.net/album/birthday-axl-2011/dries-with-lego
My Experience
● 10+ years in programming
● 8+ years in the web industry
● 6+ years building Drupal sites
● 4+ years as Technical Lead at Access
● Development, system design, database and server
administration, consulting, SEO, usability, training,
mentoring
Other People’s Projects
● Reviewing projects built internally
● Migrating existing Drupal sites
● Third party sites that we need to host and maintain
● Rescue jobs
The good thing about
PHP, is it’s really easy
to learn.
The bad thing about
PHP, is it’s really easy
to learn
Ben Dechrai
Contents
● Drupal File Architecture
● Coding
● Configuration
● Contrib Modules
Drupal File Architecture
Drupal File Structure
● Custom/contrib for the modules directory
-- sites
---- all
------ modules
-------- contrib
-------- custom
● Easy to spot what the custom modules are
● Makes analysing custom code much easier
● Always use sites/default/files to store your
files, it will make life easier in the long run
Multi-site Setups
● Use DNS entries to auto-detect your file directory
sites/www.example.com/files
sites/www.example.com/modules
sites/www.example.com/settings.php
● Nice idea
● In practice it causes more problems than it solves
● This is used even when not needed
Themes
● Use the template.php file for theme overrides and
helper functions
● Do not use the template.php file to run database
commands
● Do not hardcode ID’s all over the place
● Use generic templates and stop template proliferation
● Drupal 8 forces you to stop using logic in your
templates and instead use preprocess hooks
Overly Specifying Specific Specifics
● More specific custom code means more stuff to break
if ($node->nid == 1234) {
}
● Node ID and Block ID specific templates
● Use of taxonomy term ID to control things
● If you have to use specifics then use configuration to
set these values
Drupal Module File Structure
● Lots of Drupal 7 hooks come with a file parameter
● Use it to move functionality into different files
● Namespace your module functions in Drupal 7
my_custom_module_some_function()
● Put all classes in their own files
● Use the X Autoload module to use PSR-4 in Drupal 7
● Drupal 8 Forces PSR-4! :)
http://www.jpstacey.info/blog/2015-06-22/architecting-drupal-7-module-multiple-files
Drupal Module Documentation
● Add documentation to your modules
● Write more than the basics in your info file
name = Tool Tips module
description = A module for tool tips
● Add a readme file and detail to the drupal.org module
page
● Also think about adding install and configure help
Drupal CHANGELOG.txt
● Don’t allow information leakage by including the
CHANGELOG.txt file in your Drupal install
● Restrict access via webserver configs
● Can also remove them from your codebase but the
Hacked! module will complain
● Alternatively, simply remove them as part of your
deployment process
Drupal Custom Code
● Don’t reinvent the wheel, use Drupal’s framework
● Use third party modules to provide functionality as
much as possible
● Use Drupal’s hooks to accomplish actions or change
existing functionality
Coding
Don’t Hack Core
● There are a million good reasons not to do this
● This includes contributed module and theme hacks
● Patching is ok as a last resort, BUT document your
changes!
● Do it the right way, learn about hooks, overrides and
child themes
https://www.drupal.org/best-practices/do-not-hack-core
Version Control
● Use version control
● Seriously, use it
● Git is good, so is Mercurial
● Commit often, use commit messages, describe your
changes
Version Control Branches
● Git branching is cheap
● Use git flow (or a variant)
● The master branch is a copy of the live site
● All work should be done on a development branch and
merged with master when ready for deployment
Version Control Etiquette
● Describe your work in commit messages
● Don’t add databases to your git repo
● Don’t include the user files directory in your git repo!
● settings.php file is debatable, just be careful of
adding usernames and passwords to your repos
● Use a local settings file
if (file_exists(__DIR__ . '/settings.local.php')) {
include __DIR__ . '/settings.local.php';
}
Use An IDE
● Syntax highlighting, code navigation, debugging,
autocomplete, auto formatting and more!
● Quickly spot unused variables
● Detect errors and problems before you commit the
code
Development Environment
● Try to replicate your production environment when
developing
● Stop silly errors creeping into the live site
● WAMP/MAMP solutions just don’t cut it
● Use Vagrant and a provisioning tool
● Vlad! :)
PHP Errors
● Syntax errors should never make it into production
● PHP Notices and Warnings are also NOT acceptable
in a production environment!
● Understand the internal Drupal error processing
(See _drupal_log_error() in Drupal 7)
● Don’t use @ to suppress warnings, it’s lazy and has
performance implications
● Use try {...} catch() {...} block to catch
exceptions
Coding Standards
● Pick a coding standard and stick to it
● Use the Code Sniffer tool, preferably with the Drupal
coding standards files
● Implement a continuous integration system to auto
check the code (e.g. Jenkins)
● Coder module (https://www.drupal.org/project/coder)
has everything you need
https://www.drupal.org/coding-standards
Cyclomatic Complexity
● The total number of paths of execution through a block
of code
if ($variable == TRUE) {
do_something();
}
else {
do_something_else();
}
● High numbers are bad (harder to read and maintain)
● Use PHPMD to inspect your own code and refactor
complexity
Cyclomatic Complexity = 2
Always code as if the
person who ends up
maintaining your code
is a violent psychopath
who knows where you
live.
John Woods
Drupal Tests
● Drupal has a test module bundled
● Drupal 7 uses Simpletest, Drupal 8 uses Simpletest
and PHPUnit
● Write tests!
● Test current functionality, re-run tests when refactoring
or adding new functionality
● Can take time to write tests, but it’s worth it in the long
run
Configuration
Drupal Content Types
● Content type != template type
Press Release
News Article
Front Page News Article
● A mistake that many site builders make
● Create functional content types, use data to control
them
CSS/JavaScript Aggregation
● Turn it on!
● Reduce the size of your files and the number of files
downloaded
● Reduces server load and decreases page load speed
● Try it before you deploy live, some CSS/JavaScript
code can be broken by this
● Spot problems before they appear in live
environments
Fieldsets And Vertical Tabs
● 40+ fields on your content types makes a long edit
page
● Use vertical tabs and fieldsets to break the page up
● Field Group module has this functionality
● Try to avoid using “Unlimited” cardinality on fields
especially on file fields
● Think about how your users will edit pages
Permissions
● General rule is to restrict user permissions to the core
activities they will be doing
● Giving users too much access can be confusing,
especially for new Drupal users
● Also don’t allow lots of ‘superuser’ roles as it becomes
difficult to restrict access
PHP Filter
● The PHP Filter module is bad, never use it
● Execution of PHP is slow and uncachable
● Quickly creates an unmaintainable mess
● Lots of security implications
● Removed from Drupal 8 (with much fanfare!)
Running Cron
● Don't get your users to run cron, put it in crontab
● Use the Elysia Cron module to process cron tasks at
different times
● Can see a massive (90%+) reduction in the cron
footprint
https://www.drupal.org/project/elysia_cron
Updates
● Some modules use update hooks to run actions,
usually to add or update database tables
● It is essential that you run update.php when you
deploy an update to a module
● Using ‘drush updatedb’ also works well here
Uninstall Deactivated Modules
● Uninstalling modules is important as they leave behind
tables and data that isn’t used
● Turn off and uninstall modules before deleting them
Contrib Modules
Views, Views, Views
● Use Views to show lists of content
● Built into Drupal 8
● Don’t duplicate a View to display the same thing on
different pages
● Use contextual filters to alter the same View in
different contexts
● Remember to add pagination and limits
Pathauto
● Seeing node/123 on production websites makes me
cringe
● Use Pathauto to create pretty paths from node data
● Creates SEO friendly paths
https://www.drupal.org/project/pathauto
Context
● React to certain page level conditions
- Paths
- Views
- Content Types
- Menu Items
- Taxonomy Terms
● Much better and more controlled block placement in
Drupal 7
● Fully exportable so placement can be kept in config
https://www.drupal.org/project/context
Advanced Aggregation
● Compress your CSS and JS even more
● GZips your code for smaller size when transporting
https://www.drupal.org/project/advagg
UI Modules
● Many modules come with a user interface (UI) sub
module that wrap the administration interface
- Views UI
- Context UI
- Rules UI
- Display Suite UI
etc...
● Turn them off in production
Devel
● Really powerful module
● Makes development easy in Drupal
● Awesome sub modules like Devel Generate and Devel
Node Access
● Who doesn’t love Devel?
● Don’t, don’t, DON’T leave it running it production!
● Also, DON’T commit dpm() into your code!
Stage File Proxy
● Really good module for using uploaded files on a dev
platform without having to download the user files
directory from production
● No need deploy to production
https://www.drupal.org/project/stage_file_proxy
Features
● Features allows modules to be made that create
Content Types, Fields, Views, Contexts, Rules, and
many more types of configuration
● Allows you to see when things have changed and
allows easy deployment of new functionality
● Try to add as much configuration into code as possible
● Group like items together
https://www.drupal.org/project/features
Spotting Problems
opensource.com
● JavaScript aggregation is
turned off (but not CSS?)
● Messy module directory
structure (due to Panopoly
distribution)
Cisco Internet Of Everything
● Runs Drupal 7.24 (as seen
from CHANGELOG.txt)
● Vulnerable to SA-CORE-
2014-005?
belgium.be
● Lots of stuff done right
● CSS and JavaScript
aggregation turned off
Greater Than Games
● Runs Drupal 7.41, as seen in
CHANGELOG.txt
● Multi-site setup
Elite Dangerous Community Site
● CSS/JavaScript aggregation
is turned off
● Some use of Path Auto so
URL’s like ‘node/123’ are
common
● Multi-site setup
● Hacked the Bootstrap theme
to make a sub-theme
● Call me! :)
Top Tips
Some things to take away with you
Top Tips
● Have a go live plan
● Think about the experience of all of your users
● Don’t overcomplicate simple functionality
● Don’t use specific templates, generalise
● Think about the long term life of the site
● Learn the system (i.e. Drupal)
Becoming A Drupal Master Builder

More Related Content

PDF
Drupal 8 Services And Dependency Injection
PDF
Getting Into Drupal 8 Configuration
PDF
Drupal 8 Services
PDF
Drupal 8 Configuration Management
PPTX
WordPress Plugin development
PDF
Drupal 8 Configuration Management with Features
KEY
Automating Drupal Development: Makefiles, features and beyond
PDF
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
Drupal 8 Services And Dependency Injection
Getting Into Drupal 8 Configuration
Drupal 8 Services
Drupal 8 Configuration Management
WordPress Plugin development
Drupal 8 Configuration Management with Features
Automating Drupal Development: Makefiles, features and beyond
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)

What's hot (19)

PDF
Drupal 8 - Corso frontend development
PPTX
Django Architecture Introduction
PDF
Configuration Management in Drupal 8: A preview (DrupalCamp Alpe Adria 2014)
PPT
Drupal Javascript for developers
PDF
Building a Dynamic Website Using Django
PPTX
Making Magento flying like a rocket! (A set of valuable tips for developers)
PPTX
Migrate yourself. code -> module -> mind
PPT
jQuery and_drupal
PPT
Multi Tenancy With Python and Django
PPT
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
PPTX
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
PPTX
Drupal 8 deploying
PPTX
PDF
Web applications with Catalyst
PPT
Render API - Pavel Makhrinsky
PPTX
The Django Web Application Framework 2
PPTX
Zend framework
PDF
Drupal 8 CMI on a Managed Workflow
Drupal 8 - Corso frontend development
Django Architecture Introduction
Configuration Management in Drupal 8: A preview (DrupalCamp Alpe Adria 2014)
Drupal Javascript for developers
Building a Dynamic Website Using Django
Making Magento flying like a rocket! (A set of valuable tips for developers)
Migrate yourself. code -> module -> mind
jQuery and_drupal
Multi Tenancy With Python and Django
Phase2 OpenPublish Presentation SF SemWeb Meetup, April 28, 2009
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
Drupal 8 deploying
Web applications with Catalyst
Render API - Pavel Makhrinsky
The Django Web Application Framework 2
Zend framework
Drupal 8 CMI on a Managed Workflow
Ad

Similar to Becoming A Drupal Master Builder (20)

PDF
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
PDF
Drupal Best Practices
ODP
Drupal in 5mins + Previewing Drupal 8.x
PDF
Drupal + composer = new love !?
PDF
Choosing Drupal as your Content Management Framework
PDF
Modernize Your Drupal Development
ODP
Hong Kong Drupal User Group - 2014 March 8th
PDF
Drupal 8 improvements for developer productivity php symfony and more
ODP
Moodle Development Best Pracitces
PDF
Drupal 8 - Core and API Changes
ODP
Drupal Architecture and functionality
PDF
Drupal in-depth
PDF
Open Innovation Lab (OIL) - 2014 Sep 26th
PDF
[HKDUG] #20180512 - Fix Hacked Drupal with GIT
PPTX
Top 20 mistakes you will make on your 1st Drupal project
PDF
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
PPT
Drupal training-1-in-mumbai
PDF
Efficient development workflows with composer
PDF
Implementing a Symfony Based CMS in a Publishing Company
PDF
Drupal and contribution (2010 - 2011 / 2)
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Drupal Best Practices
Drupal in 5mins + Previewing Drupal 8.x
Drupal + composer = new love !?
Choosing Drupal as your Content Management Framework
Modernize Your Drupal Development
Hong Kong Drupal User Group - 2014 March 8th
Drupal 8 improvements for developer productivity php symfony and more
Moodle Development Best Pracitces
Drupal 8 - Core and API Changes
Drupal Architecture and functionality
Drupal in-depth
Open Innovation Lab (OIL) - 2014 Sep 26th
[HKDUG] #20180512 - Fix Hacked Drupal with GIT
Top 20 mistakes you will make on your 1st Drupal project
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Drupal training-1-in-mumbai
Efficient development workflows with composer
Implementing a Symfony Based CMS in a Publishing Company
Drupal and contribution (2010 - 2011 / 2)
Ad

More from Philip Norton (9)

PDF
ReactPHP
PDF
Webform and Drupal 8
PDF
Acquia Drupal Certification
PDF
Drupal Performance : DrupalCamp North
PPT
Getting Started With Jenkins And Drupal
PDF
Drupal theming
PDF
ODP
Making The Drupal Pill Easier To Swallow
ODP
Drupal 7 Queues
ReactPHP
Webform and Drupal 8
Acquia Drupal Certification
Drupal Performance : DrupalCamp North
Getting Started With Jenkins And Drupal
Drupal theming
Making The Drupal Pill Easier To Swallow
Drupal 7 Queues

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Electronic commerce courselecture one. Pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
Cloud computing and distributed systems.
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing
The AUB Centre for AI in Media Proposal.docx
Electronic commerce courselecture one. Pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Modernizing your data center with Dell and AMD
Cloud computing and distributed systems.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cuic standard and advanced reporting.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Becoming A Drupal Master Builder

  • 1. Becoming A Drupal Master Builder Philip Norton
  • 2. Blog at #! code (www.hashbangcode.com) @philipnorton42 on Twitter Technical Lead at Philip Norton Creator of Vlad Helps run NWDUG
  • 3. ==
  • 6. My Experience ● 10+ years in programming ● 8+ years in the web industry ● 6+ years building Drupal sites ● 4+ years as Technical Lead at Access ● Development, system design, database and server administration, consulting, SEO, usability, training, mentoring
  • 7. Other People’s Projects ● Reviewing projects built internally ● Migrating existing Drupal sites ● Third party sites that we need to host and maintain ● Rescue jobs
  • 8. The good thing about PHP, is it’s really easy to learn. The bad thing about PHP, is it’s really easy to learn Ben Dechrai
  • 9. Contents ● Drupal File Architecture ● Coding ● Configuration ● Contrib Modules
  • 11. Drupal File Structure ● Custom/contrib for the modules directory -- sites ---- all ------ modules -------- contrib -------- custom ● Easy to spot what the custom modules are ● Makes analysing custom code much easier ● Always use sites/default/files to store your files, it will make life easier in the long run
  • 12. Multi-site Setups ● Use DNS entries to auto-detect your file directory sites/www.example.com/files sites/www.example.com/modules sites/www.example.com/settings.php ● Nice idea ● In practice it causes more problems than it solves ● This is used even when not needed
  • 13. Themes ● Use the template.php file for theme overrides and helper functions ● Do not use the template.php file to run database commands ● Do not hardcode ID’s all over the place ● Use generic templates and stop template proliferation ● Drupal 8 forces you to stop using logic in your templates and instead use preprocess hooks
  • 14. Overly Specifying Specific Specifics ● More specific custom code means more stuff to break if ($node->nid == 1234) { } ● Node ID and Block ID specific templates ● Use of taxonomy term ID to control things ● If you have to use specifics then use configuration to set these values
  • 15. Drupal Module File Structure ● Lots of Drupal 7 hooks come with a file parameter ● Use it to move functionality into different files ● Namespace your module functions in Drupal 7 my_custom_module_some_function() ● Put all classes in their own files ● Use the X Autoload module to use PSR-4 in Drupal 7 ● Drupal 8 Forces PSR-4! :) http://www.jpstacey.info/blog/2015-06-22/architecting-drupal-7-module-multiple-files
  • 16. Drupal Module Documentation ● Add documentation to your modules ● Write more than the basics in your info file name = Tool Tips module description = A module for tool tips ● Add a readme file and detail to the drupal.org module page ● Also think about adding install and configure help
  • 17. Drupal CHANGELOG.txt ● Don’t allow information leakage by including the CHANGELOG.txt file in your Drupal install ● Restrict access via webserver configs ● Can also remove them from your codebase but the Hacked! module will complain ● Alternatively, simply remove them as part of your deployment process
  • 18. Drupal Custom Code ● Don’t reinvent the wheel, use Drupal’s framework ● Use third party modules to provide functionality as much as possible ● Use Drupal’s hooks to accomplish actions or change existing functionality
  • 20. Don’t Hack Core ● There are a million good reasons not to do this ● This includes contributed module and theme hacks ● Patching is ok as a last resort, BUT document your changes! ● Do it the right way, learn about hooks, overrides and child themes https://www.drupal.org/best-practices/do-not-hack-core
  • 21. Version Control ● Use version control ● Seriously, use it ● Git is good, so is Mercurial ● Commit often, use commit messages, describe your changes
  • 22. Version Control Branches ● Git branching is cheap ● Use git flow (or a variant) ● The master branch is a copy of the live site ● All work should be done on a development branch and merged with master when ready for deployment
  • 23. Version Control Etiquette ● Describe your work in commit messages ● Don’t add databases to your git repo ● Don’t include the user files directory in your git repo! ● settings.php file is debatable, just be careful of adding usernames and passwords to your repos ● Use a local settings file if (file_exists(__DIR__ . '/settings.local.php')) { include __DIR__ . '/settings.local.php'; }
  • 24. Use An IDE ● Syntax highlighting, code navigation, debugging, autocomplete, auto formatting and more! ● Quickly spot unused variables ● Detect errors and problems before you commit the code
  • 25. Development Environment ● Try to replicate your production environment when developing ● Stop silly errors creeping into the live site ● WAMP/MAMP solutions just don’t cut it ● Use Vagrant and a provisioning tool ● Vlad! :)
  • 26. PHP Errors ● Syntax errors should never make it into production ● PHP Notices and Warnings are also NOT acceptable in a production environment! ● Understand the internal Drupal error processing (See _drupal_log_error() in Drupal 7) ● Don’t use @ to suppress warnings, it’s lazy and has performance implications ● Use try {...} catch() {...} block to catch exceptions
  • 27. Coding Standards ● Pick a coding standard and stick to it ● Use the Code Sniffer tool, preferably with the Drupal coding standards files ● Implement a continuous integration system to auto check the code (e.g. Jenkins) ● Coder module (https://www.drupal.org/project/coder) has everything you need https://www.drupal.org/coding-standards
  • 28. Cyclomatic Complexity ● The total number of paths of execution through a block of code if ($variable == TRUE) { do_something(); } else { do_something_else(); } ● High numbers are bad (harder to read and maintain) ● Use PHPMD to inspect your own code and refactor complexity Cyclomatic Complexity = 2
  • 29. Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live. John Woods
  • 30. Drupal Tests ● Drupal has a test module bundled ● Drupal 7 uses Simpletest, Drupal 8 uses Simpletest and PHPUnit ● Write tests! ● Test current functionality, re-run tests when refactoring or adding new functionality ● Can take time to write tests, but it’s worth it in the long run
  • 32. Drupal Content Types ● Content type != template type Press Release News Article Front Page News Article ● A mistake that many site builders make ● Create functional content types, use data to control them
  • 33. CSS/JavaScript Aggregation ● Turn it on! ● Reduce the size of your files and the number of files downloaded ● Reduces server load and decreases page load speed ● Try it before you deploy live, some CSS/JavaScript code can be broken by this ● Spot problems before they appear in live environments
  • 34. Fieldsets And Vertical Tabs ● 40+ fields on your content types makes a long edit page ● Use vertical tabs and fieldsets to break the page up ● Field Group module has this functionality ● Try to avoid using “Unlimited” cardinality on fields especially on file fields ● Think about how your users will edit pages
  • 35. Permissions ● General rule is to restrict user permissions to the core activities they will be doing ● Giving users too much access can be confusing, especially for new Drupal users ● Also don’t allow lots of ‘superuser’ roles as it becomes difficult to restrict access
  • 36. PHP Filter ● The PHP Filter module is bad, never use it ● Execution of PHP is slow and uncachable ● Quickly creates an unmaintainable mess ● Lots of security implications ● Removed from Drupal 8 (with much fanfare!)
  • 37. Running Cron ● Don't get your users to run cron, put it in crontab ● Use the Elysia Cron module to process cron tasks at different times ● Can see a massive (90%+) reduction in the cron footprint https://www.drupal.org/project/elysia_cron
  • 38. Updates ● Some modules use update hooks to run actions, usually to add or update database tables ● It is essential that you run update.php when you deploy an update to a module ● Using ‘drush updatedb’ also works well here
  • 39. Uninstall Deactivated Modules ● Uninstalling modules is important as they leave behind tables and data that isn’t used ● Turn off and uninstall modules before deleting them
  • 41. Views, Views, Views ● Use Views to show lists of content ● Built into Drupal 8 ● Don’t duplicate a View to display the same thing on different pages ● Use contextual filters to alter the same View in different contexts ● Remember to add pagination and limits
  • 42. Pathauto ● Seeing node/123 on production websites makes me cringe ● Use Pathauto to create pretty paths from node data ● Creates SEO friendly paths https://www.drupal.org/project/pathauto
  • 43. Context ● React to certain page level conditions - Paths - Views - Content Types - Menu Items - Taxonomy Terms ● Much better and more controlled block placement in Drupal 7 ● Fully exportable so placement can be kept in config https://www.drupal.org/project/context
  • 44. Advanced Aggregation ● Compress your CSS and JS even more ● GZips your code for smaller size when transporting https://www.drupal.org/project/advagg
  • 45. UI Modules ● Many modules come with a user interface (UI) sub module that wrap the administration interface - Views UI - Context UI - Rules UI - Display Suite UI etc... ● Turn them off in production
  • 46. Devel ● Really powerful module ● Makes development easy in Drupal ● Awesome sub modules like Devel Generate and Devel Node Access ● Who doesn’t love Devel? ● Don’t, don’t, DON’T leave it running it production! ● Also, DON’T commit dpm() into your code!
  • 47. Stage File Proxy ● Really good module for using uploaded files on a dev platform without having to download the user files directory from production ● No need deploy to production https://www.drupal.org/project/stage_file_proxy
  • 48. Features ● Features allows modules to be made that create Content Types, Fields, Views, Contexts, Rules, and many more types of configuration ● Allows you to see when things have changed and allows easy deployment of new functionality ● Try to add as much configuration into code as possible ● Group like items together https://www.drupal.org/project/features
  • 50. opensource.com ● JavaScript aggregation is turned off (but not CSS?) ● Messy module directory structure (due to Panopoly distribution)
  • 51. Cisco Internet Of Everything ● Runs Drupal 7.24 (as seen from CHANGELOG.txt) ● Vulnerable to SA-CORE- 2014-005?
  • 52. belgium.be ● Lots of stuff done right ● CSS and JavaScript aggregation turned off
  • 53. Greater Than Games ● Runs Drupal 7.41, as seen in CHANGELOG.txt ● Multi-site setup
  • 54. Elite Dangerous Community Site ● CSS/JavaScript aggregation is turned off ● Some use of Path Auto so URL’s like ‘node/123’ are common ● Multi-site setup ● Hacked the Bootstrap theme to make a sub-theme ● Call me! :)
  • 55. Top Tips Some things to take away with you
  • 56. Top Tips ● Have a go live plan ● Think about the experience of all of your users ● Don’t overcomplicate simple functionality ● Don’t use specific templates, generalise ● Think about the long term life of the site ● Learn the system (i.e. Drupal)

Editor's Notes

  • #6: Who am I to tell you what to be doing with your Drupal sites?
  • #8: This is a talk born from frustration frustration of sites being so broken that they just need throwing away and starting again frustration of drupal being hacked to make it work like an amature So what is the problem? Stems from the ability of people to build Drupal sites with little or no knowledge. Drupal is a tool like any other, and there is a right way and a wrong way. In the PHP world there is this saying...
  • #9: Drupal is a great tool, it’s quite easy to get up and running quickly But it’s really easy to build a Drupal site that is an unmaintainable mess Drupal: The Right Way?
  • #13: Main problem is when doing updates. Split the module from one site into another, which site is running what module.
  • #14: Think of MVC, but in this case it’s Entity, Theme, Menu hook? Model is the Entity View is the Theme Controller is the menu_hook Drupal 8 and Twig
  • #15: what happens when things change? what happens when you move from dev to production, will be IDs be the same?
  • #16: file parameter is in menu, theme, as the most notable examples, and a few other things It’s not just about how Drupal it put together, but also about the file structure within a module
  • #17: often come across custom modules that have no explanation of what they are doing, even in comments in the code don’t rely on the code being the documentation
  • #19: understand how Drupal is put together and understand how it can be overridden seen examples of: - random scripts being placed next to drupal that aren’t in modules or things like that - the book module being rebuilt - cache modules being created from scratch - Solr modules being built from scratch - API integration modules being rebuilt from scratch “re-invent the wheel, often” but own your own time!
  • #20: Some tips on getting the most out of your coding
  • #21: I still see this quite a lot
  • #22: commit messages must be present should also contain an indication of what changed and why it was changed
  • #23: git flow is also a good mechanism to control git branching
  • #24: settings.php file can be used to store certain module configuration options so it can be added to the repo in which case the local override block should be added this local settings technique is part of Drupal 8 core now
  • #25: notepad isn’t enough notepad++ is better, still not enough in my opinion Notable examples are Netbeans, Eclipse or PHPStorm Might be regarded as bloat-ware by some, but code navigation, debugging and autocomplete are essential for my sanity
  • #26: Linux vs Windows for development and production versions of software might cause problems, so installing the same version of X on both systems helps iron out issues in the future also think about PHP settings and real world data, will your site be able to cope?
  • #27: don’t forget about the error logs in Drupal make sure to set the error message printing to an appropriate level
  • #28: mainly simple things like: - the number of spaces in code -
  • #29: Cyclomatic complexity is a good heuristic of the complexity of the code this figure can be set anything above 10 is going to be hard to figure out! PHPMD will also point out where potential code problems might occurr unused variables in code variable names being too long or too short excessive function lengths Think about the next person who will look at the code. when writing complex code there is something you should understand...
  • #30: this also applies to yourself
  • #33: modules like display suite provide a nice approach to templates
  • #35: An example of a complex node would be An Event A gallery A news item with multiple control fields (e.g. for permissions) However, a few things to watch out for Don’t include 50+ images into a single node If you have to edit the php.ini to use 200MB+ uploads then you are doing it wrong
  • #36: drupal has poor logging built in, so seeing who altered some item of content can be hard avoid audit knightmare by restricting your users
  • #37: what happens when you have a View with some PHP filter stuff in it? Or a Node with some PHP filter code as the content? Where is the code being executed from? what about hooks?
  • #38: the graph shows the time taken to execute the cron before and after
  • #39: this can often lead to problems where a module expects certain parameters/ fields or whatever to be in place, which aren’t, errors are caused as a result
  • #42: Don’t add a new View for every page that it should appear on creates an administration headache Remember about Views caching, but be fully aware of what it does cached for everybody means that content generated by one user will be seen by all users so if you have any user specific stuff it will be seen by all users Views is powerful, but remember that there is a right and a wrong way to override views. the wrong way can easily cause errors and security holes
  • #44: and lots more!
  • #45: further reduces the footprint of your site
  • #46: saves CPU cycles
  • #47: It slows down your sites with: - profiling code - inspection code At Access we automatically detect for the presence of dpm() calls and fail the build if any are found
  • #49: for example, with a new feature you would have the content type extra fields vocabularies views
  • #50: this isn’t about pointing out problems with other sites, it’s about being easily able to see problems just from inspecting the front end code i’ll show that the problems i have gone over here can be easily seen in live sites i’m not making this stuff up!
  • #53: In reality, most of the big Drupal sites do a lot of stuff right and finding sites that are really broken is often rare
  • #54: misses out the latest securty patches
  • #55: I want to go on record by saying that I freaking love Elite dangerous this site is fucking atrocious! I dread to think what is going on inside i wonder if the code is as bad? if anyone knows who is in charge then get them to give me a ring