1 / 23

Hook, Drush, and Alters Oh Mai!

Hook, Drush, and Alters Oh Mai!. btopro @btopro http://btopro.com/ http://drupal.psu.edu/blog/1 Bryan Ollendyke. This is a code deep dive “ Hello World ” dev @ 10am in 206 Modules and Dev must haves Cover basic hooks Cover more obscure but useful hooks

blue
Télécharger la présentation

Hook, Drush, and Alters Oh Mai!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hook, Drush, and Alters Oh Mai! btopro @btopro http://btopro.com/ http://drupal.psu.edu/blog/1 Bryan Ollendyke

  2. This is a code deep dive • “Hello World” dev @ 10am in 206 • Modules and Dev must haves • Cover basic hooks • Cover more obscure but useful hooks • Examples provided throughout via contrib Topics

  3. Stackoverflow • Api.drupal.org • Drupal.org issue queues • Drush.org • http://dropbucket.org/ Places to look for help

  4. devel (drush support) • Easy to debug all aspects of drupal objects • drush - Drupal via Command line • Ex: drush @sites cc all • Clear cache on all sites in this multi-site • coder (drush support) • Feedback on code quality based on Drupal community conventions • Provides security audits and suggestions • libraries • API for reusable, non-drupal lib integration Must Have projects

  5. devel_themer • Theme debugging / template sniffing • query_coder • Convert SQL to Drupal query language • features (drush support) • Bundle exportable configuration • Maintain consistency / version control IA • profiler_builder (drush support) • Help converting a site into a distribution • Consistency across build routines (ulmus) Nice to Have projects

  6. registry_rebuild (drush) • Drush extension, life saver at times • backup_migrate (drush support) • UI / Drush based migrations • module_builder (drush support) • Generate module skeletons quickly • examples • Community approved example implementations of APIs Nice to Have projects

  7. entity • field_collection • replicate • Libraries • context • rules Other good API projects

  8. Commonly referred to as “the drupal way” • Easy to override some else’s code • Goal is to never modify others code unless absolutely necessary • Common to write a “sitename_helper” style module loaded with alters Hook/alter architecture

  9. init • page_build • page_alter • form_alter • menu • menu_alter • admin_paths • theme_registry_alter • custom_theme • views_query_alter A few random Hooks

  10. page_build • page_alter Hook Example

  11. page_build • page_alter Alter Example

  12. arg($id) – part of the url (node/67/edit) • arg(0) == ‘node’ • arg(1) == 67 • arg(2) == ‘edit’ • arg(3) NULL • menu_get_item – pull object from URL • $node = menu_get_item(); • the same as node_load(arg(1)); but more flexible (works with other menu objects) Useful API functions

  13. module_load_include(‘module’, ‘yourproject’) • Load an include file w.o. knowing path • module_invokes(‘cron’); • List all modules invoking a hook • drupal_static($value, ‘default’); • Centralized static caching • drupal_form_submit(‘name’, $values) • Programmatically trigger form to submit • dvm($node) or dpm($node) • Required devel, clean var_dump of object Useful API functions

  14. module_invoke_all (‘things_stuff’) • Assemble an array of all returns • {MODULENAME}_things_stuff • drupal_alter(‘things_stuff’, $data) • $data passed by reference to all modules • {MODULE}_things_stuff_alter(&$data); • Invoking existing hook (like page_build) • Call your module_invoke_all(‘myhook’); • Follow it by drupal_alter(‘myhook’, $data); • This allows other devs to safely mod Build own hooks

  15. mooc_helper • Supplamental glue code for install profile • Mostly just injects minor changes • Drupal.org/project/mooc • Then view repository Common Site Example

  16. quojs • Helps include quojs with Drupal • Allows you to invoke js library from other modules • Requires libraries API module • drupal.org/project/quojs Simple Library Example

  17. regions • Stand alone “block” areas across-theme • Creates its own API that is invoked • Add “widgets” that function across themes • Reuse components across sites easier • Export via features cleaner w.o. theme issues • drupal.org/project/regions Complex Example

  18. cis_connector • Web service endpoint for my edtech distros • Caches http calls through a wrapper • Uses mix of drupal_static and cache_set • drupal.org/project/cis_connector • https://drupal.psu.edu/node/779 Complex Example

  19. entity_iframe • Stand alone functionality for any site • Themeable via tpl.php files • Views integration • Dynamic url rewriting per request • Allows secure cross-frame communication • drupal.org/project/entity_iframe Complex Example

  20. drush dl outline_designer views regions cis_connector • Download outline_designer, views, regions, and cis_connector to sites/all/modules • --y can be used to answer yes to everything • drush @sites cc all • Clear the cache on all sites Simple Drush example

  21. book_copy • Replicate book outlines in Drupal • Drush support for passing a node id • drupal.org/project/book_copy Writing your own Drush

  22. See if functionality could be useful elsewhere • Solve for Drupal, not for PSU • hooks/alters to solution, PSU being just 1 • Code “The drupal way” • Try to structure code as follows: • Contrib module – given away • PSU – specific to university • College – specific to our usage • Implementation – specific to 1 deployment Maximize reuse

  23. Questions?#dcpsu@psu_drupal

More Related