Objectifying drupal


Published on

An introduction to a module which helps you develop Drupal applications in an Object oriented way.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Objectifying drupal

  1. 1. Objectifying Drupal - by extending the node
  2. 2. Extending the Node <ul><li>Some things in Drupal are more easily extendable that others. The node is a very good place to begin.  </li></ul><ul><li>By creating classes for all content types and utility objects that can be inherited or be instantiated we increase the legibility of the code and multiply re-usability.  </li></ul>
  3. 3. Objects Module <ul><li>The purpose of the module is to  </li></ul><ul><ul><li>Auto loads the classes </li></ul></ul><ul><ul><li>Generates a Class file for each content type </li></ul></ul><ul><li>   spl_autoload_register('objects_autoload'); </li></ul><ul><li>   if (file_exists(&quot;{$path}/{$class}.class.php&quot;))  </li></ul><ul><li>     require_once $class_path; </li></ul>
  4. 4. ContentType Class <ul><li>The ContentType class defines methods to do powerful things, such as report on relationships and manipulate data.  </li></ul><ul><li>When you create a new Content Type in Drupal the Drupal Objects module will create a new class named after the CT and implement the ContentType class. This way you can turn any node into an extended object at any point in your code.  </li></ul>
  5. 5. Content Class, ie. Page.class.php <ul><li>This object will then have all the methods of the ContentType class and your node will become able to, for instance provide details of any node, term or user that has been associated with it and provide context for that relationship.  </li></ul><ul><li>   $page = new Page($node); </li></ul><ul><ul><li>$page->getTitle(); </li></ul></ul><ul><ul><li>$page->getBody(); </li></ul></ul><ul><ul><li>$page->cck('color'); </li></ul></ul><ul><ul><li>$page->isPublished(); </li></ul></ul><ul><ul><li>$page->unpublish(); </li></ul></ul><ul><ul><li>$page->delete(); </li></ul></ul><ul><ul><li>$page->save(); </li></ul></ul><ul><ul><li>$page->getAssociatedNodes([return],[publ.],[type],[order]); </li></ul></ul>
  6. 6. Collection Class <ul><li>Colelctions are a loosely defined concept in PHP, apart from arrays it is up to you to create your own way to manage collections.  </li></ul><ul><li>The Collection class defines Drupal/cck specific functions to make it easy to create and manipulate collections.  </li></ul><ul><li>There is nothing like it in the standard Drupal installation and it makes for a really handy class.  </li></ul>
  7. 7. Core Concepts <ul><ul><li>DrupalObjects module extends the node </li></ul></ul><ul><ul><li>All content types create a standard Class, which inherit from the ContentType class </li></ul></ul><ul><ul><li>Autoload ensures that all classes are always available </li></ul></ul><ul><ul><li>Utility classes allow quick deployment of powerful methods </li></ul></ul><ul><ul><li>Add functionality to your classes to extend and customize the node </li></ul></ul>
  8. 8. Benefits of Drupal Objects <ul><ul><li>Rapid development </li></ul></ul><ul><ul><li>Organized code </li></ul></ul><ul><ul><li>Fewer Modules, more power </li></ul></ul><ul><ul><li>On-demand loading of functions, improved performance </li></ul></ul><ul><ul><li>Taking advantage of PHPs OO  </li></ul></ul><ul><ul><li>Reduces the need to use globals and session vars to make data globally available  </li></ul></ul>
  9. 9. Roadmap <ul><li>Adding functionality to the ContentType Class. </li></ul><ul><li>The node is not the only entity of Drupal that can be extended. The User and Taxonomy are also ripe for a similar treatment.  </li></ul><ul><ul><li>User </li></ul></ul><ul><ul><li>Vocabulary </li></ul></ul><ul><ul><li>Term  </li></ul></ul>
  10. 10. References <ul><li>The module has been submitted under the name Objects. You can track the progress of the acceptance process and download the code on: </li></ul><ul><ul><li>drupal.org/node/823750 </li></ul></ul><ul><li>More information:  </li></ul><ul><ul><li>The standard node object: drupal.org/node/49768 </li></ul></ul><ul><ul><li>Native Drupal OO perspective: drupal.org/node/547518 </li></ul></ul>