adding many example blocks and re-arranging the plugin system to have interfaces...
authorKris
Fri, 6 Jan 2012 17:50:37 +0000 (11:50 -0600)
committerKris
Fri, 6 Jan 2012 17:50:37 +0000 (11:50 -0600)
15 files changed:
.htaccess
core/includes/Drupal/Configuration/ConfigurationService.php
core/includes/Drupal/Plugin/Core/AbstractBlock.php [new file with mode: 0644]
core/includes/Drupal/Plugin/Core/BlockInterface.php
core/includes/Drupal/Plugin/Core/Searchblock.php [new file with mode: 0644]
core/includes/Drupal/Plugin/Core/SystemHelpBlock.php [new file with mode: 0644]
core/includes/Drupal/Plugin/Core/SystemMainBlock.php [new file with mode: 0644]
core/includes/Drupal/Plugin/Core/SystemMenuBlock.php [new file with mode: 0644]
core/includes/Drupal/Plugin/Core/SystemPoweredByBlock.php [new file with mode: 0644]
core/includes/Drupal/Plugin/Core/Testblock.php
core/includes/Drupal/Plugin/Multiconfig.php
core/includes/Drupal/Plugin/PluginChildrenInterface.php [new file with mode: 0644]
core/includes/Drupal/Plugin/PluginInterface.php [new file with mode: 0644]
core/modules/block/block.module
index.php

index a69bdd4..8a98b80 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -136,3 +136,4 @@ DirectoryIndex index.php index.html index.htm
     </FilesMatch>
   </IfModule>
 </IfModule>
+php_value display_errors 1
index 3702866..73a2a93 100644 (file)
@@ -16,7 +16,7 @@ class ConfigurationService {
          'title' => 'Cache',
          'description' => 'A core cache plugin utility mechanism.',
       ),
