From 73f6988e74641443f06c247badde04bcfd533efa Mon Sep 17 00:00:00 2001
From: damiankloip <damiankloip@1037976.no-reply.drupal.org>
Date: Wed, 17 Oct 2012 18:31:40 +0200
Subject: [PATCH] Issue #1808670 by dawehner, damiankloip: Added Provide a way
 for area handlers to be available by area type.

---
 lib/Drupal/views/Tests/ViewsDataTest.php | 26 ++++++++++++++++++++++++
 modules/views.views.inc                  |  1 +
 views_ui/admin.inc                       | 10 +++++++--
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/views/Tests/ViewsDataTest.php b/lib/Drupal/views/Tests/ViewsDataTest.php
index 1ad72a3d4e4b..6b16a82a2783 100644
--- a/lib/Drupal/views/Tests/ViewsDataTest.php
+++ b/lib/Drupal/views/Tests/ViewsDataTest.php
@@ -61,6 +61,11 @@ protected function viewsData() {
     unset($data['views_test_data']['age']['filter']);
     unset($data['views_test_data']['job']['sort']);
     $data['views_test_data']['created']['area']['id'] = 'text';
+    $data['views_test_data']['age']['area']['id'] = 'text';
+    $data['views_test_data']['age']['area']['sub_type'] = 'header';
+    $data['views_test_data']['job']['area']['id'] = 'text';
+    $data['views_test_data']['job']['area']['sub_type'] = array('header', 'footer');
+
 
     return $data;
   }
@@ -99,6 +104,17 @@ public function testViewsFetchFields() {
       ),
       'area' => array(
         'created',
+        'job',
+        'age'
+      ),
+      'header' => array(
+        'created',
+        'job',
+        'age'
+      ),
+      'footer' => array(
+        'created',
+        'job',
       ),
     );
 
@@ -110,6 +126,16 @@ public function testViewsFetchFields() {
       });
       $this->assertEqual($expected_keys, array_keys($fields), format_string('Handlers of type @handler_type are listed as expected.', array('@handler_type' => $handler_type)));
     }
+
+    // Check for subtype filtering, so header and footer.
+    foreach (array('header', 'footer') as $sub_type) {
+      $fields = views_fetch_fields('views_test_data', 'area', FALSE, $sub_type);
+
+      $expected_keys = array_walk($expected[$sub_type], function(&$item) {
+        $item = "views_test_data.$item";
+      });
+      $this->assertEqual($expected_keys, array_keys($fields), format_string('Sub_type @sub_type is filtered as expected.', array('@sub_type' => $sub_type)));
+    }
   }
 
 }
diff --git a/modules/views.views.inc b/modules/views.views.inc
index baee98ca352c..069dd99150c3 100644
--- a/modules/views.views.inc
+++ b/modules/views.views.inc
@@ -70,6 +70,7 @@ function views_views_data() {
     'help' => t('Override the default view title for this view. This is useful to display an alternative title when a view is empty.'),
     'area' => array(
       'id' => 'title',
+      'sub_type' => 'empty',
     ),
   );
 
diff --git a/views_ui/admin.inc b/views_ui/admin.inc
index f272009001ff..b6a9db2c01f2 100644
--- a/views_ui/admin.inc
+++ b/views_ui/admin.inc
@@ -1549,7 +1549,7 @@ function views_ui_add_item_form($form, &$form_state) {
 
   // Figure out all the base tables allowed based upon what the relationships provide.
   $base_tables = $view->getBaseTables();
-  $options = views_fetch_fields(array_keys($base_tables), $type, $display->useGroupBy());
+  $options = views_fetch_fields(array_keys($base_tables), $type, $display->useGroupBy(), $form_state['type']);
 
   if (!empty($options)) {
     $form['options']['controls'] = array(
@@ -2558,11 +2558,14 @@ function _views_sort_types($a, $b) {
  *   The handler type, for example field or filter.
  * @param bool $grouping
  *   Should the result grouping by its 'group' label.
+ * @param string $sub_type
+ *   An optional sub type. E.g. Allows making an area plugin available for
+ *   header only, instead of header, footer, and empty regions.
  *
  * @return array
  *   A keyed array of in the form of 'base_table' => 'Description'.
  */
-function views_fetch_fields($base, $type, $grouping = FALSE) {
+function views_fetch_fields($base, $type, $grouping = FALSE, $sub_type = NULL) {
   static $fields = array();
   if (empty($fields)) {
     $data = views_fetch_data();
@@ -2597,6 +2600,9 @@ function views_fetch_fields($base, $type, $grouping = FALSE) {
             if ($grouping && !empty($info[$key]['no group by'])) {
               continue;
             }
+            if ($sub_type && isset($info[$key]['sub_type']) && (!in_array($sub_type, (array) $info[$key]['sub_type']))) {
+              continue;
+            }
             if (!empty($info[$key]['skip base'])) {
               foreach ((array) $info[$key]['skip base'] as $base_name) {
                 $skip_bases[$field][$key][$base_name] = TRUE;
-- 
GitLab