You are here

function context_ui_form_block_admin_configure_alter in Context 6

Same name and namespace in other branches
  1. 6.2 context_ui/context_ui.module \context_ui_form_block_admin_configure_alter()

Implementation of hook_form_alter() for block_admin_configure.

File

context_ui/context_ui.module, line 191

Code

function context_ui_form_block_admin_configure_alter(&$form, $form_state) {

  // Display context_ui visibility information on block configuration pages
  $module = $form['module']['#value'];
  $delta = $form['delta']['#value'];
  $rows = array();
  $contexts = context_enabled_contexts();
  foreach ($contexts as $context) {
    if (!empty($context->block)) {
      foreach ($context->block as $block) {

        // @TODO: normalize this to either an array or object. I apolgize for this sloppy shiz : |
        $block = (object) $block;
        if ($block->module == $module && $block->delta == $delta) {
          $row = array();
          $row[] = $context->namespace;
          $row[] = $context->attribute;
          $row[] = $context->value;
          $row[] = $block->region;
          $identifier = "{$context->namespace}-{$context->attribute}-{$context->value}";
          $options = array(
            'fragment' => 'context-ui-blocks',
            'query' => 'destination=' . $_GET['q'],
          );
          if ($context->system) {
            $row[] = l(t('Override visibility'), "admin/build/context/{$identifier}/clone", $options);
          }
          else {
            $row[] = l(t('Edit visibility'), "admin/build/context/{$context->cid}", $options);
          }
          $rows[] = $row;
        }
      }
    }
  }
  if ($rows) {
    $content = theme('table', array(
      t('Namespace'),
      t('Attribute'),
      t('Value'),
      t('Region'),
      '',
    ), $rows);
  }
  else {
    $content = "<p>" . t('No visibility rules have been set for this block using context_ui.') . "</p>";
  }
  $form['context_ui'] = array(
    '#type' => 'fieldset',
    '#title' => t('Context UI visibility'),
    '#weight' => -1,
    '#collapsible' => true,
  );
  $form['context_ui']['contexts'] = array(
    '#type' => 'item',
    '#value' => $content,
    '#description' => t('To add or remove block visibility rules based on context, use the !context_admin.', array(
      '!context_admin' => l(t('context administration page'), 'admin/build/context'),
    )),
  );
  $form['block_settings']['#weight'] = -5;
}