simplify.module in Simplify 7.2
Same filename and directory in other branches
Simplifies the admin interface.
File
simplify.moduleView source
<?php
/**
* @file
* Simplifies the admin interface.
*/
/**
* Implements hook_help().
*/
function simplify_help($path, $arg) {
switch ($path) {
case 'admin/config/user-interface/simplify':
$output = '<p>' . t('Check boxes to hide those items from the admin interface.') . '</p>';
return $output;
case 'admin/help#simplify':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Simplify module offers the ability to simplify the admin interface through simple on/off checkboxes. If desired, you may disable the Simplify module from the <a href="@modules">Module administration page</a>. See the <a href="@project">Simplify project page</a> page for more information.', array(
'@modules' => url('admin/modules'),
'@project' => 'http://drupal.org/project/simplify',
)) . '</p>';
return $output;
}
}
/**
* Implements hook_permission().
*/
function simplify_permission() {
return array(
'administer simplify' => array(
'title' => t('Administer simplify'),
),
'simplify node hide settings' => array(
'title' => t('Simplify node hide settings'),
),
);
}
/**
* Implements hook_menu().
*/
function simplify_menu() {
$items = array();
$items['admin/config/user-interface/simplify'] = array(
'title' => 'Simplify',
'description' => 'Adjust Simplify configuration options.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplify_admin_settings',
),
'access arguments' => array(
'administer simplify',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_form_alter().
*/
function simplify_form_alter(&$form, &$form_state, $form_id) {
global $user;
switch ($form_id) {
case '_node_form' == drupal_substr($form_id, -10):
// All nodes forms
// Check role to hide items, but never show for administrator
if (1 != $user->uid && user_access('simplify node hide settings')) {
$node_types = node_type_get_types();
// Add general node to list of node types (all nodes)
array_push($node_types, array(
'type' => 'node',
));
foreach ($node_types as $key => $value) {
$value = (array) $value;
if (str_replace('_node_form', '', $form_id) == $value['type'] || 'node' == $value['type']) {
simplify_form_alter_unset($form, (array) $value);
}
}
}
}
}
/**
* Hide specified form items.
*/
function simplify_form_alter_unset(&$form, $node_type) {
$node_type_type = $node_type['type'];
$simplify_node_type = $node_type_type == 'node' ? '' : '_' . $node_type_type;
// Hide specified form items if they are checked
if (variable_get('simplify' . $simplify_node_type . '_node_hide_filter')) {
drupal_add_js('jQuery().ready(function(){jQuery(".filter-wrapper").hide();});', 'inline');
}
if (variable_get('simplify' . $simplify_node_type . '_node_hide_menu')) {
$form['menu']['#access'] = FALSE;
}
if (variable_get('simplify' . $simplify_node_type . '_node_hide_revision_information')) {
$form['revision_information']['#access'] = FALSE;
}
if (variable_get('simplify' . $simplify_node_type . '_node_hide_path')) {
$form['path']['#access'] = FALSE;
}
if (variable_get('simplify' . $simplify_node_type . '_node_hide_comment_settings')) {
$form['comment_settings']['#access'] = FALSE;
}
if (variable_get('simplify' . $simplify_node_type . '_node_hide_author')) {
$form['author']['#access'] = FALSE;
}
if (variable_get('simplify' . $simplify_node_type . '_node_hide_options')) {
$form['options']['#access'] = FALSE;
}
}
/**
* Form builder. Simplify admin settings.
*/
function simplify_admin_settings() {
$form = array();
$node_types = node_type_get_types();
// Add general node to list of node types (all nodes)
array_unshift($node_types, array(
'type' => 'node',
'name' => 'All',
));
foreach ($node_types as $key => $value) {
simplify_get_admin_settings_array($form, (array) $value);
}
return system_settings_form($form);
}
/**
* Array builder. Simplify admin settings.
*/
function simplify_get_admin_settings_array(&$form, $node_type) {
$node_type_type = $node_type['type'];
$node_type_name = $node_type['name'];
$form['simplify'][$node_type_type] = array(
'#type' => 'fieldset',
'#title' => t($node_type_name),
'#description' => '<p>' . t("Checked settings apply to {$node_type_name} nodes.") . '</p>',
);
$simplify_node_type = $node_type_type == 'node' ? '' : '_' . $node_type_type;
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_filter'] = array(
'#type' => 'checkbox',
'#title' => t('Hide text format settings'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_filter'),
);
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_menu'] = array(
'#type' => 'checkbox',
'#title' => t('Hide menu settings'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_menu'),
);
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_revision_information'] = array(
'#type' => 'checkbox',
'#title' => t('Hide revision information'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_revision_information'),
);
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_path'] = array(
'#type' => 'checkbox',
'#title' => t('Hide path settings'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_path'),
);
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_comment_settings'] = array(
'#type' => 'checkbox',
'#title' => t('Hide comment settings'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_comment_settings'),
);
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_author'] = array(
'#type' => 'checkbox',
'#title' => t('Hide author information'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_author'),
);
$form['simplify'][$node_type_type]['simplify' . $simplify_node_type . '_node_hide_options'] = array(
'#type' => 'checkbox',
'#title' => t('Hide publishing options'),
'#default_value' => variable_get('simplify' . $simplify_node_type . '_node_hide_options'),
);
}
Functions
Name | Description |
---|---|
simplify_admin_settings | Form builder. Simplify admin settings. |
simplify_form_alter | Implements hook_form_alter(). |
simplify_form_alter_unset | Hide specified form items. |
simplify_get_admin_settings_array | Array builder. Simplify admin settings. |
simplify_help | Implements hook_help(). |
simplify_menu | Implements hook_menu(). |
simplify_permission | Implements hook_permission(). |