View source
<?php
module_load_include('inc', 'patterns', 'theme/common');
module_load_include('inc', 'patterns', 'theme/modules');
function patterns_theme() {
return array(
'patterns_form_helper' => array(
'arguments' => array(
'form_id' => NULL,
'values' => NULL,
),
),
'patterns_form_helper_menu' => array(
'forms' => NULL,
),
'patterns_list' => array(
'variables' => array(
'patterns' => array(),
'invalid' => array(),
),
),
'patterns_patterns_fieldset' => array(
'render element' => 'form',
),
'patterns_extract_table' => array(
'render element' => 'form',
),
);
}
function theme_patterns_form_helper_menu($forms) {
$output = '<ul class="patterns-form-menu">';
foreach ($forms as $form_id => $values) {
$output .= '<li class="patterns-form-menu-item">' . $form_id . '</li>';
}
$output .= '</li>';
return $output;
}
function theme_patterns_form_helper($form_id, $values) {
$output = '<div class="patterns-form" id="patterns-form-' . $form_id . '">';
$output .= '<div class="patterns-form-title">' . t('Form values for %key', array(
'%key' => $form_id,
)) . '</div>';
foreach ($values as $key => $value) {
$output .= '<div class="patterns-form-item"><div class="patterns-form-key">' . $key . ' => </div>';
$output .= '<div class="patterns-form-value">' . print_r($value, TRUE) . '</div></div>';
}
$output .= '</div>';
return $output;
}
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">';
$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,
),
),
);
}
}
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);
}
function theme_patterns_patterns_fieldset($variables) {
$form = $variables['form'];
$rows = array();
foreach (element_children($form) as $key) {
$pattern = $form[$key];
$row = array();
unset($pattern['enable']['#title']);
$row[] = array(
'class' => array(
'checkbox',
),
'data' => drupal_render($pattern['enable']),
);
$label = '<label ';
if (isset($pattern['enable']['#id'])) {
$label .= ' for="' . $pattern['enable']['#id'] . '"';
}
$row[] = drupal_render($pattern['format']);
$row[] = $label . '><strong>' . drupal_render($pattern['name']) . '</strong></label>';
$row[] = drupal_render($pattern['title']);
$row[] = drupal_render($pattern['version']);
$description = drupal_render($pattern['description']);
$row[] = array(
'data' => $description,
'class' => array(
'description',
),
);
foreach ($pattern['links'] as $key => $value) {
$row[] = array(
'data' => $value,
);
}
$rows[] = $row;
}
return theme('table', array(
'header' => $form['#header'],
'rows' => $rows,
));
}
function _patterns_pattern_build_row($pid, $pattern, $options = array()) {
$extra = array(
'requires' => array(),
'required_by' => array(),
'disabled' => FALSE,
'enabled' => FALSE,
'links' => array(),
);
$form = array(
'#tree' => TRUE,
);
$title = '<span id="pid-' . $pid . '" class="pattern-title">' . $pattern->title . '</span>';
$info = array();
$info[] = t('Author:') . ' ' . @$pattern->info['author'];
$info[] = t('Email:') . ' ' . @$pattern->info['author_email'];
$info[] = t('Web:') . ' ' . @$pattern->info['author_website'];
$author = theme('item_list', array(
'items' => $info,
));
$title .= '<div id="pid-' . $pid . '-info" class="pattern-info">' . $author . '</div>';
$form['format'] = array(
'#markup' => $pattern->format,
);
$form['name'] = array(
'#markup' => $pattern->name,
);
$form['title'] = array(
'#markup' => $title,
);
$form['description'] = array(
'#markup' => $pattern->description,
);
$form['version'] = array(
'#markup' => @$pattern->info['version'],
);
$compatible = TRUE;
$status_short = '';
$status_long = '';
$compatible = TRUE;
if ($compatible) {
$form['enable'] = array(
'#markup' => $pattern->status ? t('Enabled') : t('Disabled'),
);
}
else {
$form['enable'] = array(
'#markup' => theme('image', array(
'path' => 'misc/watchdog-error.png',
'alt' => $status_short,
'title' => $status_short,
)),
);
$form['description']['#markup'] .= theme('system_modules_incompatible', array(
'message' => $status_long,
));
}
$actions = patterns_get_patterns_links($pattern);
$form['links'] = $actions;
return $form;
}
function theme_patterns_category_table($patterns) {
$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'),
t('Uri'),
),
);
return $form;
}