Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EECI 2012 Presentation -- Extending Add-ons: How to make popular add-ons even more powerful

EECI 2012 Presentation -- Extending Add-ons: How to make popular add-ons even more powerful

My presentation at the October 2012 ExpressionEngine/CodeIgniter Conference in Austin, Texas.

Sometimes an existing add-on gets you most of the way towards a feature, but not all the way there. Instead of reverting to building your own add-on for the feature, I talk about when it makes sense to use the existing add-on but extend it to do everything you need. I also show examples of how to extend some popular existing add-ons, beyond extension hooks.

Matt Weinberg

October 16, 2012
Tweet

More Decks by Matt Weinberg

Other Decks in Technology

Transcript

  1. Who Am I? • President of Development & Technology at

    Vector Media Group, a development and online marketing company NYC • I co-founded the company with my partner Lee. We’re now 14 people. • Most of our development is ExpressionEngine-based • Clients like Starwood, Kenneth Cole, NY Times • We love EE • @mrw on Twitter • [email protected]
  2. My Goals Today • Create a context around choosing between

    writing your own add-ons from scratch, or extending existing add-ons • Show how some popular add-ons can be extended and give examples where we’ve used them. • Equip you to make these decisions in the future with a better frame of reference
  3. The choice • We’ve all been in the situation where

    an add-on gets you part of the way to functionality you need but not all the way, and you’re not sure how to proceed • Using just the add-on wouldn’t satisfy the site’s requirements • Building totally from scratch means you’re duplicating lots of functionality existing add-ons already have
  4. An example: CartThrob • Angie Herrera (420 Creative) asked us

    to consult on a project • Standard eCommerce site but with a few special requirements • “Build Your Own” products with pricing and combination restrictions from various data sources • Gift Card support: buying, gifting, adding to your account, and using card balance + credit card in the same transaction • CartThrob had the basics: cart, checkout tags, products, discounts, etc... Not worth building our own shopping add-on • Decided to use CartThrob as our base and heavily extend it to support custom features. Best of both worlds. • More on CartThrob later
  5. How do we decide between extending an existing add-on or

    going fully custom? • Spend lots of time thinking about this • Early code decisions can have outsized influence later on • We write significant amounts of custom one-time add-ons for each project • Goal is to minimize total codebase, time spent troubleshooting, and duplication of effort
  6. How do we decide between extending an existing add-on or

    going fully custom? • Are the kinds of hooks or expansion capabilities included in the add-on we're considering? • We almost never hack an add-on or core to add what we need. • Avoid later upgrade headaches • Standardize behavior for ease of portability within our team, and maintenance • There’s some disagreement in the EE community on this
  7. How do we decide between extending an existing add-on or

    going fully custom? • How much of the existing add-on will we use? • One small feature we can easily replicate, or are we taking advantage of a lot the add-on has to offer? • If it's a tiny piece, it's may be easier to just make our own add-on. • CartThrob example, we were using significant amounts of their features
  8. How do we decide between extending an existing add-on or

    going fully custom? • How long would it take us to write the functionality from scratch? • In the CartThrob example, it would have taken us a good amount of time to replicate CartThrob's basic ecommerce functionality • We'd have had no benefits over where we ended up
  9. How do we decide between extending an existing add-on or

    going fully custom? • How complex is the existing add-on's functionality? • How long has the add-on been available? • How popular is the add-on? • How reliable is the developer? • For complex functionality with a lot of moving parts, reliable developers of popular add-ons have probably already fixed the low- hanging bugs and dealt with the basic problems we may run into. • For existing add-ons that haven’t been widely used or tested, we may end up spending more time fixing it than we would have writing our own. It’s not a net time savings.
  10. Zenbu • Client wanted to use ExpressionEngine as a CRM,

    with channel entries as their contacts (their contacts don't need to login) • Around 55 fields; mostly a mix of text, date, file, Matrix, and custom fieldtypes • Client needed a great search/sort interface for the entry listings, where they could see a lot of custom fields at once and filter with complex rules to any of the fields. The native edit listing wasn’t enough.
  11. Zenbu • Zenbu is an add-on that enhances the CP

    edit entries listing to include custom fields and more granular searching.
  12. Zenbu • Great base • Show custom fields on the

    edit screen • Search specific fields with rules • Save searches for future use • Not powerful enough on its own for this project • But, if we built this interface from scratch, we’d end up rebuilding much of what Zenbu already has
  13. Zenbu • By default, Zenbu displays the value stored in

    exp_channel_data for fieldtypes it doesn’t know • We had a few custom fieldtypes that stored data in other tables • Zenbu will look for a zenbu_display method in any custom fieldtype. • It will get passed entry_id among other parameters • You can do any processing you need. The string you return is displayed by Zenbu as the value for that field
  14. Zenbu • Zenbu knows about some fieldtypes and displays them

    in specific ways. • The default display of Matrix data didn't meet our client’s needs • For fieldtypes that aren't yours, you can create a matching file in zenbu/fieldtypes and control how it displays. • For Matrix, this allowed us to display just a few columns from a few specific rows, and style them appropriately for our client.
  15. Zenbu • Zenbu can display all an entry’s categories on

    the listing page by default • Our client was using categories in a very specific way, and listing them all in arbitrary order wouldn’t be helpful • We wrote an extension for Zenbu’s zenbu_modify_category_display hook that re- processed/selectively modified category data and returned a much more client-friendly format
  16. Zenbu • Hypothetically, we could have built a custom entry

    listing and searching add-on ourselves, but we ended up with a great, upgrade-safe solution with far less work. • Tip: Zenbu will call your methods for each result (potentially hundreds or thousands of entries). Take advantage of its bulk helper methods and the session cache to minimize duplicate queries and processing.
  17. CE Image • CE Image is an excellent image resizing

    and processing plugin that supports many options. • Typical usage is inside templates:
  18. CE Image • We sometimes need these kinds of features

    outside of regular templates • Recent example: • Site primarily driven by JavaScript Handlebars templates and JSON feeds. • On page loads, JS would fetch JSON data from a module we created and run through Handlebars for output. • Because processing was in-browser, we wanted to output paths for multiple sizes of optimized and resized images directly to the JSON object.
  19. CE Image • In our JSON output module, we created

    a _create_image method that used CE Image via PHP and returned the relative path.
  20. CE Image • Tips: • Once you require PATH_THIRD .

    'ce_img/libraries/ Ce_image.php', usage is as defined in CE Image's regular PHP docs • You can use $this->EE->config->item() to make sure CE Image uses the same settings whether it’s used in PHP or EE templates
  21. Wygwam • Wygwam is a WYSIWYG editor created by Pixel

    & Tonic. One of our favorite add-ons. • Offers customizable toolbars allowing you to hide/ show certain buttons on certain fields:
  22. Wygwam • Some site designs call for multiple variations of

    a single type of element within an area controlled by a WYSIWYG field. • e.g. multiple table or list styles. • CKEditor/Wygwam has custom style sets. • Use JSON to define custom classes for elements • Enable it as a stylesSet in Wygwam. • Clients get friendly settings to choose display types.
  23. Wygwam • Enable it as a stylesSet in Wygwam •

    Note we’ve named it tic_styles, referencing the site name and matching the name in the JSON
  24. Freeform • Freeform is the fantastic form add-on from Solspace.

    Easily create forms and store inputted data • Settings to have multiple recipients, notify on submit via email, etc...
  25. Freeform • We're often asked to build forms that save

    to ExpressionEngine and also send the data to an external system for further processing • Freeform gets us most of the way there • It includes field definitions, entry validation, saving to the EE database, a nice control panel UI, and more • We’d usually need to build all this anyway
  26. Freeform • We use the freeform_module_insert_end hook. • Runs if

    data passes Freeform's validation and is successfully saved. • You're passed the Freeform entry ID and field information, and can do whatever further processing you need.
  27. CartThrob • We do a significant amount of eCommerce work,

    and each site is completely different • CartThrob, Brilliant Retail, and Exp:resso Store are all very customizable for developers • Focusing on CartThrob just for example purposes
  28. CartThrob • Payment Gateway plugins • Add new payment gateways

    or re-write support for an existing one • Shipping plugins • Calculate shipping via custom logic • e.g. integrate with external shipping providers to get live cost • Discount and tax plugins • Custom tax and discount logic during checkout • Extension hooks at every step
  29. CartThrob • Discount Plugin • Only allows discount on items

    with certain custom field values • Calculates discounts using complex business rules
  30. CartThrob • Extension Hooks • Add shipped-to addresses to user’s

    “Address Book” • Allows users to choose from Address book on checkout
  31. Summary • If an otherwise great add-on doesn’t get you

    everything you need, consider extending it before building completely from scratch • Many add-ons can be extended in surprising ways • It’s not just about extension hooks
  32. Thank You + Q & A • Contact me any

    time with any questions • [email protected] • @mrw • http://www.VectorMediaGroup.com • I’ll post slides online after the conference