View source
<?php
define('OVERRIDE_CSS_SETTINGS_PATH', 'admin/appearance/override_css/settings');
function override_css_settings_menu() {
$items = array();
if (variable_get('override_css_settings_enabled', FALSE)) {
$basepath = variable_get('override_css_settings_path', OVERRIDE_CSS_SETTINGS_PATH);
$arg_counter = count(explode('/', $basepath));
$items[$basepath] = array(
'title' => variable_get('override_css_settings_title', 'Override theme'),
'page callback' => 'override_css_settings_page',
'access arguments' => array(
'override css settings',
),
'type' => variable_get('override_css_settings_type', MENU_LOCAL_TASK),
'weight' => 1,
);
$items[$basepath . '/%override_css_selector/values'] = array(
'title' => 'Values',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'override_css_selector_value',
$arg_counter,
TRUE,
),
'access arguments' => array(
'override css settings',
),
'type' => MENU_LOCAL_TASK,
'file' => 'override_css.admin.inc',
'file path' => drupal_get_path('module', 'override_css'),
'weight' => -10,
);
$items[$basepath . '/%override_css_selector/reset'] = array(
'title' => 'Reset',
'page callback' => 'override_css_reset_selector_page',
'page arguments' => array(
$arg_counter,
TRUE,
),
'access arguments' => array(
'override css settings',
),
'type' => MENU_LOCAL_TASK,
'file' => 'override_css.admin.inc',
'file path' => drupal_get_path('module', 'override_css'),
'weight' => -9,
);
}
return $items;
}
function override_css_settings_page() {
$output = '';
$output .= override_css_settings_table();
$output .= drupal_render(drupal_get_form('override_css_settings_form'));
return $output;
}
function override_css_settings_form() {
$form = array();
$form['override_css_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#collapsible' => FALSE,
);
$form['override_css_settings']['override_css_settings_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable theme override.'),
'#default_value' => variable_get('override_css_settings_enabled', TRUE),
'#description' => t('Disable all your overrides without deleting them.'),
);
return system_settings_form($form);
}
function override_css_settings_table() {
drupal_add_css(drupal_get_path('module', 'override_css_settings') . '/override_css_settings.css');
$groups = override_css_selector_load_all();
$header = array(
t('Title'),
t('Description'),
t('Actions'),
);
$bundles = array();
foreach ($groups as $name => $group) {
if (variable_get('override_css_bundle_enabled', FALSE)) {
$bundles[$group['bundle']][$name] = $group;
}
else {
$bundles[][$name] = $group;
}
}
ksort($bundles);
$rows = array();
$active_bundle_name = '';
foreach ($bundles as $bundle_name => $groups) {
if (variable_get('override_css_bundle_enabled', FALSE) && $active_bundle_name != $bundle_name) {
$rows[] = array(
array(
'data' => $bundle_name,
'colspan' => array(
3,
),
'class' => 'bundle-row',
),
);
$active_bundle_name = $bundle_name;
}
foreach ($groups as $name => $group) {
$actions = array(
l(t('edit'), variable_get('override_css_settings_path', OVERRIDE_CSS_SETTINGS_PATH) . '/' . $name . '/values'),
);
if (count($group['properties_values'])) {
$actions[] = l(t('reset'), variable_get('override_css_settings_path', OVERRIDE_CSS_SETTINGS_PATH) . '/' . $name . '/reset');
}
$rows[] = array(
(variable_get('override_css_bundle_enabled', FALSE) ? ' - ' : '') . $group['title'],
$group['description'],
theme('item_list', array(
'items' => $actions,
'attributes' => array(
'class' => 'inline',
),
)),
);
}
}
return theme('table', array(
'header' => $header,
'rows' => $rows,
'empty' => t('No selector groups defined.'),
));
}
function override_css_settings_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'override_css_reset_selector_form':
case 'override_css_selector_value':
if (!user_access('override css admin') && variable_get('override_css_settings_enabled', FALSE)) {
$form_state['redirect'] = variable_get('override_css_settings_path', OVERRIDE_CSS_SETTINGS_PATH);
}
break;
}
}
function override_css_settings_form_override_css_admin_form_alter(&$form, &$form_state, $form_id) {
$form['override_css_settings_path_settings'] = array(
'#type' => 'fieldset',
'#title' => 'Properties of override css path.',
);
$form['override_css_settings_path_settings']['override_css_settings_enabled'] = array(
'#type' => 'checkbox',
'#title' => 'Enable simple settings page',
'#default_value' => variable_get('override_css_settings_enabled', FALSE),
);
$form['override_css_settings_path_settings']['override_css_settings_title'] = array(
'#type' => 'textfield',
'#title' => 'Title',
'#default_value' => variable_get('override_css_settings_title', 'Override theme'),
'#states' => array(
'invisible' => array(
':input[name="override_css_settings_enabled"]' => array(
'checked' => FALSE,
),
),
),
);
$form['override_css_settings_path_settings']['override_css_settings_path'] = array(
'#type' => 'textfield',
'#title' => 'Path',
'#default_value' => variable_get('override_css_settings_path', OVERRIDE_CSS_SETTINGS_PATH),
'#states' => array(
'invisible' => array(
':input[name="override_css_settings_enabled"]' => array(
'checked' => FALSE,
),
),
),
);
$form['override_css_settings_path_settings']['override_css_settings_type'] = array(
'#type' => 'select',
'#title' => 'Menu type',
'#default_value' => variable_get('override_css_settings_type', MENU_LOCAL_TASK),
'#options' => array(
MENU_LOCAL_TASK => t('Tab'),
MENU_NORMAL_ITEM => t('Normal'),
),
'#states' => array(
'invisible' => array(
':input[name="override_css_settings_enabled"]' => array(
'checked' => FALSE,
),
),
),
);
$form['#submit'][] = 'override_css_settings_form_submit';
}
function override_css_settings_form_submit($form, &$form_state) {
menu_rebuild();
}