Code Monkey home page Code Monkey logo

droopal's Introduction

drOOPal

Object-oriented approach with helper classes for nodes, users, and forms for Drupal 7.

Why drOOPal?

In a world where many if not most complex systems are based on a language that has Object Oriented Programming (OOP) in it's DNA, drOOPal can help take the procedural programming aspects of Drupal and incorporate using OOP patterns and practices (encapsulation, inheritance, abstraction, etc) with Drupal's fundamental entities (nodes, users, and forms) and maintain overall code that is Drupal compliant.

Usage

Take an existing content type and make it OOP using drOOPal. Let's take a simple blog with content type blog.

class Blog extends Node {
	protected $node_type = 'blog';
}

// You can load a blog object using a nid or a node object.
$node = node_load(123);
$blog = new Blog($node);

// or

$blog = new Blog(123);

// Say you have a field named *field_blog_body* that you want to use.

// The non-drOOPal way.
$blog_body = NULL;
if (property_exists($node, 'field_blog_body')) {
  $entity = entity_metadata_wrapper('node', $node);
  if (!empty($entity)) {
  	$blog_body = $entity->field_blog_body->value();
  }
}
print $blog_body;

// The drOOPal way.
print $blog->blog_body;

The drOOPal standard classes come with many helpful methods, which can all be extended in the custom classes:

class Blog extends Node {
	protected $node_type = 'blog';
	
	public function get_asdf() {
	
	}
}

$node = node_load(123);
$blog = new Blog($node);

// Let's get the author info of the blog node, but first check if the blog is loaded.

// The non-drOOPal way.
if (!empty($node->nid)) {
	$user = user_load($node->uid);
	print $user->name;
}

// The drOOPal way.
if ($blog->is_loaded()) {
	// Returns a drOOPal User object.
	print $blog->get_user()->name;
}

droopal's People

Contributors

khalib avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.