Folie 1 - DrupalCon Munich 2012
Download
Report
Transcript Folie 1 - DrupalCon Munich 2012
Drupal 7 as an enterprise web
application framework
Why as a developer you should use
Drupal to build web applications?
Klaus Harris
DrupalCon Munich 2012
Brief bio
• Who am I?
• What‘s my Drupal story?
Why this talk?
1. Address some preconceptions that developers
have about Drupal
2. Why should I as a developer use Drupal 7
Part 1
Preconceptions
Developer preconceptions
1.
2.
3.
4.
5.
6.
7.
8.
9.
Drupal is just a CMS
Drupal isn’t suitable for large enterprise sites
It’s old fashioned procedural code
I’ll have to learn some hideous plugin architecture
I’ll have to fit around the Drupal data model
What I can do is limited (it’s just a CMS)
Theming is difficult
Drupal is slow
I can write something like this but better
1. Drupal is just a CMS
We see a lot of comparisons like this:
Drupal vs Joomla vs WordPress
Open Source CMS Comparison
CMS Comparison: Drupal, Joomla and Wordpress
by Ashleigh Davis on 27 March 2011 | 6 Comments
CMS-Battle: TYPO3 vs Drupal
fight over 20 rounds
But not this:
Drupal vs Symfony
Drupal vs
Zend Framework
And according to Wikipedia a web framework has:
•
•
•
•
•
•
•
Web template system
Caching
Security
Database access, mapping and configuration
Url mapping
Ajax
Web services
http://en.wikipedia.org/wiki/Web_application_framework
So why is Drupal is only seen as a CMS?
• Drupal‘s origins
• Comparisons with Joomla, Wordpress and Typo3
• No comparisons with PHP frameworks like Zend
• Installable software on some hosters
• Very node centric data structure in < Drupal 7
• Admin interface (horror!)
• All those modules, it must be a CMS
• Ignorance
Drupal 6 was less flexible
There was only really
one content data
type built in, namely
the node.
Nodes could be subtyped and had only
basic view modes.
Full
Teaser
node
type
type
type
A page is a
node for
example.
type
And that data lived in two tables
Node
Node revisions
Drupal 7 changes all this!
Entity API, make:
• your own data table(s)
• different view modes
• sub-types
• fields
AND
you get all the goodneess
you know from node API
So now..
Entity
node
type
Full
RSS
user
type
Teaser
comment
type
Top 5
custom
type
Full
type
Teaser
RSS
and…
We aren‘t tied to the Drupal database
We can can override
the data operation
methods.
meaning…
Entity
node
type
type
Drupal
DB
custom
custom
type
type
Another
DB
type
Web
service
Our data can come from anywhere…
Entities are new in Drupal 7
• Add fields
• Control displayed fields depending on view mode
• Get the data into search and define which fields to
index
• Use our own view modes
• Add custom sub-types
• Be data source agnostic
• Use all the hooks you are used to from nodes
BUT!
You aren‘t tied to entities.
If you want, just write your own CRUD code.
What else makes Drupal more web framework?
•
•
•
•
•
•
•
•
•
•
URL routing / menu
Actions and triggers
Queue mechanism
Database API
Caching
Form API
Theme system
File API
Roles and permissions
and more..
• Internationalistion
• Web services
• Testing framework
Contrib gold such as..
• Views
• Flag
• Rules
• Search API
We use actions and triggers extensively
Great for
decoupling
2. Drupal isn’t suitable for large enterprise sites
Wrong!
Look at big sites using it and explore case studies.
Look at the architecture.
• http://www.examiner.com/
• http://www.acquia.com/resources/case-study/examinercom
• http://www.govtech.com/policy-management/Why-Big-Sites-RunDrupal.html?page=1
• http://buytaert.net/tag/drupal-sites
3. It’s old fashioned procedural code
„It‘s not all OOP“
True. Is that bad? *
„It has global variables“
True, live with it.
„There are so many arrays“
So what? It‘s PHP.
* http://drupal.org/node/547518
4. I’ll have to learn some hideous plugin architecture
Wrong!
You will find it:
Yes!
• Well architected
• Simple
• Powerful
• Intuitive
You will need to learn
about hooks, overrides
and preprocessing but..
It is easy, you will like it
For example, making a module:
Menu hook
and
page callback
Enable the new module.
Simple!
Let‘s make a block
Simple!
Form API is gold
As a developer you will
write a LOT of form code
You should use a Form API
that you like.
5. I’ll have to fit around the Drupal data model
Wrong!
Think of Drupal as a web framework with some default
data structures set up for you.
• Create data structures via Entities
• Just make DB tables and write your own CRUD code
• Get data from entirely different DBs
• Get data from web services
Power to you!
6. What I can do is limited (it’s just a CMS)
Wrong!
Anything you can build with:
• Zend Framework
• Symfony
• and so on
you can build with Drupal. With reduced development
time!
Don‘t forget! You can use Zend Framework
components in Drupal too!
This search uses Zend Framework Lucene libraries.
7. Theming is difficult
No it‘s not.
• Themer - http://drupal.org/project/devel_themer
• Devel - http://drupal.org/project/devel
• Examples - http://drupal.org/project/examples
Try simple starter theme
• Zen theme - http://drupal.org/project/zen
• Basic theme - http://drupal.org/project/basic
Theming
is easy
Renderable arrays, theming is even easier.
Devel Themer module
8. I can write something like this but better
Really?
9. Drupal is slow
• Full page caching
• Partial page caching e.g. blocks
• Static caching with function calls
• More efficient Entity loading
• Javascript aggregation
• CSS aggregation
• Master / Slave database configurations
• Different caching backends e.g. memcache
Drupal performance greatly benefits from:
• An opcode cache like APC
• Memcache
Check out the Drupal performance group:
http://groups.drupal.org/high-performance
and some performance related modules such as:
• http://drupal.org/project/memcache
• http://drupal.org/project/mongodb
• http://drupal.org/project/varnish
Worth looking here..
on any module page.
Part 2
Why should I as a developer use
Drupal 7?
1. What is good about coding Drupal 7?
2. What should I be aware of?
3. What mindset change do I need?
4. Where do I go from here?
1. What is good about coding Drupal 7?
•
•
•
•
•
•
•
•
It is amazing what you can build just with modules
Rapid results
Fully featured
Code organisation
Community and resources
There‘s a module for that
Really nice APIs
Developer tools
2. What should I be aware of?
Shock!!
Zend Framework
Drupal
Organising code
Up to you
Configuration
And..
Works the same
Deployment can be easier and trickier
Easier through hooks and install pofiles.
Trickier with configuration in the DB. Explore
Features module.
Flush the theme registry after theme changes
Flush the menu registry after menu changes
3. What mindset change do I need?
• You will combine modules AND custom code.
• Don‘t look for MVC, it‘s more PAC *
• Don‘t look for a Zend / Symfony file structure
• Understand OO principles in the API ** and see past
the procedural code.
• Embrace the Drupal way
*
http://www.garfieldtech.com/blog/mvc-vs-pac
http://www.dossier-andreas.net/software_architecture/pac.html
** http://drupal.org/node/547518
4. Where do I go from here?
Explore
Experiment
• Drupal.org
• Buy a book
• Who uses Drupal?
• Install Drupal
• Try some cookbook site
builds
Experiment with programming
• devel, drush, schema, devel_themer modules
• Explore the examples module
• Write a module
Where could you use Drupal to get started?
• Personal site
• An intranet tool e.g. wiki / bug tracker / CRM
• New business project
• Part of a business presence
• Or a hybrid form
The trick is to gain experience.
I started with Drupal via a hybrid model..
Internet
Intranet
Drupal
An established B2C
website News, help
& FAQ
Views
Main
Main
DB
DBs
Drupal
DB
Multi-lingual content for news,
help and FAQs built in Drupal.
I liked Drupal so much we built on it for a startup
It was a good decision
and is fun!
Thank you for listening
Klaus Harris
[email protected]
www.distribly.com
Appendix
Some good books
Drupal 6
Using Drupal - First edition 1, O'Reilly Press
Pro Drupal 6 Development - Second Edition Apress
Drupal 7
Drupal 7 Module Development - Packt
Pro Drupal 7 Development, Apress
The Definitive Guide to Drupal 7 - Apress
Some links
http://drupal.org
Developer modules
http://drupal.org/project/admin_menu
http://drupal.org/project/devel
http://drupal.org/project/devel_themer
http://drupal.org/project/schema
http://drupal.org/project/drush
http://drupal.org/project/examples
Recommended starter themes
http://drupal.org/project/basic
http://drupal.org/project/zen
MVC vs PAC
http://www.garfieldtech.com/blog/mvc-vs-pac
http://www.dossier-andreas.net/software_architecture/pac.html
Drupal and OOP
http://drupal.org/node/547518