You are here

function theme_panels_common_context_list in Panels 6.2

Same name and namespace in other branches
  1. 5.2 includes/common.inc \theme_panels_common_context_list()

Create a visible list of all the contexts available on an object. Assumes arguments, relationships and context objects.

Contexts must be preloaded.

2 theme calls to theme_panels_common_context_list()
panels_mini_edit_form in panels_mini/panels_mini.admin.inc
Form to edit the settings of a mini panel.
panels_page_edit_form in panels_page/panels_page.admin.inc
The form to edit the page portion of a panel.

File

includes/common.inc, line 496
Functions used by more than one panels client module.

Code

function theme_panels_common_context_list($object, $header = '') {
  $titles = array();
  $output = '';
  $count = 1;

  // Describe 'built in' contexts.
  if (!empty($object->base_contexts)) {
    foreach ($object->base_contexts as $id => $context) {
      $output .= '<tr>';
      $output .= '<td valign="top"><em>' . t('Built in context') . '</em></td>';
      $desc = check_plain($context->identifier);
      if (isset($context->keyword)) {
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array(
          '@keyword' => $context->keyword,
        )) . '</div>';
      }
      if (isset($context->description)) {
        $desc .= '<div class="description">' . filter_xss_admin($context->description) . '</div>';
      }
      $output .= '<td>' . $desc . '</td>';
      $output .= '</tr>';
      $titles[$id] = $context->identifier;
      $count++;
    }
  }

  // First, make a list of arguments. Arguments are pretty simple.
  if (!empty($object->arguments)) {
    foreach ($object->arguments as $argument) {
      $output .= '<tr>';
      $output .= '<td valign="top"><em>' . t('Argument @count', array(
        '@count' => $count,
      )) . '</em></td>';
      $desc = check_plain($argument['identifier']);
      if (isset($argument['keyword'])) {
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array(
          '@keyword' => $argument['keyword'],
        )) . '</div>';
      }
      $output .= '<td>' . $desc . '</td>';
      $output .= '</tr>';
      $titles[panels_context_id($argument, 'argument')] = $argument['identifier'];
      $count++;
    }
  }
  $count = 1;

  // Then, make a nice list of contexts.
  if (!empty($object->contexts)) {
    foreach ($object->contexts as $context) {
      $output .= '<tr>';
      $output .= '<td><em>' . t('Context @count', array(
        '@count' => $count,
      )) . '</em></td>';
      $desc = check_plain($context['identifier']);
      if (isset($context['keyword'])) {
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array(
          '@keyword' => $context['keyword'],
        )) . '</div>';
      }
      $output .= '<td>' . $desc . '</td>';
      $output .= '</tr>';
      $titles[panels_context_id($context)] = $context['identifier'];
      $count++;
    }
  }

  // And relationships
  if (!empty($object->relationships)) {
    foreach ($object->relationships as $relationship) {
      $output .= '<tr>';
      $output .= '<td valign="top"><em>' . t('From "@title"', array(
        '@title' => $titles[$relationship['context']],
      )) . '</em></td>';
      $desc = check_plain($relationship['identifier']);
      if (isset($relationship['keyword'])) {
        $desc .= '<div class="description">' . t('Keyword: %@keyword', array(
          '@keyword' => $relationship['keyword'],
        )) . '</div>';
      }
      $output .= '<td>' . $desc . '</td>';
      $output .= '</tr>';
      $titles[panels_context_id($relationship, 'relationship')] = $relationship['identifier'];
      $count++;
    }
  }
  if ($output) {
    $head = '';
    if ($header) {
      $head .= '<thead><tr>';
      $head .= '<th colspan="2">' . $header . '</th>';
      $head .= '</tr></thead>';
    }
    return "<table>{$head}<tbody>{$output}</tbody></table>\n";
  }
}