Index: multiblock.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/multiblock/multiblock.install,v retrieving revision 1.1.4.1 diff -u -r1.1.4.1 multiblock.install --- multiblock.install 23 Jun 2008 23:53:42 -0000 1.1.4.1 +++ multiblock.install 18 Jan 2009 17:13:05 -0000 @@ -1,5 +1,10 @@ 'Instances', - 'description' => t('Create and delete instances of blocks.'), + 'description' => 'Create and delete instances of blocks.', 'page callback' => 'multiblock_general', 'access callback' => 'user_access', 'access arguments' => array('administer blocks'), 'type' => MENU_LOCAL_TASK, 'weight' => -1, - ); + ); + $items['admin/build/block/blocked_modules'] = array( + 'title' => 'Blocked Modules', + 'description' => 'Block modules from instance creation.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('multiblock_blocked_modules'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 3, + ); $items['admin/build/block/instances/delete'] = array( 'title' => 'Delete Block Instance', 'page callback' => 'drupal_get_form', @@ -22,7 +37,7 @@ 'access callback' => 'user_access', 'access arguments' => array('administer blocks'), 'type' => MENU_CALLBACK, - ); + ); return $items; } @@ -30,19 +45,22 @@ * Implementation of hook_block(). */ function multiblock_block($op = 'list', $delta = 0, $edit = array()) { - if ($op == 'list') { - // Get all of the block instances that exist. - $blocks = multiblock_get_block(NULL); - $list = array(); - foreach ($blocks as $block) { -// $list[$block->delta] = array('info' => check_plain($block->title)); - $list[$block->delta] = array('info' => $block->title); - } - return $list; - } - // Any op besides list we want to dispatch the call to its respective module. - else if ($op == 'view' || $op == 'configure' || $op == 'save') { - return multiblock_call_block($delta, $op, $edit); + switch ($op) { + case 'mb_blocked': + return 'multiblock'; + + case 'list': + // Get all of the block instances that exist. + $blocks = multiblock_get_block(NULL); + $list = array(); + foreach ($blocks as $block) { + $list[$block->delta] = array('info' => $block->title); + } + return $list; + + // Any op besides list we want to dispatch the call to its respective module. + default: + return multiblock_call_block($delta, $op, $edit); } } @@ -138,26 +156,30 @@ else { // Turn $blocks into form options of block types. // Remember we need the module and delta to be able to tell what kind of - // blocks we're talking about. + // blocks we're talking about. + $blocked_modules = variable_get('multiblock_blocked', array('multiblock')); + $auto_blocked = module_invoke_all('block', 'mb_blocked'); + $blocked_modules = array_unique(array_merge($blocked_modules, $auto_blocked)); + $options = array(); foreach ($blocks as $block) { // Don't include multiblock module blocks in the list. - if ($block['module'] != 'multiblock') { + if (!in_array(strtolower($block['module']), $blocked_modules)) { $options[$block['module'] .'***MB***'. $block['delta']] = $block['info']; } } - + $form['block'] = array( '#type' => 'select', '#title' => t('Block type'), '#options' => $options, '#required' => TRUE, - ); + ); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), - ); + ); return $form; } @@ -331,3 +353,43 @@ return $output; } + +/** + * Build a blocked modules list to prevent instance creation. + */ +function multiblock_blocked_modules() { + $form = array(); + $current = variable_get('multiblock_blocked', array('multiblock')); + $x = array_keys($current, 'multiblock'); + unset ($current[$x[0]]); + + $form['blocked'] = array( + '#type' => 'textarea', + '#rows' => 10, + '#description' => t('Add modules, one per line, that will not be shown in the "Add Instance" list.'), + '#default_value' => implode("\n", $current), + ); + + $auto_blocked = module_invoke_all('block', 'mb_blocked'); + if ($auto_blocked) { + $form['blocked']['#description'] .= '
'. t('Note: The following modules are automatically blocked: @auto', array('@auto' => implode(', ', $auto_blocked))); + } + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + return $form; +} + +/** + * Process the blocked modules list. + */ +function multiblock_blocked_modules_submit($form, $form_state) { + $blocked = preg_split('/(\r\n?|\n)/', $form_state['values']['blocked']); + $blocked[] = 'multiblock'; + // Remove duplicates, empty lines, and excess spaces. + $blocked = array_map('trim', array_filter(array_unique($blocked))); + variable_set('multiblock_blocked', $blocked); + drupal_set_message(t('Configuration saved'), 'status'); +}