I have restarted work on the embed module, but I am targetting Drupal 7. There are already multiple embedding methods in Drupal 6, so another one just adds to the confusion. However, getting something viable in place for Drupal 7 could be really interesting.

This module is working towards providing a standard method for objects to be embedded on a Drupal site. It does this by defining a new element type called object. Objects have attributes and parameters to define them, and the module makes it possible to write themes that turn objects in to markup on a page.

As far as possible we are sticking with standard Drupal functions to handle rendering, and standard definitions of objects to describe them, in order to make an API layer that is slim, consistent and easy to learn. So we use the existing element property of #attributes, and we describe objects using things like mime type.

There's a very long thread describing the thinking that has led to the current code.

While the module is being worked up the following code snippet shows how a piece of flash content would be defined and embedded using the new format.

// Describe the object
$attributes = array(
'type' => 'application/x-shockwave-flash',
'data' => '/server/sites/default/files/myFlash.swf',
'height' => 200,
'width' => 200,
// Define its parameters (optional)
$params = array(
'play' => 'true',
'loop' => 'true',
// Create a Drupal element
$element = array(
'#type' => 'object',
'#attributes' => $attributes,
'#parameters' => $params,
// Render it
print drupal_render($element);

The important thing to note is that the output is created via drupal_render(). Because this is the case you could equally place the element as part of a node tree, or a Form API tree, and get your content that way. No special code or calls to themes or functions. You also have access to all the other properties like #prefix, #suffix, and even #pre_render and #post_render.

The module also works a lot like CCK when presented with multiple objects - it can either display them individually (e.g. each audio element in its own container), or if the supporting module allows it then it can turn them in to things like playlists.

The early versions of embed were created for Drupal 6 and were used to prove a few concepts. For example, we had a modified version of SWF Tools that used the embed framework to place flash content on a page instead of using the SWF Tools provided methods. We made a very small module that let you send content from the audio module via the embed framework and have it appear in FlowPlayer (a player that audio module knows nothing about). We also used embed to add svg graphics to a page, both natively (in browsers that support it), or via a flash rendering mechanism.

Why do this? There are multiple modules designed to handle media content like flash and videos. In general each of these re-implements a method of putting flash a page, or re-implements a means of putting a particular media player on a page. The ambition of the embed module is to make this unnecessary by letting all modules talk to all other modules when handling media. That way we can have less duplication and focus effort on creating fantastic implementations of the available players and embedding systems that are out there. And for the end user it means they can pick and choose between all the options, instead of having to wait for their particular preference to be written for a specific module.

At the moment on HEAD is the prototype for Drupal 7. At the time of writing this implements generic object embedding (for objects that don't have a special handler written for them). The generic handler will attempt to use <object></object> to embed the item. To prove the concept there are handlers for flash (application/x-shockwave-flash) objects that will embed use HTML or SWF Object 2, and there's an elementary FlowPlayer 3 module (audio/mp3, video/x-flv, audio/mpeg). None of the modules are feature rich yet as the current intent is to keep them intentionally overly simple while the concepts are tested.

The code is under active development, and the framework has a tendency to change as we learn and discover things during its development. For this reason there is currently no package to download. However, the code is in CVS if you want to take a look. The issue queue is also open, although at the moment it is more for capturing discussion to help shape how embed will look. Please join in!

The rendering process is all based on the use of themes, and one theme can call another, transforming objects as they go. For example, if you submit an audio/mp3 object, and have FlowPlayer3 configured as the handler then the FlowPlayer3 theme function will turn the object in to a flash object, and it calls drupal_render again with the new object.

Useful references

Project Information

  • Maintenance status: Unknown
  • Development status: Unknown
  • Last modified: August 23, 2009