Bean - Block Entities Aren't Nodes
Bean - Block Entities Aren't Nodes
8 October, 2012
Bean stands for Block Entities Arent Nodes and provides a new method of displaying content on a Drupal site. Still require
some clarification as to what this module provides? I sure did when I first looked at Bean so I will take you through the
basics of implementing your own module that takes advantage of Beans.
Overview
Recently in a project it was a requirement for the client to have the ability to have an unlimited amount of blocks that could be placed around a site,
enter Bean Module. Bean stands for Block Entities Arent Nodes and provides a new method of displaying content on a Drupal site. Still require some
clarification as to what this module provides? I sure did when I first looked at Bean so I will take you through the basics of implementing your own
module that takes advantage of Beans.
What is Bean?
Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to
create as many blocks as you require (see screenshot below). The bean content can then be placed around the site just like any other block.
How do I Implement a Bean?
For this demonstration I will be taking snippets of code out of a Hello World module that I wrote for this blog post. This example can be found at the
sandbox page.
1. First we need to define a new Bean type. In this case we are defining a Hello World type with the class HelloWorldBean. As seen the class is
defined in the modules plugins/bean/ directory under the file hello_world.hello_world.inc.
/**
* Implements hook_bean_types_api_info().
*/
function bean_hello_world_bean_types_api_info() {
return array('api' => 4);
}
/**
* Implements hook_bean_types().
*/
function bean_hello_world_bean_types() {
$plugins = array();
$plugin_path = drupal_get_path('module', 'hello_world') . '/plugins/bean';
$plugins['article_listing'] = array(
'label' => t('Hello World'),
'description' => t('A demonstration of the Bean module.'),
'handler' => array(
'class' => 'HelloWorldBean',
'parent' => 'bean',
),
'path' => $plugin_path,
'file' => 'bean_hello_world.hello_world.inc',
);
http://www.previousnext.com.au/blog/introduction-bean-module
1 of 6
return $plugins;
}
Conclusion
Bean module is a new and flexible way to provide another method for a client to display data on a site. This module can provide something as simple as
a Title/Body block or get as complex as a graphing bean of type Line Chart where the content editor could provide a set of data.
In my personal opinion I really enjoy the structure that Bean provides.
http://www.previousnext.com.au/blog/introduction-bean-module
2 of 6
http://www.previousnext.com.au/blog/introduction-bean-module
3 of 6
Tweet
Nick Schuch
nick_schuch
Drupal Developer and Systems
Administrator
Nick has been involved in Drupal since 2011 and more recently become hooked on Drupal 8 core development. Nick's achievements include becoming
the maintainer of Tour module in Drupal 8 core and catching Dries out in a game of beach cricket at Drupalcon Syndey 2013.
More posts by Nick
Categories
Drupal Development (40)
Conference Presentations (17)
Uncategorized (14)
Drupal Theming (11)
Drupal Site Building (8)
High Performance Drupal (4)
Drupal System Administration (4)
http://www.previousnext.com.au/blog/introduction-bean-module
4 of 6
Archives
May 2014 (4)
April 2014 (3)
March 2014 (2)
January 2014 (3)
December 2013 (2)
November 2013 (2)
October 2013 (1)
September 2013 (6)
August 2013 (2)
July 2013 (1)
June 2013 (2)
May 2013 (2)
April 2013 (4)
March 2013 (5)
February 2013 (12)
January 2013 (4)
December 2012 (2)
November 2012 (6)
October 2012 (7)
September 2012 (1)
August 2012 (2)
May 2012 (7)
http://www.previousnext.com.au/blog/introduction-bean-module
5 of 6
http://www.previousnext.com.au/blog/introduction-bean-module
6 of 6