To Patch Contrib or Write a Custom Module: When to know which path to follow

A presentation at New England Drupal Camp (NEWDcamp) in November 2014 in Providence, RI, USA by Michael Miles

Slide 1

Slide 1

How to R.E.A.D Steps for selecting the correct module. #PatchOrCustom, #justREAD

Slide 2

Slide 2

Who You Are. • Site Builder • • Developer ! • • Decision Maker New to Drupal Want to re-enforce habits

Slide 3

Slide 3

What’s it all about. How to quickly make smart, informed decisions.

Slide 4

Slide 4

What we’ll cover. • Steps to decide between a contrib, patched or custom module. • Basics of patching. • Basics of writing a module.

Slide 5

Slide 5

Michael Miles • Associate Director of PHP @ Genuine Interactive. • Drank the Drupal Kool-aid in 2008. (it’s grape flavored) ! • Twitter: @mikemiles86 • D.o: mikemiles86 @WeAreGenuine

Slide 6

Slide 6

A lover of memes.

Slide 7

Slide 7

How to R.E.A.D! (yay acronyms!) !

Slide 8

Slide 8

R.E.A.D • Research what exists. • Evaluate the options. • Analyze the gap. • Determine amount of change. #justREAD

Slide 9

Slide 9

Research what exists.

Slide 10

Slide 10

Research what exists. • Isolate keywords about functionality. • Search for existing modules. • Use the community.

Slide 11

Slide 11

Slide 12

Slide 12

Evaluate the options.

Slide 13

Slide 13

Evaluate the options. • Read the module description. • Look at community adoption. • Look at maintainer activity.

Slide 14

Slide 14

Slide 15

Slide 15

Analyze the gap.

Slide 16

Slide 16

Analyze the gap. • Download and test the module. • Discover missing functionality. • Check issue queue for solutions.

Slide 17

Slide 17

Patch not found.

Slide 18

Slide 18

Determine amount of change.

Slide 19

Slide 19

Determine amount of change. • Review the module code. • Estimate how much has to be changed. • Do changes extend or alter module?

Slide 20

Slide 20

Let’s review. Like developers…

Slide 21

Slide 21

…Flow Chart FTW! Use community solutions. YES Research.! Find modules? YES Evaluate.! find best fit? NO YES Analyze.! is there a gap? YES NO NO Community solutions exist? NO Use existing module. Build a custom module. YES Determine.! big change? NO Patch.

Slide 22

Slide 22

…Flow Chart FTW! Use community solutions. YES Research.! Find modules? YES Evaluate.! find best fit? NO YES Analyze.! is there a gap? YES NO NO Community solutions exist? NO Use existing module. Build a custom module. YES Determine.! big change? NO Patch.

Slide 23

Slide 23

Examples.

Slide 24

Slide 24

Scenario #1.

Slide 25

Slide 25

The Requirements. WHEN SAVING A FILE AND IT IS A JPEG IMAGE THEN THE EXIF META DATA NEEDS TO BE CAPTURED AND MAPPED TO CUSTOM FIELDS AND THESE MAPPINGS NEED TO BE EXPORTABLE USING FEATURES !

Slide 26

Slide 26

Step 1 Research what exists.

Slide 27

Slide 27

Research what exists. Isolate keywords about functionality. WHEN SAVING A FILE AND IT IS A JPEG IMAGE THEN THE EXIF META DATA NEEDS TO BE CAPTURED AND MAPPED TO CUSTOM FIELDS AND THESE MAPPINGS NEED TO BE EXPORTABLE USING FEATURES. !

Slide 28

Slide 28

Research what exists. Search for existing modules.

Slide 29

Slide 29

Research what exists. Talk to the community. IRC: #drupal, #drupal-support

Slide 30

Slide 30

Research what exists. Find possible existing solutions • The Exif module • The Exif custom module

Slide 31

Slide 31

Step 2 Evaluate the options.

Slide 32

Slide 32

Evaluate the options Read the module description.

Slide 33

Slide 33

Evaluate the options Look at community adoption. Exif Exif Custom

Slide 34

Slide 34

Evaluate the options Look at maintainer activity.

Slide 35

Slide 35

Evaluate the options Determine best fit.

Slide 36

Slide 36

Step 3 Analyze the gap.

Slide 37

Slide 37

Analyze the gap. Download and test the module.

Slide 38

Slide 38

Analyze the gap. Discover missing functionality.

Slide 39

Slide 39

Analyze the gap. Check issue queue for solutions.

Slide 40

Slide 40

Step 4 Determine amount of change.

Slide 41

Slide 41

Determine amount of change. Review the module code.

Slide 42

Slide 42

