best practices in component development for modx

21

Upload: jan-tezner

Post on 01-Jul-2015

710 views

Category:

Software


2 download

DESCRIPTION

Slides from MODX Weekend by modMore. https://conference.modmore.com/

TRANSCRIPT

Page 1: Best Practices in Component Development for MODX
Page 2: Best Practices in Component Development for MODX

Jan Tezner@jantezner

Prague, Czech Republic

Best Practices in Component Development

Page 3: Best Practices in Component Development for MODX

ABOUT ME

● More than 10 years in PHP development

● 7 years experience with MODX

● CTO and Team Leader in COEX

● MODX Ambassador for Czech Republic

● One of organizers of Czech MODX Day 2013

Page 4: Best Practices in Component Development for MODX

ABOUT COEX

● Established in 2006

● Custom PHP & Python development

● 20 people in-house

● 100+ of MODX finished projects

● MODX Professional partner since 2011

● Direct subcontractors of MODX LLC since 2012

Page 5: Best Practices in Component Development for MODX

“We don't always give our clients what they originally wanted but we always bring them what their business really

needs.“

Page 6: Best Practices in Component Development for MODX

WHAT WILL FOLLOW AND WHAT NOT

This is not an ultimate workflow, those are best practices we found in COEX in last couple of years.

1. What to consider before start

2. Environment setup

3. Development tips

4. Build of Transport Package

5. Testing

6. Release

7. Maintenance of Component

8. Links to other resources

Page 7: Best Practices in Component Development for MODX

WHAT TO CONSIDER BEFORE START

● Clarify solution requirements

● Search for an existing solution

● Consider development for yourself or public use

● Find a good name for your component

● Consider support for old Revolution 2.2

Page 8: Best Practices in Component Development for MODX

ENVIRONMENT SETUP - Folders

.../somewhere//extjs//modx22t//modx23//modx23t//packages/

site webroot //localhost/extjs debug filestestingdevelopmenttestingcomponents folders inside

ExtJS 3.4 download link

Put content of archive ./ext-3.4.0/src/ into /extjs/ folder

Page 9: Best Practices in Component Development for MODX

ENVIRONMENT SETUP - MODX

System Settings

● compress_js = No

● compress_css = No

● cache_disabled = Yes

● session_cookie_path = /

Then don’t forget to:

● Manually delete all content in /core/cache/ folder

● Delete all cookies in the browser

} Or more easily by SQL

Page 10: Best Practices in Component Development for MODX

ENVIRONMENT SETUP - Package

● Don’t start from scratch

○ BxrExtra Yeoman generator

○ GitPackageManagement → ./_packages/

● Use IDE for development →

● User your favorite browser :)

○ Console

○ Network logger

Page 11: Best Practices in Component Development for MODX

ENVIRONMENT SETUP - PhpStorm

For smooth development I strongly recommend to make following configurations for your component project.

Tree > External LibrariesConfigure PHP Include Path

● /modx/connectors● /modx/core/cache● /modx/core/model

Settings > Javascript > Libraries● modext /modx/manager/assets/modext/● extjs /extjs/

● /modx/core/xpdo● /modx/manager/controllers● /modx/manager/templates

Page 12: Best Practices in Component Development for MODX

ENVIRONMENT SETUP - .gitignore

Don’t forget to ignore files which shouldn’t be located within your repository.

E.g. config, uploaded, temporary or dev tools files.

Link to .gitignore from Tagger

Page 13: Best Practices in Component Development for MODX

DEVELOPMENT TIPS - General

● MODX Error log is your friend → use $modx->log(...);

● Clear cache often (on filesystem /core/cache/)

● Use xDebug

Beware of backwards compatibility to 2.2

● Javascript: MODx.config.connector_url only in 2.3

● PHP: if ($modx->version[‘major_version’] < 3) { ... }

Page 14: Best Practices in Component Development for MODX

DEVELOPMENT TIPS - Elements

● Use Static elements for development

● Try to not use nested Chunks → performance, readability

● Don’t hardcode strings into code, use Lexicons

● Snippets / Plugins shouldn’t contain HTML

● Don’t be lazy with creating snippet parameters

● Don’t hardcode “global” variables,

use System or Context Settings

Page 15: Best Practices in Component Development for MODX

BUILD OF PACKAGE

● Correctly use Semantic versioning

● Don’t forget to write changelog

● It is good practice to write date of release into

readme and changelog

● Don’t forget to put short description and basic usage of

component or its parts into readme

● Also put link to documentation into readme

● Readme should also contain version of MODX where you

have tested your Component

Page 16: Best Practices in Component Development for MODX

TESTING

● Test often and carefully in time of development

● Before release perform tests on clean MODX install

● Don’t forget to also test Component updates and uninstall

● Test on latest version of MODX

● Don’t test it only by yourself

○ Ask your colleague / friend to help

○ Ask the community

Page 17: Best Practices in Component Development for MODX

RELEASE

Great documentation makes great components, great components make money.

● Start at least with basic documentation with elementary

description of snippet parameters

● Use standard place for documentation

● Make screenshots of visual parts

● Make a nice description for extras.modx.com

● Promote it to community

Page 18: Best Practices in Component Development for MODX

MAINTENANCE OF COMPONENT

Lifecycle of component doesn’t end when component is released.

Page 19: Best Practices in Component Development for MODX

LINKS

● How to Write a Good Chunk

● How to Write a Good Snippet

● Advanced Development

● Developing an Extra in MODX Revolution

● Creating a 3rd Party Component Build Script

● MODExt

● ExtJS 3.4 API Documentation

● ExtJS 3.4 Examples

Page 20: Best Practices in Component Development for MODX