? 710034.patch
Index: ds.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ds/ds.module,v
retrieving revision 1.1.2.50
diff -u -p -r1.1.2.50 ds.module
--- ds.module	3 Feb 2010 16:34:22 -0000	1.1.2.50
+++ ds.module	22 Feb 2010 23:21:18 -0000
@@ -103,6 +103,48 @@ function ds_features_api() {
 }
 
 /**
+ * Implementation of hook_block().
+ */
+function ds_block($op = 'list', $delta = 0, $edit = array()) {
+  switch ($op) {
+    case 'list':
+      require_once('includes/ds.registry.inc');
+      return _ds_block_list();
+      break;
+    case 'view':
+      $content = array();
+      $ds_blocks = variable_get('ds_blocks', array());
+      if (isset($ds_blocks[$delta])) {
+        $info = $ds_blocks[$delta];
+        $data = $info['data'];
+        if (isset($data['filename']) && isset($data['class'])) {
+          require_once($data['filename']);
+          $class = $data['class'];
+          $plugin = new $class();
+          if (method_exists($plugin, 'block_view')) {
+            $content = $plugin->block_view($info);
+          }
+        }
+      }
+      return $content;
+      break;
+  }
+}
+
+/**
+ * Set or get static variables at runtime.
+ */
+function ds_static_variables($key, $data = NULL) {
+  static $variables = array();
+  if (!isset($data) && isset($key) && isset($variables[$key])) {
+    return $variables[$key];
+  }
+  elseif (!isset($variables[$key]) && isset($data)) {
+    $variables[$key] = $data;
+  }
+}
+
+/**
  * Return API info about a module and type.
  *
  * @param string $module The module to get the API info from.
@@ -494,7 +536,7 @@ function ds_plugins_process($module, $ob
         require_once($data['filename']);
         $class = $data['class'];
         $plugin = new $class();
-        $plugin->execute($vars, $display, $display_settings, $object_type);
+        $plugin->execute($vars, $display, $display_settings, $object_type, $module);
       }
     }
   }
Index: includes/ds.registry.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ds/includes/ds.registry.inc,v
retrieving revision 1.1.2.26
diff -u -p -r1.1.2.26 ds.registry.inc
--- includes/ds.registry.inc	3 Feb 2010 13:15:50 -0000	1.1.2.26
+++ includes/ds.registry.inc	22 Feb 2010 23:21:18 -0000
@@ -336,6 +336,48 @@ function _ds_register_build_modes() {
 }
 
 /**
+ * Return blocks.
+ */
+function _ds_block_list() {
+  $blocks = array();
+  $all_blocks = array();
+
+  foreach (module_implements('ds_api') as $module) {
+    $plugins = variable_get($module .'_plugin_settings', array());
+    if (!empty($plugins)) {
+      foreach ($plugins as $key => $data) {
+        if (isset($data['filename']) && isset($data['class'])) {
+          require_once($data['filename']);
+          $class = $data['class'];
+          $plugin = new $class();
+          if (method_exists($plugin, 'block_list')) {
+            $plugin->block_list($module, $all_blocks, $data);
+          }
+        }
+      }
+    }
+  }
+
+  if (!empty($all_blocks)) {
+    $i = 0;
+    $ds_blocks = array();
+    foreach ($all_blocks as $key => $block) {
+      if (isset($block['info']) && isset($block['key']) && isset($block['data'])) {
+        // Calculating the md5 from the key is effective here, because we'll
+        // get back an int which is exactly 32 characters long, the length
+        // of the delta field of the blocks table.
+        $hash = md5($block['key']);
+        $blocks[$hash] = array('info' => $block['info']);
+        $ds_blocks[$hash] = $block;
+      }
+    }
+    variable_set('ds_blocks', $ds_blocks);
+  }
+
+  return $blocks;
+}
+
+/**
  * Return ds plugins.
  */
 function _ds_plugins() {
@@ -357,5 +399,13 @@ function _ds_plugins() {
       'path' => $path .'/plugins',
       'target' => 'all',
     ),
+    'regiontoblock' => array(
+      'title' => t('Region to block'),
+      'class' => 'ds_regiontoblock',
+      'description' => t('Render a display suite region into a theme region. That region will be made available as a block.'),
+      'file' => 'ds_regiontoblock.inc',
+      'path' => $path .'/plugins',
+      'target' => 'all',
+    ),
   );
 }