Determine amount of change. Estimate how much has to be changed. • Requires little rewriting of code base. • Need to add new hooks and one new file.

Slide 43

Slide 43

Determine amount of change. Will changes extend or alter the module?

Slide 44

Slide 44

Which path to choose? • Patch Exif Custom module ! • Write own Exif module

Slide 45

Slide 45

PATCH!

Slide 46

Slide 46

What is a Patch? • drupal.org/patch • A structured list of changes to a file. • Used to re-create changes to a files. • Focus on a single change.

Slide 47

Slide 47

How to create a Patch. • Clone module repository. • Create a new branch. • Make changes to code. • Test changes. • Generate the patch.

Slide 48

Slide 48

Clone module repository. mm:~$ git clone —branch 7.x-1.x http://git.drupal.org/project/exif_custom.git

Slide 49

Slide 49

Create a branch. mm:exif_custom$ git checkout -b patch/features_integration

Slide 50

Slide 50

Make changes.

Slide 51

Slide 51

Test changes.

Slide 52

Slide 52

Create the patch file. mm:exif_custom$ git diff 7.x-1.x > exif_custom-features_integration.patch

Slide 53

Slide 53

How to submit a Patch. • Create/Comment on an issue. • Attach the patch. • • [description]-[issue-number]-[comment-number].patch Revise based on testing/reviews.

Slide 54

Slide 54

Create an issue.

Slide 55

Slide 55

Attach the patch. [description]-[issue-number]-[comment-number].patch

Slide 56

Slide 56

Slide 57

Slide 57

Contributing back to the community.

Slide 58

Slide 58

Scenario #2.

Slide 59

Slide 59

The Requirements. WHEN SITE USES WORKBENCH TO MODERATE CONTENT THEN CAN CREATE MULTIPLE TRANSITIONS BETWEEN STATES AND TRANSITIONS ARE EXPORTABLE USING FEATURES ! WHEN EDITNG A CONTENT REVISION THEN CAN SCHEDULE A TRANSITION AND CAN SELECT DATE FOR FIRST STATE AND CAN SELECT DATE FOR SECOND STATE

Slide 60

Slide 60

Step 1 Research what exists.

Slide 61

Slide 61

Research what exists. Isolate keywords about functionality. WHEN SITE USES WORKBENCH TO MODERATE CONTENT THEN CAN CREATE MULTIPLE TRANSITIONS BETWEEN STATES AND TRANSITIONS ARE EXPORTABLE USING FEATURES ! WHEN EDITNG A CONTENT REVISION THEN CAN SCHEDULE A TRANSITION AND CAN SELECT DATE FOR FIRST STATE AND CAN SELECT DATE FOR SECOND STATE

Slide 62

Slide 62

Research what exists. Search for existing modules.

Slide 63

Slide 63

Step 2 Evaluate the options.

Slide 64

Slide 64

Evaluate the options Read the module description.

Slide 65

Slide 65

Evaluate the options Look at community adoption.

Slide 66

Slide 66

Evaluate the options Look at maintainer activity.

Slide 67

Slide 67

Step 3 Analyze the gap.

Slide 68

Slide 68

Analyze the gap. Download and test the module.

Slide 69

Slide 69

Analyze the gap. Discover missing functionality. • Unable to create different transitions per type • Unable to select different transitions for revisions • No features integration.

Slide 70

Slide 70

Step 4 Determine amount of change.

Slide 71

Slide 71

Determine amount of change. Review the module code.

Slide 72

Slide 72

Determine amount of change. Estimate how much has to be changed. • Will need to change how transitions are created. • Will need to change how schedules are stored. • Will need to add features integration.

Slide 73

Slide 73

Determine amount of change. Will changes extend or alter the module?

Slide 74

Slide 74

Which path to choose? • Patch Scheduler workbench module ! • Write own scheduler module

Slide 75

Slide 75

CUSTOM MODULE!

Slide 76

Slide 76

Module Writing Guidelines. • drupal.org/developing/modules • Follow Drupal coding standards. • Make use of hooks and APIs. • Test your code.

Slide 77

Slide 77

Contributing a module. • Is it functionality other could use? • Name appropriately. • Provide accurate description. • Be an active maintainer.

Slide 78

Slide 78

Name appropriately.

Slide 79

Slide 79

Provide detailed description.

Slide 80

Slide 80

Be an active maintainer.

Slide 81

Slide 81

Free QA and improvements from community.

Slide 82

Slide 82

Slide 83

Slide 83

How to R.E.A.D. • Research what exists. • Evaluate the options. • Analyze the gap. • Determine amount of change. #justREAD

Slide 84

Slide 84

Thank You! @mikemiles86