10
Objectifying Drupal - by extending the node

Objectifying drupal

  • Upload
    valberg

  • View
    951

  • Download
    0

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Objectifying drupal

Objectifying Drupal

- by extending the node

Page 2: Objectifying drupal

Extending the Node

Some things in Drupal are more easily extendable that others. The node is a very good place to begin. 

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. 

Page 3: Objectifying drupal

Objects Module

The purpose of the module is to 

• Auto loads the classes• Generates a Class file for each content type

  spl_autoload_register('objects_autoload');

  if (file_exists("{$path}/{$class}.class.php"))     require_once $class_path;

Page 4: Objectifying drupal

ContentType Class

The ContentType class defines methods to do powerful things, such as report on relationships and manipulate data. 

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. 

Page 5: Objectifying drupal

Content Class, ie. Page.class.phpThis 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. 

  $page = new Page($node);

• $page->getTitle();• $page->getBody();• $page->cck('color');• $page->isPublished();• $page->unpublish();• $page->delete();• $page->save();• $page->getAssociatedNodes([return],[publ.],[type],

[order]);

Page 6: Objectifying drupal

Collection ClassColelctions are a loosely defined concept in PHP, apart from arrays it is up to you to create your own way to manage collections. 

The Collection class defines Drupal/cck specific functions to make it easy to create and manipulate collections. 

There is nothing like it in the standard Drupal installation and it makes for a really handy class. 

Page 7: Objectifying drupal

Core Concepts

• DrupalObjects module extends the node

• All content types create a standard Class, which inherit from the ContentType class

• Autoload ensures that all classes are always available

• Utility classes allow quick deployment of powerful methods

• Add functionality to your classes to extend and customize the node

Page 8: Objectifying drupal

Benefits of Drupal Objects

• Rapid development• Organized code• Fewer Modules, more power• On-demand loading of functions, improved

performance• Taking advantage of PHPs OO • Reduces the need to use globals and session vars to

make data globally available 

Page 9: Objectifying drupal

Roadmap

Adding functionality to the ContentType Class.

The node is not the only entity of Drupal that can be extended. The User and Taxonomy are also ripe for a similar treatment. 

• User• Vocabulary• Term 

Page 10: Objectifying drupal

References

The module has been submitted under the name Objects. You can track the progress of the acceptance process and download the code on:

• drupal.org/node/823750

More information: 

• The standard node object: drupal.org/node/49768• Native Drupal OO perspective:

drupal.org/node/547518