function theme_themekey_rule_chain_form in ThemeKey 6.3
Same name and namespace in other branches
- 6.4 themekey_admin.inc \theme_themekey_rule_chain_form()
- 6.2 themekey_admin.inc \theme_themekey_rule_chain_form()
- 7.3 themekey_admin.inc \theme_themekey_rule_chain_form()
- 7 themekey_admin.inc \theme_themekey_rule_chain_form()
- 7.2 themekey_admin.inc \theme_themekey_rule_chain_form()
Themes themekey_rule_chain_form() and adds drag'n'drop features.
File
- ./
themekey_admin.inc, line 494
Code
function theme_themekey_rule_chain_form($form) {
themekey_admin_theme_warning();
$output = '';
$rows = array();
if (!empty($form['old_items'])) {
$num_childs = array();
$parents_disabled = array();
$attributes = variable_get('themekey_attributes', array());
foreach ($form['old_items'] as $key => $item) {
if (isset($item['property'])) {
$num_childs[$key] = 0;
$parents_disabled[$key] = FALSE;
if (!empty($parents_disabled[$item['parent']['#value']])) {
$form['old_items'][$key]['enabled']['#value'] = 0;
}
if (!$form['old_items'][$key]['enabled']['#value']) {
$parents_disabled[$key] = TRUE;
}
elseif ($item['parent']['#value']) {
$num_childs[$item['parent']['#value']]++;
}
}
}
foreach ($form['old_items'] as $key => $item) {
if (isset($item['property'])) {
$row = isset($form['old_items'][$key]['#attributes']) && is_array($form['old_items'][$key]['#attributes']) ? $form['old_items'][$key]['#attributes'] : array();
// Add special classes to be used for tabledrag.js.
$form['old_items'][$key]['id']['#attributes']['class'] = 'themekey-property-id';
$form['old_items'][$key]['parent']['#attributes']['class'] = 'themekey-property-parent';
$form['old_items'][$key]['weight']['#attributes']['class'] = 'themekey-property-weight';
// Add special classes to be used for themekey-properties.js.
$form['old_items'][$key]['property']['#attributes']['class'] = 'themekey-property-property themekey-fadeable';
$form['old_items'][$key]['wildcard']['#attributes']['class'] = 'themekey-property-wildcard themekey-fadeable';
$form['old_items'][$key]['operator']['#attributes']['class'] = 'themekey-fadeable';
$form['old_items'][$key]['value']['#attributes']['class'] = 'themekey-fadeable';
$form['old_items'][$key]['enabled']['#attributes']['class'] = 'themekey-property-enabled';
$form['old_items'][$key]['theme']['#attributes']['class'] = 'themekey-property-theme themekey-fadeable';
// form items of type markup don't have attributes
$form['old_items'][$key]['delete']['#value'] = str_replace('<a', '<a class="themekey-rule-delete-link"', $form['old_items'][$key]['delete']['#value']);
if ('drupal:path:wildcard' != $item['property']['#value']) {
$form['old_items'][$key]['wildcard']['#attributes']['style'] = 'display: none';
}
if ($num_childs[$key]) {
$form['old_items'][$key]['theme']['#attributes']['style'] = 'display: none';
// form items of type markup don't have attributes
$form['old_items'][$key]['delete']['#value'] = str_replace('<a', '<a style="display: none"', $form['old_items'][$key]['delete']['#value']);
}
if (!empty($parents_disabled[$item['parent']['#value']])) {
$form['old_items'][$key]['enabled']['#attributes']['style'] = 'display: none';
$form['old_items'][$key]['enabled']['#default_value'] = 0;
}
$elements = array();
$description = htmlentities(strip_tags($attributes[$form['old_items'][$key]['property']['#default_value']]['description']));
$description = str_replace('\'', '', $description);
$elements[] = array(
'data' => theme('indentation', $form['old_items'][$key]['depth']['#value']) . drupal_render($form['old_items'][$key]['id']) . drupal_render($form['old_items'][$key]['property']) . drupal_render($form['old_items'][$key]['wildcard']) . drupal_render($form['old_items'][$key]['operator']) . drupal_render($form['old_items'][$key]['value']) . '<a name="anchor-' . $key . '" href="#anchor-' . $key . '" id="' . form_clean_id('edit-old-items-' . $key . '-value-help') . '" class="themekey-fadeable" title="' . $description . '" onClick="alert(\'' . $description . '\')">?</a>',
'class' => 'themekey-properties-row',
);
$elements[] = array(
'data' => drupal_render($form['old_items'][$key]['theme']),
);
$elements[] = array(
'data' => drupal_render($form['old_items'][$key]['enabled']),
);
$elements[] = array(
'data' => drupal_render($form['old_items'][$key]['delete']),
);
$elements[] = array(
'data' => drupal_render($form['old_items'][$key]['parent']),
);
$elements[] = array(
'data' => drupal_render($form['old_items'][$key]['weight']),
);
$page_cache = $attributes[$form['old_items'][$key]['property']['#default_value']]['page cache'];
if ($form['old_items'][$key]['enabled']['#value']) {
themekey_page_cache_warning($page_cache);
}
$elements[] = array(
'data' => '<div id="' . form_clean_id('edit-old-items-' . $key . '-page-cache-icon') . '">' . theme('themekey_page_cache_icon', $page_cache) . '</div>',
);
$row['class'] = !empty($row['class']) ? $row['class'] . ' draggable' : 'draggable';
if (!$form['old_items'][$key]['enabled']['#value']) {
$row['class'] .= ' themekey-fade-out';
}
if (!$form['old_items'][$key]['parent']['#value']) {
$row['class'] .= ' themekey-top-level';
}
$row['id'] = 'themekey-properties-row-' . $key;
$row['data'] = $elements;
$rows[] = $row;
}
}
}
if (!empty($rows)) {
if (empty($form['pager']['#value'])) {
drupal_add_tabledrag('themekey-properties', 'match', 'parent', 'themekey-property-parent', 'themekey-property-parent', 'themekey-property-id', TRUE);
drupal_add_tabledrag('themekey-properties', 'order', 'sibling', 'themekey-property-weight');
}
$header = array(
array(
'data' => t('Theme Switching Rule Chain'),
),
array(
'data' => t('Theme'),
),
array(
'data' => t('Enabled'),
),
array(
'data' => t('Operation'),
),
array(
'data' => t('Parent'),
),
array(
'data' => t('Weight'),
),
array(
'data' => t('Page<br />Cache'),
),
);
$output .= theme('table', $header, $rows, array(
'id' => 'themekey-properties',
));
foreach ($num_childs as $parent => $num) {
$output .= '<input id="themekey-num-childs-' . $parent . '" type="hidden" value="' . $num . '"></input>';
}
}
$rows = array();
if (!empty($form['new_item'])) {
if (isset($form['new_item']['property'])) {
$row = isset($form['new_item']['#attributes']) && is_array($form['new_item']['#attributes']) ? $form['new_item']['#attributes'] : array();
// Add special classes to be used for themekey-properties.js.
$form['new_item']['property']['#attributes']['class'] = 'themekey-property-property';
$form['new_item']['wildcard']['#attributes']['class'] = 'themekey-property-wildcard';
if ('drupal:path:wildcard' != $form['new_item']['property']['#value']) {
$form['new_item']['wildcard']['#attributes']['style'] = 'display: none';
}
$elements = array();
$elements[] = t('New Rule:');
$elements[] = array(
'data' => drupal_render($form['new_item']['property']) . drupal_render($form['new_item']['wildcard']) . drupal_render($form['new_item']['operator']) . drupal_render($form['new_item']['value']),
'class' => 'themekey-properties-row',
);
$elements[] = array(
'data' => drupal_render($form['new_item']['theme']),
);
$elements[] = array(
'data' => drupal_render($form['new_item']['enabled']),
);
$row['data'] = $elements;
$rows[] = $row;
}
}
if (!empty($rows)) {
$header = array(
'',
array(
'data' => t('Theme Switching Rule'),
),
array(
'data' => t('Theme'),
),
array(
'data' => t('Enabled'),
),
);
$output .= '<a name="themekey_new_rule"></a>';
$output .= theme('table', $header, $rows, array(
'id' => 'themekey-new-item',
));
}
$output .= drupal_render($form);
drupal_add_css(drupal_get_path('module', 'themekey') . '/themekey_properties.css');
drupal_add_js(drupal_get_path('module', 'themekey') . '/themekey_properties.js');
return $output;
}