diff --git a/refresh.install b/refresh.install old mode 100644 new mode 100755 index 5ecd859..d5a287e --- a/refresh.install +++ b/refresh.install @@ -17,7 +17,11 @@ function refresh_install() { * Implementation of hook_uninstall(). */ function refresh_uninstall() { - drupal_set_message(st('Refresh was uninstalled successfully.')); + foreach (node_type_get_names('names') as $type => $type_name) { + variable_del('refresh_' . $type); + } + + drupal_set_message(st('Refresh was uninstalled successfully.')); } diff --git a/refresh.js b/refresh.js old mode 100644 new mode 100755 index 73274d1..7881d88 --- a/refresh.js +++ b/refresh.js @@ -13,4 +13,21 @@ Drupal.behaviors.refreshFieldsetSummaries = { } }; +Drupal.behaviors.ctRefreshFieldsetSummaries = { + attach: function (context) { + $('fieldset#edit-refresh-fs', context).drupalSetSummary(function (context) { + + // Retrieve the value of the selected radio button + var refresh = $("input[name=refresh]:checked").val(); + + if (refresh==0) { + return Drupal.t('Disabled'); + } + else if (refresh==1) { + return Drupal.t('Enabled'); + } + }); + } +}; + })(jQuery); diff --git a/refresh.module b/refresh.module old mode 100644 new mode 100755 index 2a3a728..edbde5b --- a/refresh.module +++ b/refresh.module @@ -5,6 +5,9 @@ * Provides a configurable meta refresh when viewing individual nodes. */ +define('REFRESH_DISABLED', 0); +define('REFRESH_ENABLED', 1); + /** * Implementation of hook_permission(). * Creates two new permissions: one to create refreshes and one the change @@ -28,36 +31,38 @@ function refresh_permission() { * Adds a refresh group and numeric edit field to the node editing form. */ function refresh_form_node_form_alter(&$form, $form_state) { - if (isset($form['#node']->refresh)) { - $refresh = $form['#node']->refresh; - } - else { - $refresh = 0; + if (refresh_get_setting($form['#node']->type) == REFRESH_ENABLED){ + if (isset($form['#node']->refresh)) { + $refresh = $form['#node']->refresh; + } + else { + $refresh = 0; + } + $form['refresh'] = array( + '#type' => 'fieldset', + '#title' => t('Refresh settings'), + '#collapsible' => TRUE, + '#collapsed' => empty($refresh), + '#access' => user_access('create refreshes'), + '#weight' => 30, + '#group' => 'additional_settings', + '#attributes' => array( + 'class' => array('refresh-form'), + ), + '#attached' => array( + 'js' => array(drupal_get_path('module', 'refresh') . '/refresh.js'), + ), + ); + $form['refresh']['refresh'] = array( + '#type' => 'textfield', + '#default_value' => $refresh, + '#maxlength' => 3, + '#size' => 10, + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('Optionally provide a number of seconds after which the node page refreshes.'), + ); } - $form['refresh'] = array( - '#type' => 'fieldset', - '#title' => t('Refresh settings'), - '#collapsible' => TRUE, - '#collapsed' => empty($refresh), - '#access' => user_access('create refreshes'), - '#weight' => 30, - '#group' => 'additional_settings', - '#attributes' => array( - 'class' => array('refresh-form'), - ), - '#attached' => array( - 'js' => array(drupal_get_path('module', 'refresh') . '/refresh.js'), - ), - ); - $form['refresh']['refresh'] = array( - '#type' => 'textfield', - '#default_value' => $refresh, - '#maxlength' => 3, - '#size' => 10, - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#description' => t('Optionally provide a number of seconds after which the node page refreshes.'), - ); } /** @@ -80,6 +85,42 @@ function refresh_node_view($node, $view_mode) } /** + * Implements hook_form_FORM_ID_alter() for the node type form. + */ +function refresh_form_node_type_form_alter(&$form, &$form_state) { + $default_value = refresh_get_setting($form['#node_type']->type); + + $form['refresh_fs'] = array( + '#type' => 'fieldset', + '#title' => t('Automatic reloading of node'), + '#weight' => 0, + '#collapsible' => TRUE, + '#collapsed' => !$default_value, + '#group' => 'additional_settings', + '#attached' => array( + 'js' => array( + 'refresh' => drupal_get_path('module', 'refresh') . '/refresh.js', + ), + ), + ); + $form['refresh_fs']['refresh'] = array( + '#type' => 'radios', + '#default_value' => $default_value, + '#options' => array( + t('Disabled'), + t('Enabled'), + ) + ); +} + +/** + * Gets the refresh setting associated with the given content type. + */ +function refresh_get_setting($type) { + return variable_get('refresh_' . $type, REFRESH_DISABLED); +} + +/** * Implements hook_node_load. */ function refresh_node_load($nodes, $types) { @@ -132,3 +173,20 @@ function refresh_node_update($node) { } } } + +/** + * Implements hook_node_type_delete(). + */ +function refresh_node_type_delete($info) { + variable_del('refresh_' . $info->type); +} + +/** + * Implements hook_node_type_update(). + */ +function refresh_node_type_update($info) { + if (!empty($info->old_type) && $info->old_type != $info->type) { + variable_set('refresh_' . $info->type, refresh_get_setting($info->old_type)); + variable_del('refresh_' . $info->old_type); + } +}