drupal development tips

34
Drupal Development Tips May 16th, 2013 php|tek 2013 1 E-mail: [email protected] Twitter: @dragonmanta App.net: @ctankersl https://joind.in/8153

Upload: chris-tankersley

Post on 26-May-2015

490 views

Category:

Technology


0 download

DESCRIPTION

Overview of various tools to help Drupal developers build and develop modules.

TRANSCRIPT

Page 1: Drupal Development Tips

Drupal Development Tips

May 16th, 2013 php|tek 2013 1

E-mail: [email protected]: @dragonmantank

App.net: @ctankersleyhttps://joind.in/8153

Page 2: Drupal Development Tips

php|tek 2013

Who Are You and Why Are You In My House At My Conference

Chris Tankersley Doing PHP for 9 Years Lots of projects no one uses, and a

few that some do TL;DR

https://github.com/dragonmantank

Heavy Drupal Development for 2 years

May 16th, 2013 2

Page 3: Drupal Development Tips

Tip #1

Don’t use Drupal

May 16th, 2013 php|tek 2013 3

Page 4: Drupal Development Tips

Tip #1

Don’t abuse Drupal

May 16th, 2013 php|tek 2013 4

Page 5: Drupal Development Tips

Development StacksWhat powers your site

May 16th, 2013 php|tek 2013 5

Page 6: Drupal Development Tips

php|tek 2013

Acquia Dev Desktop – What is it?

Pre-built *AMP Stack Available for Drupal 6 or 7 Install and Ready to Go

May 16th, 2013 6

Advantages

Disadvantages Not built for multiple installs Can’t use for existing sites Only for Windows and Mac

Page 7: Drupal Development Tips

php|tek 2013

Acquia Dev Desktop – When to Use?

Best to use for module or theme development

I don’t like it for full site development

May 16th, 2013 7

Page 8: Drupal Development Tips

php|tek 2013

Acquia Dev Desktop - Tips

Make use of the “Sites” option to help separate work

On Mac, only the /sites/all/ folder is writable Even Sites you create are not writable

Don’t put the entire stack in VC, just your work

May 16th, 2013 8

Page 9: Drupal Development Tips

php|tek 2013

vagrant – What is it?

May 16th, 2013 9

Full server to run code Self contained and can be replicated Most modern machines can do VM

Advantages

Disadvantages Uses more resources Easier to break

Page 10: Drupal Development Tips

php|tek 2013

vagrant – When to Use?

Best to use for full site development Or use it all the time, it’s nice to

have an environment you control

May 16th, 2013 10

Page 11: Drupal Development Tips

php|tek 2013

vagrant - Tips

Try and pick a distro that is close to your production setup. If you are running Redhat in production, set up an CentOS box

Set up the document root for your web server to be the /vagrant folder (or sub folder, depending on your site layout). This way your site will run automatically.

If you are running CentOS and Apache, disable SELinux so that Apache will use the /vagrant folder

Don't use PHP 5.4 with Drupal 7 or lower Make sure APC, or some opcode cache, is installed Provide lots of RAM, at least 1GB

May 16th, 2013 11

Page 12: Drupal Development Tips

php|tek 2013

Local Stack

Run everything off of your local machine!

Great if you can do it, I like vagrant better

May 16th, 2013 12

Page 13: Drupal Development Tips

Testing Your Code@grmpyprogrammer will track you down if you don’t

May 16th, 2013 php|tek 2013 13

Page 14: Drupal Development Tips

php|tek 2013

Testing

Automatically making sure your code works

May 16th, 2013 14

Page 15: Drupal Development Tips

php|tek 2013

Test Driven Development

Write your tests before you code Watch it fail Write code to make your tests pass Feel better

May 16th, 2013 15

Page 16: Drupal Development Tips

php|tek 2013

TDD in Drupal – Yes We Can!

Drupal ships with SimpleTest baked in

Supports unit testing and functional testing

