Post on 01-Jul-2015
description
Jan Tezner@jantezner
Prague, Czech Republic
Best Practices in Component Development
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
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
“We don't always give our clients what they originally wanted but we always bring them what their business really
needs.“
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
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
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
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
ENVIRONMENT SETUP - Package
● Don’t start from scratch
○ BxrExtra Yeoman generator
○ GitPackageManagement → ./_packages/
● Use IDE for development →
● User your favorite browser :)
○ Console
○ Network logger
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
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
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) { ... }
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
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
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
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
MAINTENANCE OF COMPONENT
Lifecycle of component doesn’t end when component is released.
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
Thank you!
COEX@coexczfacebook.com/coex.cz
Jan Tezner@janteznerPrague, Czech Republic