View source
<?php
define('NODE_PAGE_DISABLE_DEFAULT', TRUE);
function node_page_disable_menu_alter(&$items) {
global $_node_page_disable_restore_path_node_;
if (empty($_node_page_disable_restore_path_node_) && isset($items['node']) && !($keep = variable_get('node_page_disable_path_node_keep', NODE_PAGE_DISABLE_DEFAULT))) {
$frontpage = variable_get('site_frontpage', '');
if (!empty($frontpage) && $frontpage != 'node') {
unset($items['node']);
}
}
}
function node_page_disable_form_system_site_information_settings_alter(&$form, $form_state) {
if (!array_key_exists('site_frontpage', $form)) {
return;
}
$default = variable_get('node_page_disable_path_node_keep', NODE_PAGE_DISABLE_DEFAULT);
$front = variable_get('site_frontpage', FALSE);
$form['#node_page_disable']['node_page_disable_path_node_keep'] = $default;
$element = array(
'#type' => 'checkbox',
'#title' => t('Retain <a href="@url">/node</a> as an active url?', array(
'@url' => url('node'),
)),
'#default_value' => $default,
);
$splice = array_keys($form);
$splice = array_search('site_frontpage', $splice) + 1;
$form = array_slice($form, 0, $splice, TRUE) + array(
'node_page_disable_path_node_keep' => $element,
) + array_slice($form, $splice, NULL, TRUE);
$form['#submit'][] = 'node_page_disable_form_system_site_information_settings_submit';
array_unshift($form['#validate'], 'node_page_disable_form_system_site_information_settings_validate1');
$form['#validate'][] = 'node_page_disable_form_system_site_information_settings_validate2';
}
function _node_page_disable_restore_path_node() {
$errors = form_get_errors();
global $_node_page_disable_restore_path_node_;
$_node_page_disable_restore_path_node_ = TRUE;
variable_set('menu_rebuild_needed', TRUE);
}
function node_page_disable_form_system_site_information_settings_validate1($form, &$form_state) {
$frontpage = $form_state['values']['site_frontpage'];
if (($frontpage = '' || ($frontpage = 'node')) && !variable_get('node_page_disable_path_node_keep', NODE_PAGE_DISABLE_DEFAULT)) {
_node_page_disable_restore_path_node();
}
}
function node_page_disable_form_system_site_information_settings_validate2($form, &$form_state) {
if ($form_state['values']['site_frontpage'] == 'node') {
form_set_value($form['node_page_disable_path_node_keep'], TRUE, $form_state);
variable_set('menu_rebuild_needed', TRUE);
}
}
function node_page_disable_form_system_site_information_settings_submit($form, &$form_state) {
if ($form['#node_page_disable']['node_page_disable_path_node_keep'] != $form_state['values']['node_page_disable_path_node_keep']) {
variable_set('menu_rebuild_needed', TRUE);
}
}