Unit tests are done by extending DrupalUnitTestCase

Functional tests are done by extending DrupalWebTestCaseMay 16th, 2013 16

Page 17: Drupal Development Tips

php|tek 2013May 16th, 2013 17

Page 18: Drupal Development Tips

php|tek 2013

Unit Tests vs Functional Tests

Unit tests do not bootstrap Drupal, so are very quick

Functional Tests bootstrap Drupal, so are very slow

May 16th, 2013 18

Page 19: Drupal Development Tips

php|tek 2013

There are some downsides…

The test runner is AJAX, so it can break very easily

Debugging can be hard since extra output breaks the test runner, and since the DB is destroyed watchdog() is useless You can use $this->verbose(‘message’) or debug(‘message’) though

May 16th, 2013 19

Page 20: Drupal Development Tips

drushYour command line friend

May 16th, 2013 php|tek 2013 20

Page 21: Drupal Development Tips

php|tek 2013

Swiss Army Knife for Drupal

Dump your database to an SQL file$ drush sql-dump --result-file=/PATH/TO/dump.sql

Back up the entire site to a tarball$ drush archive-dump default

View watchdog entries$ drush watchdog-list

Update Drupal and modules$ drush pm-update

Download module$ drush pm-download [module_name]

May 16th, 2013 21

Page 22: Drupal Development Tips

ModulesI couldn’t think of a good tagline that should go here

May 16th, 2013 php|tek 2013 22

Page 23: Drupal Development Tips

php|tek 2013

Backup and Migrate

Allows you to quickly back up the DB and move it

No need to use a DB GUI Can do automatic local or remote

backups Useful for moving databases from

one server to another

May 16th, 2013 23

Page 24: Drupal Development Tips

php|tek 2013

devel

Exposes a lot of the structure of Drupal Things like nodes can be clicked through

to see their object structure Can auto-generate dummy content Better debugging output

dpm() and dvm() for pretty output dpr(), kpr(), and dvr() will dump to

the page header

May 16th, 2013 24

Page 25: Drupal Development Tips

php|tek 2013

Features

Package system for Drupal Takes a lot of stuff in the DB and

makes it exportable and portable via code

Lot of stuff works out of the box, extra modules like UUID, boxes, and features_extra pick up the slack

ftools makes updating features easy

May 16th, 2013 25

Page 26: Drupal Development Tips

Site CachingUnderstand it and harness its power

May 16th, 2013 php|tek 2013 26

Page 27: Drupal Development Tips

php|tek 2013

Drupal offers caching built in

Page caching for full output caching Block caching so that dynamic

content can still update if it needs to You can configure how long to cache

things for

May 16th, 2013 27

Page 28: Drupal Development Tips

php|tek 2013

Understanding the difference

In Full Page Caching, most of the PHP isn’t run Effectively turns your site into a static

site (kind of)

With block caching, not all blocks will cache. What and when to cache is up to the block

May 16th, 2013 28

Page 29: Drupal Development Tips

Asset AggregationIt’s kind of like nuclear fusion, but without all the explosions

May 16th, 2013 php|tek 2013 29

Page 30: Drupal Development Tips

php|tek 2013

Makes your site faster

Will group needed JS and CSS files together, reducing the number of HTTP requests

Will minify CSS, reducing some of the transmission size

YOU have to make your modules take advantage of it, though

May 16th, 2013 30

Page 31: Drupal Development Tips

php|tek 2013

How to take advantage of it

Let Drupal know about your files drupal_add_js() drupal_add_css() Add the files to your .info file

Don’t just add JS and CSS files via <script> and <style> tags in your theme

May 16th, 2013 31

Page 32: Drupal Development Tips

Questions?Really, ask.

May 16th, 2013 php|tek 2013 32

Page 34: Drupal Development Tips

Thank you!

May 16th, 2013 php|tek 2013 34

E-mail: [email protected]: @dragonmantankApp.net: @ctankersley

https://joind.in/8153