Index: plugins/ds_cssoverrider.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ds/plugins/Attic/ds_cssoverrider.inc,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 ds_cssoverrider.inc
--- plugins/ds_cssoverrider.inc	2 Feb 2010 11:04:30 -0000	1.1.2.6
+++ plugins/ds_cssoverrider.inc	22 Feb 2010 23:21:18 -0000
@@ -69,7 +69,7 @@ class ds_cssoverrider {
   /**
    * process().
    */
-  public function execute(&$vars, &$display, $display_settings, $object_type) {
+  public function execute(&$vars, &$display, $display_settings, $object_type, $module) {
 
     foreach ($display->themed_regions as $region_name => $region_data) {
 
Index: plugins/ds_emptyregionrender.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ds/plugins/Attic/ds_emptyregionrender.inc,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 ds_emptyregionrender.inc
--- plugins/ds_emptyregionrender.inc	2 Feb 2010 11:04:30 -0000	1.1.2.6
+++ plugins/ds_emptyregionrender.inc	22 Feb 2010 23:21:18 -0000
@@ -60,7 +60,7 @@ class ds_emptyregionrender {
   /**
    * execute().
    */
-  public function execute(&$vars, &$display, $display_settings, $object_type) {
+  public function execute(&$vars, &$display, $display_settings, $object_type, $module) {
 
     foreach ($display->all_regions as $region_name => $region_title) {
 
Index: plugins/ds_regiontoblock.inc
===================================================================
RCS file: plugins/ds_regiontoblock.inc
diff -N plugins/ds_regiontoblock.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/ds_regiontoblock.inc	22 Feb 2010 23:21:18 -0000
@@ -0,0 +1,127 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * DS_RegionToBlock: Plugin to make a region available as a block.
+ */
+
+class ds_regiontoblock {
+
+  /**
+   * Constructor().
+   */
+  function __construct() {
+
+  }
+
+  /**
+   * plugin_form().
+   */
+  public function plugin_form(&$form, $display_settings) {
+
+    $form['regiontoblock'] = array(
+      '#type' => 'fieldset',
+      '#collapsible' => FALSE,
+      '#collapsed' => FALSE,
+      '#description' => t('Toggle regions you want to make available as a block.'),
+    );
+
+    $build_mode = $form['#build_mode'];
+    $regions = ds_regions();
+    foreach ($regions as $region => $title) {
+      if ($region != 'disabled') {
+        $form['regiontoblock']['region-block-'. $region] = array(
+          '#title' => $title,
+          '#type' => 'checkbox',
+          '#default_value' => ds_default_value($display_settings, $build_mode, 'regiontoblock', 'block', $region, ''),
+        );
+      }
+    }
+  }
+
+  /**
+   * plugin_form_submit().
+   */
+  public function plugin_form_submit($form, $form_state, &$display_settings) {
+
+    $regions = ds_regions();
+    $regions_save = array();
+    $build_mode = $form['#build_mode'];
+
+    foreach ($regions as $region => $title) {
+      if (isset($form_state['values']['regiontoblock']['region-block-'. $region]))
+      $regions_save['block'][$region] = $form_state['values']['regiontoblock']['region-block-'. $region];
+    }
+
+    $display_settings[$build_mode]['regiontoblock'] = $regions_save;
+  }
+
+  /**
+   * plugin block listing.
+   *
+   * Make sure you create a unique name for your $block_key.
+   * You should return info & plugin so ds_block knows
+   * which block to load. You can add other info, which
+   * you'll receive back in block_list.
+   */
+  public function block_list($module, &$blocks, $data) {
+    $api_info = ds_api_info($module);
+    $types = $api_info['types']();
+    if (!empty($types)) {
+      foreach ($types as $type_key => $object) {
+        $display_settings = variable_get($module .'_display_settings_'. $type_key, array());
+        foreach ($display_settings as $build_mode => $settings) {
+          if (isset($settings['regiontoblock'])) {
+            foreach ($settings['regiontoblock']['block'] as $region => $value) {
+              if ($value) {
+                $block_key = 'ds_regiontoblock_'. $module .'_'. $object->type .'_'. $build_mode .'_'. $region;
+                $block_info = $api_info['title'] .': '. $object->name .', '. $build_mode .', '.$region;
+                $blocks[] = array(
+                  'info' => $block_info,
+                  'key' => $block_key,
+                  'data' => $data,
+                );
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * plugin block view
+   */
+  public function block_view($block) {
+    $content = array();
+    $static_content = ds_static_variables($block['key']);
+    if (!empty($static_content)) {
+      $content['subject'] = $block['info'];
+      $content['content'] = $static_content;
+    }
+    return $content;
+  }
+
+  /**
+   * execute().
+   */
+  public function execute(&$vars, &$display, $display_settings, $object_type, $module) {
+    $object = $vars[$object_type];
+
+    foreach ($display->all_regions as $region_name => $region_title) {
+
+      $region_to_block = ds_default_value($display_settings, $display->build_mode, 'regiontoblock', 'block', $region_name, FALSE);
+
+      if ($region_to_block == TRUE && isset($display->themed_regions[$region_name])) {
+        $region_content = $display->themed_regions[$region_name];
+        $key = 'ds_regiontoblock_'. $module .'_'. $object->type .'_'. $object->build_mode .'_'. $region_name;
+        ds_static_variables($key, $region_content['content']);
+        unset($display->themed_regions[$region_name]);
+        if ($region_name == 'left' || $region_name == 'right') {
+          unset($display->region_classes[$region_name]);
+        }
+      }
+    }
+  }
+}