-      'plugin.core.block' => array(
+      'plugin.factory.core.block' => array(
         'factory' => '\Drupal\Plugin\Multiconfig',
         'title' => 'Block',
         'description' => 'Block plugin mechanism.',
@@ -24,15 +24,63 @@ class ConfigurationService {
         'children' => TRUE,
       ),
       'plugin.core.block.test' => array(
-        'title' => 'Test Block PLugin',
-        'description' => 'A test block plugin.',
+        'subject' => 'Test Block Plugin',
+        'content' => 'A test block plugin.',
+        'module' => 'blockTest',
+        'region' => 'footer',
+        'delta' => 0,
         'block_class' => '\Drupal\Plugin\Core\Testblock',
       ),
+      'plugin.core.block.search.form' => array(
+        'subject' => 'Search',
+        'module' => 'search',
+        'region' => 'footer',
+        'delta' => 'form',
+        'block_class' => '\Drupal\Plugin\Core\Searchblock',
+      ),
+      'plugin.core.block.system.main' => array(
+        'subject' => NULL,
+        'module' => 'system',
+        'region' => 'footer',
+        'delta' => 'main',
+        'block_class' => '\Drupal\Plugin\Core\SystemMainBlock',
+      ),
+      'plugin.core.block.system.powered-by' => array(
+        'subject' => NULL,
+        'module' => 'system',
+        'region' => 'footer',
+        'delta' => 'powered-by',
+        'block_class' => '\Drupal\Plugin\Core\SystemPoweredByBlock',
+      ),
+      'plugin.core.block.system.help' => array(
+        'subject' => NULL,
+        'module' => 'system',
+        'region' => 'footer',
+        'delta' => 'help',
+        'block_class' => '\Drupal\Plugin\Core\SystemHelpBlock',
+      ),
+      'plugin.core.block.system.menu' => array(
+        'subject' => NULL,
+        'module' => 'system',
+        'region' => 'footer',
+        'delta' => NULL,
+        'block_class' => '\Drupal\Plugin\Core\SystemMenuBlock',
+      ),
       'plugin.core.block.test2' => array(
-        'title' => 'Test Block PLugin 2',
+        'title' => 'Test Block Plugin 2',
         'description' => 'Another test block plugin.',
         'block_class' => '\Drupal\Plugin\Core\Testblock',
       ),
+      // spoof plugin discovery for listing.
+      'plugin.core.block' => array(
+        'test',
+        'test2',
+        'search',
+        'system.main',
+        'system.poweredby',
+        'system.help',
+        'system.menu',
+      ),
     );
 
     return $data;
@@ -65,7 +113,7 @@ class ConfigurationService {
    * @todo Probably not the right class for those Plugin-specific helpers.
    */
   public function getPluginTypeConfiguration($scope, $type) {
-    return $this->getConfiguration("plugin.$scope.$type");
+    return $this->getConfiguration("plugin.factory.$scope.$type");
   }
 
   public function getPluginImplementations($scope, $type) {
diff --git a/core/includes/Drupal/Plugin/Core/AbstractBlock.php b/core/includes/Drupal/Plugin/Core/AbstractBlock.php
new file mode 100644 (file)
index 0000000..7fd4efe
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+namespace Drupal\Plugin\Core;
+use Drupal\Context\Context;
+use Drupal\Configuration\Configuration;
+
+/**
+ *
+ */
+abstract class AbstractBlock implements BlockInterface {
+  protected $config;
+  protected $contexts;
+
+  /**
+   * Implements PluginInterface::__construct().
+   */
+  public function __construct(Configuration $config, Context $contexts) {
+    $this->config = $config;
+    $this->contexts = $contexts;
+  }
+
+  /**
+   * Implements BlockInterface::build().
+   */
+  public function build() {}
+}
index 4c0cb33..e3def20 100644 (file)
@@ -1,15 +1,18 @@
 <?php
 
 namespace Drupal\Plugin\Core;
+use Drupal\Plugin\PluginInterface;
+use Drupal\Context\Context;
+use Drupal\Configuration\Configuration;
+use Drupal\Configuration\ConfigurationService;
 
 /**
  * Interface definition for Block plugins.
  */
-interface BlockInterface {
+interface BlockInterface extends PluginInterface {
 
   /**
-   *
+   * 
    */
-  public function __construct($config, $contexts);
-
+  public function build();
 }
diff --git a/core/includes/Drupal/Plugin/Core/Searchblock.php b/core/includes/Drupal/Plugin/Core/Searchblock.php
new file mode 100644 (file)
index 0000000..025988d
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+namespace Drupal\Plugin\Core;
+
+/**
+ *
+ */
+class Searchblock extends AbstractBlock {
+  public function build() {
+    return array(
+      '#access' => user_access('search content'),
+      '#block' => $this->config,
+      drupal_get_form('search_block_form'),
+    );
+  }
+}
diff --git a/core/includes/Drupal/Plugin/Core/SystemHelpBlock.php b/core/includes/Drupal/Plugin/Core/SystemHelpBlock.php
new file mode 100644 (file)
index 0000000..c206165
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace Drupal\Plugin\Core;
+
+/**
+ *
+ */
+class SystemHelpBlock extends AbstractBlock {
+  public function build() {
+    $help = menu_get_active_help();
+    $access = $help ? TRUE : FALSE;
+    return array(
+      '#block' => $this->config,
+      '#children' => $help,
+      '#access' => $access,
+    );
+  }
+}
diff --git a/core/includes/Drupal/Plugin/Core/SystemMainBlock.php b/core/includes/Drupal/Plugin/Core/SystemMainBlock.php
new file mode 100644 (file)
index 0000000..9540ed8
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+namespace Drupal\Plugin\Core;
+
+/**
+ *
+ */
+class SystemMainBlock extends AbstractBlock {
+  public function build() {
+    return array(
+      '#block' => $this->config,
+      drupal_set_page_content(),
+    );
+  }
+}
diff --git a/core/includes/Drupal/Plugin/Core/SystemMenuBlock.php b/core/includes/Drupal/Plugin/Core/SystemMenuBlock.php
new file mode 100644 (file)
index 0000000..60a6786
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\Plugin\Core;
+use Drupal\Plugin\PluginChildrenInterface;
+
+/**
+ *
+ */
+class SystemMenuBlock extends AbstractBlock implements PluginChildrenInterface {
+  protected $children;
+  protected $child;
+
+  public function getChild($child) {
+    $this->child = $child;
+    if (!isset($this->children[$child])) {
+      $this->getChildren();
+    }
+    return isset($this->children[$child]) ? $this->children[$child] : array();
+  }
+
+  public function getChildren() {
+    foreach (menu_list_system_menus() as $menu => $name) {
+      $this->children[$menu] = clone($this->config);
+      $this->children[$menu]->delta = $menu;
+      $this->children[$menu]->subject = $name;
+    }
+    return $this->children;
+  }
+
+  public function build() {
+    return array(
+      '#block' => $this->children[$this->child],
+      menu_tree($this->child),
+    );
+  }
+}
diff --git a/core/includes/Drupal/Plugin/Core/SystemPoweredByBlock.php b/core/includes/Drupal/Plugin/Core/SystemPoweredByBlock.php
new file mode 100644 (file)
index 0000000..233ca84
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+namespace Drupal\Plugin\Core;
+
+/**
+ *
+ */
+class SystemPoweredByBlock extends AbstractBlock {
+  public function build() {
+    return array(
+      '#block' => $this->config,
+      '#children' => theme('system_powered_by'),
+    );
+  }
+}
index b318519..3f0800e 100644 (file)
@@ -5,16 +5,11 @@ namespace Drupal\Plugin\Core;
 /**
  *
  */
-class Testblock implements BlockInterface {
-  protected $config;
-  protected $contexts;
-
-  /**
-   * Implements TestblockInterface::__construct().
-   */
-  public function __construct($config, $contexts) {
-    $this->config = $config;
-    $this->contexts = $contexts;
+class Testblock extends AbstractBlock {
+  public function build() {
+    return array(
+      '#block' => $this->config,
+      '#children' => $this->config->content,
+    );
   }
-
 }
index 228ded6..d8fbe72 100644 (file)
@@ -9,6 +9,7 @@ use Drupal\Context\Context;
 use Drupal\Configuration\Configuration;
 use Drupal\Configuration\ConfigurationService;
 use Drupal\Plugin\PluginException;
+use Drupal\Plugin\PluginChildrenInterface;
 
 /**
  * Default Drupal Multiconfig factory.
@@ -71,7 +72,11 @@ class Multiconfig implements FactoryInterface {
    */
   public function getInstance($options, Context $context) {
     list($plugin_class, $config) = $this->getConfiguration($options);
-    return new $plugin_class($config, $context);
+    $instance = new $plugin_class($config, $context);
+    if ($instance instanceof PluginChildrenInterface && isset($options['child'])) {
+      $instance->getChild($options['child']);
+    }
+    return $instance;
   }
 
 }
diff --git a/core/includes/Drupal/Plugin/PluginChildrenInterface.php b/core/includes/Drupal/Plugin/PluginChildrenInterface.php
new file mode 100644 (file)
index 0000000..3cdb752
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * @file
+ * Interface implemented by plugins needing children support.
+ */
+
+namespace Drupal\Plugin;
+
+/**
+ * Plugin interface for child plugin handling.
+ */
+interface PluginChildrenInterface extends PluginInterface {
+
+  public function getChild($child);
+
+  public function getChildren();
+
+}
diff --git a/core/includes/Drupal/Plugin/PluginInterface.php b/core/includes/Drupal/Plugin/PluginInterface.php
new file mode 100644 (file)
index 0000000..4268759
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * @file
+ * Interface implemented by all plugins.
+ */
+
+namespace Drupal\Plugin;
+use Drupal\Context\Context;
+use Drupal\Configuration\Configuration;
+use Drupal\Configuration\ConfigurationService;
+
+/**
+ * Plugin factory interface for child plugin handling.
+ */
+interface PluginInterface {
+
+  public function __construct(Configuration $config, Context $contexts);
+
+}
index ea6637d..2efbf50 100644 (file)
@@ -875,26 +875,39 @@ function block_block_list_alter(&$blocks) {
  */
 function _block_get_renderable_block($element) {
   $block = $element['#block'];
-
   // Render the block content if it has not been created already.
+  drupal_set_message('<pre>' . var_export($block->module . '.' . $block->delta, TRUE) . '</pre>');
   if (!isset($block->content)) {
-    $array = module_invoke($block->module, 'block_view', $block->delta);
-
-    // Allow modules to modify the block before it is viewed, via either
-    // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
-    drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block);
-
-    if (empty($array['content'])) {
-      // Blocks without content should emit no markup at all.
-      $element += array(
-        '#access' => FALSE,
-        '#printed' => TRUE,
-      );
-    }
-    elseif (isset($array) && is_array($array)) {
-      foreach ($array as $k => $v) {
-        $block->$k = $v;
-      }
+    switch ($block->module . '.' . $block->delta) {
+      case 'search.form':
+      case 'system.main':
+      case 'system.powered-by':
+      case 'system.help':
+        $options = array(
+          'config' => $block->module . '.' . $block->delta,
+        );
+        unset($element['#block']);
+        $instance = mapper()->getPluginInstance('core', 'block', $options);
+        $element += $instance->build();
+        break;
+      default:
+        $array = module_invoke($block->module, 'block_view', $block->delta);
+        // Allow modules to modify the block before it is viewed, via either
+        // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
+        drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block);
+    
+        if (empty($array['content'])) {
+          // Blocks without content should emit no markup at all.
+          $element += array(
+            '#access' => FALSE,
+            '#printed' => TRUE,
+          );
+        }
+        elseif (isset($array) && is_array($array)) {
+          foreach ($array as $k => $v) {
+            $block->$k = $v;
+          }
+        }
     }
   }
 
index 7761f02..dbdf131 100644 (file)
--- a/index.php
+++ b/index.php
@@ -18,6 +18,23 @@ define('DRUPAL_ROOT', getcwd());
 
 require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-//$instance = mapper()->getPluginInstance('core', 'block', array('config' => 'test'));
-//drupal_set_message('<pre>' . print_r($instance, TRUE) . '</pre>');
+/*$options = array(
+  array(
+    'config' => 'system.menu',
+    'child' => 'navigation',
+  ),
+  array(
+    'config' => 'system.menu',
+    'child' => 'user-menu',
+  ),
+);
+foreach ($options as $option) {
+  $block = array(
+    '#theme_wrappers' => array(
+      'block',
+    ),
+  );
+  $block += mapper()->getPluginInstance('core', 'block', $option)->build();
+  drupal_set_message(drupal_render($block));
+}*/
 menu_execute_active_handler();