Integrating Alfresco Content into a Drupal Site

Zybzzz 2013-04-29

I've been on a bit of a tear with CMIS lately.  Every time I have a project requirement that mentions document storage or a document library, I think "hey, let's use Alfresco, that CMIS interface is pretty nifty".  I have heard some people grumble that CMIS isn't ready for "prime time" (whatever that means), but my experience suggests otherwise.  So far I have used Alfresco's CMIS interface in iPad / iPhone applications, Python scripts (running in Jython) and a few J2EE web applications.

Well, let's add another one.  My company makes extensive use of Drupal for internal and external web sites.  It's lightweight, pretty easy to train content owners to use, is dead simple to host and has LOTS of support among the various designers and agencies we work with.  I'm not a huge fan of PHP personally, but I like the modularity and simplicity Drupal offers.  One of the Drupal sites I have been called on to improve is a communication portal for a large internal project.  The portal is pretty simple, with just a few menus and a couple of custom content types.  The project participants are already using Alfresco to manage many of their internal documents, and they want to expose two Alfresco Share document libraries to the portal.  One of these sites contains general project information and the other contains training materials.  Sound like a use case for CMIS?  You bet.

There are a few options available for integrating CMIS content into a PHP web application.  The first way I explored was writing my own module using phpclient from the Apache Chemistry project.  I have used this in the past and found it to be a solid implementation of CMIS for PHP.  However, there is a better solution out there for Drupal users.  There is a CMIS API module that encompasses a CMIS query tool, a repository browser, content synchronization and a few other goodies.  Let's step through setting it up.

First, download the module package and add it to your Drupal installation.  Installing a Drupal module is as simple as unpacking it into <drupal_base>/sites/all/modules/contributed.  Once you have the module installed, open up your settings.php (I use the site-specific config file in <drupal_base>/sites/<hostname>/settings.php), and configure a new repository by adding the following bit of PHP to the end of your settings file.  If you like, you can configure multiple repositories by adding multiple entries like the 'default' entry to the outer array:

1
2
3
4
5
6
7
8
9
10
/**
 * CMIS repository configuration
 */
$conf['cmis_repositories'] = array(
    'default' => array (
        'user' => 'alfresco_username',
        'password' => 'alfresco_password',
        'url' => 'http://my.server/alfresco/service/cmis'
    )
);

Now that the module is installed and a repository is configured, log into Drupal with an Administrator account and go to the module list.  At this point you should see a new section in the list for CMIS modules.

Integrating Alfresco Content into a Drupal Site

There are a few modules here that are of particular interest.  The CMIS module has to be enabled, as it is required by the rest of the modules in the package.  Other modules I have found useful are the CMIS Browser and CMIS Query modules.   I haven't had a occasion to use the headerswing, Dev or Sync modules, but I went ahead and enabled them anyway for evaluation.  Check the requisite boxes and click "Save" at the bottom of the page to enable the modules you want to use.  Once enabled, you have some new functionality to explore.  Let's take a quick look at the CMIS Browser module first.

The browser can be accessed at http://your.server.com/yourdrupalpath/cmis/browser.  It provides a navigable, "explorer-like" view of your CMIS repository, as well as actions for creating content and folders:

Integrating Alfresco Content into a Drupal Site

The Browser module can also be directed to a specific repository path by appending that path to the end of the URL.  For example, if you want to see the contents of the "Sites" folder displayed, just append "Sites" to the end of your URL, like so:  http://your.server.com/yourdrupalpath/cmis/browser/Sites. This is very handy if you want to link to the CMIS browser from a Drupal menu and drop into a specific folder in your repository.

The query module works in a similar fashion.  It provides a CQL (Content Query Language) interface to the configured repository.  You can access the query module at http://your.server.com/yourdruplapath/cmis/query.  Just enter a valid CQL query and click "Run":

Integrating Alfresco Content into a Drupal Site

Like the browser module, the query module can take the specific query as a part of the URL.  If you append the query after the base URL, the module will be displayed with the query already executed. 

Both of these modules are very handy for exploring and searching a repository, but I need something a bit simpler.  I just want to display a table of folders and documents that my users can click through.  No tree views, no queries, no breadcrumb trail, no actions.  Just a simple little file/folder list.  To that end, I grabbed some of the code from the existing query and browser modules (thanks guys, I love open source!) and created a simple CMIS Display module:

Integrating Alfresco Content into a Drupal Site

The CMIS Display module works much like the CMIS Browser module.  It will display any repository path that is appended to the URL.  So, if you wanted to display everything in your "Sites" folder in the repository, this is the URL you would use:  http://your.server.com/yourdrupalpath/cmis/display/Sites.  It's simiple, clean and easy to use.  The CMIS Display module isn't part of the CMIS module package, but if you want to add it to your Drupal installation, just download the zip file here, and unzip it into your CMIS module installation directory.  This will create a cmis_display directory alongside your cmis_browser and cmis_query directories.  If you install it after the rest of your CMIS module is installed, don't forget to go to the Drupal Modules list and activate it.  Big thank you to all of the Drupal CMIS module contributors for making my life a little easier!

相关推荐

会写code的凳子哥 / 0评论 2011-07-19