From 2c6ee6dee0279d141642e57221d9bb9d7837d6f5 Mon Sep 17 00:00:00 2001
From: Kyle Taylor <kyletaylored@gmail.com>
Date: Sun, 2 Nov 2014 11:37:07 -0600
Subject: [PATCH] Add option for appending existing block classes

---
 blocker.install              | 27 ++++++++++++++++++++++++++-
 blocker.module               | 27 +++++++++++++++------------
 modules/blocker_ui.admin.inc | 13 ++++++++++++-
 3 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/blocker.install b/blocker.install
index c043af7..aa61e6e 100644
--- a/blocker.install
+++ b/blocker.install
@@ -64,6 +64,13 @@ function blocker_schema() {
         'default' => '',
         'not null'    => TRUE,
       ),
+      'block_class_check' => array(
+        'description' => 'Check to use existing CSS classes.',
+        'type'        => 'int',
+        'size'        => 'tiny',
+        'not null'    => TRUE,
+        'default'     => 0,
+      ),
       'row' => array(
         'type'        => 'varchar',
         'length'      => 255,
@@ -134,4 +141,22 @@ function blocker_update_7100() {
     )
   );
   
-}
\ No newline at end of file
+}
+
+/**
+ * Add block_class check.
+ */
+function blocker_update_7101() {
+  // Add fields for block_class module.
+  db_add_field('blocker', 'block_class_check',
+    array(
+      'type'        => 'int',
+      'size'        => 'tiny',
+      'not null'    => TRUE,
+      'default'     => 0,
+      'description' => 'Check to use existing CSS classes.',
+    )
+  );
+  
+}
+
diff --git a/blocker.module b/blocker.module
index 2cf64f2..7292273 100644
--- a/blocker.module
+++ b/blocker.module
@@ -26,15 +26,15 @@ function blocker_get_blocks_list($region, $object, $account) {
   global $user;
   // No clean way to pass in url or user so override system and reset.
   $orig_q = $_GET['q'];
-//  $orig_user = $user;
+  // $orig_user = $user;
   
   $entity_uri = entity_uri($object->entity_type, $object);
   $_GET['q'] = $entity_uri['path'];
-//  $user = $account;
+  // $user = $account;
   
   $blocks = block_list($region);
   
-//  $user = $orig_user;
+  // $user = $orig_user;
   $_GET['q'] = $orig_q;
 
   // Unset static cache as it is storing the wrong results.
@@ -52,14 +52,16 @@ function blocker_get_blocks_list($region, $object, $account) {
       if ($blocker->title) {
         $block->title = $blocker->title;
       }
-      $block->css_class = $blocker->css_class;
+      // Append existing class if checked.
+      if ($blocker->block_class_check) {
+        $block->css_class = trim($block->css_class.' '.$blocker->css_class);
+      }
       $block->row = $blocker->row;
       $block->row_class = $blocker->row_class;
       $block->brid = $blocker->brid; // Save off brid to use later for edit link.
       $blocks[$block->module . '_' . $block->delta] = $block;
     }
   }
-  
   return $blocks;
 }
 
@@ -100,9 +102,13 @@ function blocker_page_build(&$page) {
       foreach($blockers as $brid => $blocker) {
         $block = block_load($blocker->module, $blocker->delta);
         $block->weight = $blocker->weight;
-        $block->css_class = $blocker->css_class;
         $block->row = $blocker->row;
         $block->row_class = $blocker->row_class;
+        
+        // Append existing class if checked.
+        if ($blocker->block_class_check) {
+          $block->css_class = trim($block->css_class.' '.$blocker->css_class);
+        }
         if ($blocker->title == '<none>') {
           $block->title = '';
         }
@@ -313,11 +319,8 @@ function blocker_form_block_admin_configure_alter(&$form, &$form_state, $form_id
  */
 function blocker_preprocess_block(&$variables, $hook) {
   $block = &$variables['block'];
-  if (isset($block->css_class)) {
-    foreach(explode(' ' , $block->css_class) as $class) {
-      if (!in_array($class, $variables['classes_array'])) {
-        $variables['classes_array'][] = $class;
-      }
-    }
+  // Use class application from block_class module
+  if (isset($block->css_class) && $block->css_class != '') {
+    $variables['classes_array'] = array_merge($variables['classes_array'], explode(' ', $block->css_class));
   }
 }
diff --git a/modules/blocker_ui.admin.inc b/modules/blocker_ui.admin.inc
index 8ff9e4e..fe8435d 100644
--- a/modules/blocker_ui.admin.inc
+++ b/modules/blocker_ui.admin.inc
@@ -80,13 +80,24 @@ function blocker_ui_edit_form($form, $form_state, $blocker) {
   );
   
   if (module_exists('block_class')) {
-    $form['css_class'] = array(
+    $form['block_class'] = array(
+      '#type' => 'fieldset',
+      '#collapsible' => FALSE,
+      '#collapsed' => FALSE,
+    );
+    $form['block_class']['css_class'] = array(
       '#type' => 'textfield',
       '#title' => t('CSS class(es)'),
       '#default_value' => isset($blocker->css_class) ? $blocker->css_class : '',
       '#description' => t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.'),
       '#maxlength' => 255,
     );
+    $form['block_class']['block_class_check'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Append existing CSS class(es)'),
+      '#default_value' => isset($blocker->block_class_check) ? $blocker->block_class_check : 0,
+      '#description' => t('If this block has existing CSS classes, you can choose to have them appended.'),
+    );
   }
   
   if (module_exists('block_row')) {
-- 
1.9.3 (Apple Git-50)

