From 484567ef5de666ed1a0ed8c4ae2c666258afdc73 Mon Sep 17 00:00:00 2001
From: Marc van Gend <marc@triquanta.nl>
Date: Wed, 24 Sep 2014 09:50:39 +0200
Subject: [PATCH] add psr-4 style block plugins

---
 src/Plugin/Block/FieldBlock.php   | 32 +++++++++++++++++++++++++++++++
 src/Plugin/Deriver/FieldBlock.php | 31 ++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 src/Plugin/Block/FieldBlock.php
 create mode 100644 src/Plugin/Deriver/FieldBlock.php

diff --git a/src/Plugin/Block/FieldBlock.php b/src/Plugin/Block/FieldBlock.php
new file mode 100644
index 0000000..f22265f
--- /dev/null
+++ b/src/Plugin/Block/FieldBlock.php
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\fieldblock\Plugin\Block\FieldBlock.
+ */
+
+namespace Drupal\fieldblock\Plugin\Block;
+use Drupal\Core\Block\BlockBase;
+
+/**
+ * Provides a fieldblock.
+ *
+ * @Block(
+ *   id = "fieldblock",
+ *   admin_label = @Translation("Fieldblock"),
+ *   deriver = "Drupal\fieldblock\Plugin\Deriver\FieldBlock"
+ * )
+ */
+class FieldBlock extends BlockBase {
+
+  /**
+   * Implements \Drupal\block\BlockBase::blockBuild().
+   */
+  public function build() {
+    $block_id = $this->getDerivativeId();
+    return array(
+      '#markup' => 'There are more like me!<br> I am ' . $block_id,
+    );
+  }
+
+}
diff --git a/src/Plugin/Deriver/FieldBlock.php b/src/Plugin/Deriver/FieldBlock.php
new file mode 100644
index 0000000..22410e2
--- /dev/null
+++ b/src/Plugin/Deriver/FieldBlock.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\fieldblock\Plugin\Derivative\FieldBlock.
+ */
+
+namespace Drupal\fieldblock\Plugin\Deriver;
+
+use Drupal\Component\Plugin\Derivative\DeriverBase;
+
+/**
+ * Provides block plugin definitions for fieldblock blocks.
+ *
+ * @see \Drupal\fieldblock\Plugin\Block\FieldBlock
+ */
+class FieldBlock extends DeriverBase {
+  /**
+   * {@inheritdoc}
+   */
+  public function getDeriverDefinitions($base_plugin_definition) {
+    $blocks = fieldblock_get_block_list();
+
+    foreach ($blocks as $fieldblock_id => $description) {
+      $this->derivatives[$fieldblock_id] = $base_plugin_definition;
+      $this->derivatives[$fieldblock_id]['admin_label'] = $description;
+    }
+
+    return $this->derivatives;
+  }
+}
-- 
GitLab