function theme_themekey_rule_chain_form in ThemeKey 7
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()
- 6.3 themekey_admin.inc \theme_themekey_rule_chain_form()
- 7.3 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 528
Code
function theme_themekey_rule_chain_form($variables) {
$form = $variables['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 (is_numeric($key) && !empty($item['property'])) {
$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 (!empty($item['parent']['#value'])) {
$num_childs[$item['parent']['#value']] = empty($num_childs[$item['parent']['#value']]) ? 1 : $num_childs[$item['parent']['#value']] + 1;
}
}
}
foreach ($form['old_items'] as $key => $item) {
if (is_numeric($key) && !empty($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'] = array(
'themekey-property-id',
);
$form['old_items'][$key]['parent']['#attributes']['class'] = array(
'themekey-property-parent',
);
$form['old_items'][$key]['weight']['#attributes']['class'] = array(
'themekey-property-weight',
);
// Add special classes to be used for themekey-properties.js.
$form['old_items'][$key]['property']['#attributes']['class'] = array(
'themekey-property-property themekey-fadeable',
);
$form['old_items'][$key]['wildcard']['#attributes']['class'] = array(
'themekey-property-wildcard themekey-fadeable',
);
$form['old_items'][$key]['operator']['#attributes']['class'] = array(
'themekey-fadeable',
);
$form['old_items'][$key]['value']['#attributes']['class'] = array(
'themekey-fadeable',
);
$form['old_items'][$key]['enabled']['#attributes']['class'] = array(
'themekey-property-enabled',
);
$form['old_items'][$key]['theme']['#attributes']['class'] = array(
'themekey-property-theme themekey-fadeable',
);
// form items of type markup don't have attributes
$form['old_items'][$key]['delete']['#markup'] = str_replace('<a', '<a class="themekey-rule-delete-link"', $form['old_items'][$key]['delete']['#markup']);
if ('drupal:path:wildcard' != $item['property']['#value']) {
$form['old_items'][$key]['wildcard']['#attributes']['style'] = 'display: none';
}
if (!empty($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']['#markup'] = str_replace('<a', '<a style="display: none"', $form['old_items'][$key]['delete']['#markup']);
}
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', array(
'size' => $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="' . drupal_clean_css_identifier('edit-old-items-' . $key . '-value-help') . '" class="themekey-fadeable" title="' . $description . '" onClick="alert(\'' . $description . '\')">?</a>',
'class' => array(
'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="' . drupal_clean_css_identifier('edit-old-items-' . $key . '-page-cache-icon') . '">' . theme('themekey_page_cache_icon', array(
'page_cache_support' => $page_cache,
)) . '</div>',
);
$row['class'][] = '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(
t('Theme Switching Rule Chain'),
t('Theme'),
t('Enabled'),
t('Operation'),
t('Parent'),
t('Weight'),
t('Page<br />Cache'),
);
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => 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'] = array(
'themekey-property-property',
);
$form['new_item']['wildcard']['#attributes']['class'] = array(
'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' => array(
'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(
'',
t('Theme Switching Rule'),
t('Theme'),
t('Enabled'),
);
$output .= '<a name="themekey_new_rule"></a>';
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'themekey-new-item',
),
));
}
$output .= drupal_render_children($form);
drupal_add_css(drupal_get_path('module', 'themekey') . '/themekey_rule_chain.admin.css');
drupal_add_js(drupal_get_path('module', 'themekey') . '/themekey_rule_chain.admin.js');
return $output;
}