You are here

function expire_node_settings_form in Cache Expiration 7.2

Settings form for a node type.

1 call to expire_node_settings_form()
expire_form_node_type_form_alter in ./expire.module
Implements hook_form_FORM_ID_alter().

File

./expire.admin.inc, line 742
Settings forms for the Expire module.

Code

function expire_node_settings_form(&$form) {
  if (empty($form['#node_type']->type)) {
    return;
  }
  $node_type = $form['#node_type']->type;
  $form['expire'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cache Expiration'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
  );

  // NODE SETTINGS.
  $form['expire']['expire_node_override_defaults'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override default settings for this node type'),
    '#default_value' => variable_get('expire_node_override_defaults_' . $node_type),
  );

  // Copy here settings from default settings form.
  $settings_form = expire_admin_settings_form();
  $form['expire']['node_actions'] = $settings_form['tabs']['node']['actions'];
  $form['expire']['node_expires'] = $settings_form['tabs']['node']['expire'];

  // Display fieldsets with settings only if they should be overriden.
  $form['expire']['node_actions']['#states'] = array(
    'visible' => array(
      ':input[name="expire_node_override_defaults"]' => array(
        'checked' => TRUE,
      ),
    ),
  );
  $form['expire']['node_expires']['#states'] = array(
    'visible' => array(
      ':input[name="expire_node_override_defaults"]' => array(
        'checked' => TRUE,
      ),
    ),
  );

  // Change tab title to more suitable here.
  $form['expire']['node_expires']['#title'] = t('What pages should be expired when node action is triggered?');

  // COMMENT SETTINGS.
  if (module_exists('comment')) {
    $form['expire']['expire_comment_override_defaults'] = array(
      '#type' => 'checkbox',
      '#title' => t('Override default settings for comments to this node type'),
      '#default_value' => variable_get('expire_comment_override_defaults_' . $node_type),
    );
    $form['expire']['comment_actions'] = $settings_form['tabs']['comment']['actions'];
    $form['expire']['comment_expires'] = $settings_form['tabs']['comment']['expire'];

    // Display fieldsets with settings only if they should be overriden.
    $form['expire']['comment_actions']['#states'] = array(
      'visible' => array(
        ':input[name="expire_comment_override_defaults"]' => array(
          'checked' => TRUE,
        ),
      ),
    );
    $form['expire']['comment_expires']['#states'] = array(
      'visible' => array(
        ':input[name="expire_comment_override_defaults"]' => array(
          'checked' => TRUE,
        ),
      ),
    );
  }

  // Set default settings for this node type.
  $form['expire']['node_actions']['expire_node_actions']['#default_value'] = variable_get('expire_node_actions_' . $node_type, array());
  $form['expire']['node_expires']['expire_node_front_page']['#default_value'] = variable_get('expire_node_front_page_' . $node_type, EXPIRE_NODE_FRONT_PAGE);
  $form['expire']['node_expires']['expire_node_node_page']['#default_value'] = variable_get('expire_node_node_page_' . $node_type, EXPIRE_NODE_NODE_PAGE);
  if (module_exists('taxonomy')) {
    $form['expire']['node_expires']['expire_node_term_pages']['#default_value'] = variable_get('expire_node_term_pages_' . $node_type, EXPIRE_NODE_TERM_PAGES);
  }
  if (module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) {
    $form['expire']['node_expires']['expire_node_reference_pages']['#default_value'] = variable_get('expire_node_reference_pages_' . $node_type, EXPIRE_NODE_REFERENCE_PAGES);
    if (module_exists('field_collection')) {
      $form['expire']['node_expires']['expire_node_reference_field_collection_pages']['#default_value'] = variable_get('expire_node_reference_field_collection_pages_' . $node_type, EXPIRE_NODE_REFERENCE_FC_PAGES);
    }
  }
  $form['expire']['node_expires']['expire_node_custom']['#default_value'] = variable_get('expire_node_custom_' . $node_type, EXPIRE_NODE_CUSTOM);
  $form['expire']['node_expires']['expire_node_custom_pages']['#default_value'] = variable_get('expire_node_custom_pages_' . $node_type);

  // Set default values for comments to this node type.
  if (module_exists('comment')) {
    $form['expire']['comment_actions']['expire_comment_actions']['#default_value'] = variable_get('expire_comment_actions_' . $node_type, array());
    $form['expire']['comment_expires']['expire_comment_front_page']['#default_value'] = variable_get('expire_comment_front_page_' . $node_type, EXPIRE_COMMENT_FRONT_PAGE);
    $form['expire']['comment_expires']['expire_comment_comment_page']['#default_value'] = variable_get('expire_comment_comment_page_' . $node_type, EXPIRE_COMMENT_COMMENT_PAGE);
    $form['expire']['comment_expires']['expire_comment_node_page']['#default_value'] = variable_get('expire_comment_node_page_' . $node_type, EXPIRE_COMMENT_NODE_PAGE);
    if (module_exists('taxonomy')) {
      $form['expire']['comment_expires']['expire_comment_node_term_pages']['#default_value'] = variable_get('expire_comment_node_term_pages_' . $node_type, EXPIRE_COMMENT_NODE_TERM_PAGES);
    }
    if (module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) {
      $form['expire']['comment_expires']['expire_comment_reference_pages']['#default_value'] = variable_get('expire_comment_reference_pages_' . $node_type, EXPIRE_COMMENT_REFERENCE_PAGES);
    }
    if (module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) {
      $form['expire']['comment_expires']['expire_comment_node_reference_pages']['#default_value'] = variable_get('expire_comment_node_reference_pages_' . $node_type, EXPIRE_COMMENT_NODE_REFERENCE_PAGES);
      if (module_exists('field_collection')) {
        $form['expire']['comment_expires']['expire_comment_node_reference_field_collection_pages']['#default_value'] = variable_get('expire_comment_node_reference_field_collection_pages_' . $node_type, EXPIRE_COMMENT_NODE_REFERENCE_FC_PAGES);
      }
    }
    $form['expire']['comment_expires']['expire_comment_custom']['#default_value'] = variable_get('expire_comment_custom_' . $node_type, EXPIRE_COMMENT_CUSTOM);
    $form['expire']['comment_expires']['expire_comment_custom_pages']['#default_value'] = variable_get('expire_comment_custom_pages_' . $node_type);
  }

  // Attach js.
  $form['#attached']['js'][] = drupal_get_path('module', 'expire') . '/js/expire.admin.js';
}