You are here

function _display_cache_field_settings_form in Display Cache 7

Display cache field settings form.

See also

display_cache_form_field_ui_display_overview_form_alter()

display_cache_field_ui_form()

1 call to _display_cache_field_settings_form()
display_cache_field_ui_form in ./display_cache.admin.inc
Display cache settings form.

File

./display_cache.admin.inc, line 188
Provides the Display Cache administrative interface.

Code

function _display_cache_field_settings_form(&$form, &$form_state, $settings, $field_name) {
  $field_settings = array();
  if (!empty($settings[$field_name])) {
    $field_settings = $settings[$field_name];
  }

  // Add fieldset for this fields settings.
  $fieldset = 'display_cache_field_' . $field_name;
  $form['display_cache_fields'][$fieldset] = array(
    '#type' => 'fieldset',
    '#title' => $field_name,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Disable field settings if display cache is disabled.
  if ($settings['default']['use'] == DISPLAY_CACHE_DISABLED) {
    $form['display_cache_fields'][$fieldset]['#disabled'] = TRUE;
  }

  // Open fieldset if field settings are overridden.
  if (isset($field_settings['override']) && ($field_settings['override'] == DISPLAY_CACHE_ENABLED || $field_settings['override'] == DISPLAY_CACHE_DISABLED)) {
    $form['display_cache_fields'][$fieldset]['#collapsed'] = FALSE;
  }

  // Add radios with caching options for this field.
  $display_cache_options = array(
    DISPLAY_CACHE_FIELDS => t('Use default'),
    DISPLAY_CACHE_ENABLED => t('Override display cache defaults'),
  );

  // Set default value.
  if (!empty($field_settings['override']) && $field_settings['override'] != 0) {
    $override_default_value = $field_settings['override'];
  }
  else {
    $override_default_value = DISPLAY_CACHE_DISABLED;
  }

  // Add exclude from cache option if display is set to field cache only.
  if ($settings['default']['use'] === DISPLAY_CACHE_FIELDS) {
    $display_cache_options[DISPLAY_CACHE_DISABLED] = t('Do not cache this field');
  }
  $form['display_cache_fields'][$fieldset][$fieldset . '_override'] = array(
    '#type' => 'radios',
    '#title' => t('Override display cache defaults'),
    '#default_value' => $override_default_value,
    '#options' => $display_cache_options,
  );

  // Add radios with page granularity options.
  $page_granularity_options = array(
    0 => t('No page granularity'),
  );
  $page_default_value = 0;

  // Add page granularity option, if display is set to be URL aware.
  if (!empty($settings['default']['page_granularity'])) {
    $page_granularity_options[DRUPAL_CACHE_PER_PAGE] = t('Cache per URL');
    if (!empty($field_settings['page_granularity']) && $field_settings['page_granularity'] != 0) {
      $page_default_value = $field_settings['page_granularity'];
    }
  }
  $form['display_cache_fields'][$fieldset][$fieldset . '_page_granularity'] = array(
    '#type' => 'radios',
    '#title' => t('Cache per URL'),
    '#default_value' => $page_default_value,
    '#options' => $page_granularity_options,
    '#states' => array(
      'visible' => array(
        'input[name="' . $fieldset . '_override"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );

  // Add radios with user granularity options.
  $user_default_value = 0;
  if (!empty($field_settings['user_granularity']) && $field_settings['user_granularity'] != 0) {
    $user_default_value = $field_settings['user_granularity'];
  }
  $user_granularity_options = array(
    0 => t('No user granularity'),
  );
  if (!empty($settings['default']['user_granularity'])) {
    if ($settings['default']['user_granularity'] == DRUPAL_CACHE_PER_ROLE) {

      // Add role granularity option if display is set to role awareness.
      $user_granularity_options[DRUPAL_CACHE_PER_ROLE] = t('Cache per role');
    }
    elseif ($settings['default']['user_granularity'] == DRUPAL_CACHE_PER_USER) {

      // Add role and user granularity options if display is set to user or role
      // awareness.
      $user_granularity_options[DRUPAL_CACHE_PER_ROLE] = t('Cache per role');
      $user_granularity_options[DRUPAL_CACHE_PER_USER] = t('Cache per user');
    }
  }
  else {
    $user_default_value = 0;
  }
  $form['display_cache_fields'][$fieldset][$fieldset . '_user_granularity'] = array(
    '#type' => 'radios',
    '#title' => t('User granularity'),
    '#default_value' => $user_default_value,
    '#options' => $user_granularity_options,
    '#states' => array(
      'visible' => array(
        'input[name="' . $fieldset . '_override"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
}