You are here

function theme_patterns_list in Patterns 7

Same name and namespace in other branches
  1. 7.2 theme/theme.inc \theme_patterns_list()

Theme a list of patterns into separated fieldset ordered by category

Parameters

array $args An associative array containing: containing key 'patterns':

3 theme calls to theme_patterns_list()
patterns_io_get_patterns_service in includes/io/io.inc
Prints an HTML formatted list of patterns.
patterns_list in ./patterns.module
First function to be called for displaying the pattern list page.
patterns_list_public in ./patterns.module

File

theme/theme.inc, line 87

Code

function theme_patterns_list($args) {
  drupal_add_js('misc/collapse.js');
  drupal_add_js('misc/drupal.js');
  $patterns = $args[PATTERNS_STATUS_OK];
  $removed = $args[PATTERNS_STATUS_TRASHED];
  $patterns_title = '<div id="all_patterns_div">';

  //if (!patterns_utils_is_public_page_enabled()) {

  //  if (!patterns_parser_ready()) {
  //    $patterns_title .= t('No available patterns parser was found. Please enable one from the Modules page.');
  //  }

  //}
  $form['patterns'] = array(
    '#prefix' => $patterns_title,
    '#suffix' => ' </div>',
    '#tree' => TRUE,
  );
  if (empty($patterns)) {
    $form['patterns']['#markup'] = t('No patterns available.');
  }
  else {
    foreach ($patterns as $pid => $pattern) {
      if (patterns_utils_is_public_page()) {
        if (!$pattern->public) {
          continue;
        }
      }
      $category = $pattern->info['category'] ? $pattern->info['category'] : t('Other');
      $form['patterns'][$category][] = _patterns_pattern_build_row($pid, $pattern);
      $form['patterns'][$category] += array(
        '#type' => 'fieldset',
        '#title' => $category,
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#theme' => 'patterns_patterns_fieldset',
        '#header' => array(
          array(
            'data' => t('Enabled'),
            'class' => array(
              'checkbox',
            ),
          ),
          t('Format'),
          t('Name'),
          t('Title'),
          t('Version'),
          t('Description'),
          array(
            'data' => t('Operations'),
            'colspan' => 7,
          ),
        ),
      );
    }
  }

  // Page finishes here if this is the public
  if (patterns_utils_is_public_page()) {
    return drupal_render($form);
  }
  $form['removed'] = array(
    '#prefix' => '<div id="removed_patterns_div"><h3>' . t('Removed Patterns') . '</h3>',
    '#suffix' => ' </div>',
    '#tree' => TRUE,
  );
  if (empty($removed)) {
    $form['removed']['#markup'] = t('No patterns in the recycle bin.');
  }
  else {
    foreach ($removed as $pid => $pattern) {
      $category = $pattern->info['category'] ? $pattern->info['category'] : t('Other');
      $form['removed'][$category][] = _patterns_pattern_build_row($pid, $pattern);
      $form['removed'][$category] += array(
        '#type' => 'fieldset',
        '#title' => $category,
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#theme' => 'patterns_patterns_fieldset',
        '#header' => array(
          array(
            'data' => t('Enabled'),
            'class' => array(
              'checkbox',
            ),
          ),
          t('Format'),
          t('Name'),
          t('Title'),
          t('Version'),
          t('Description'),
          array(
            'data' => t('Operations'),
            'colspan' => 7,
          ),
        ),
      );
    }
  }
  return drupal_render($form);
}