You are here

function display_cache_field_ui_form in Display Cache 7

Display cache settings form.

See also

display_cache_form_field_ui_display_overview_form_alter()

1 call to display_cache_field_ui_form()
display_cache_form_field_ui_display_overview_form_alter in ./display_cache.module
Implements hook_form_FORM_ID_alter().

File

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

Code

function display_cache_field_ui_form(&$form, &$form_state) {
  $entity_type = $form['#entity_type'];
  $bundle = $form['#bundle'];
  $view_mode = $form['#view_mode'];
  $settings = display_cache_get_settings($entity_type, $bundle, $view_mode);

  // Add additional settings vertical tab.
  if (!isset($form['additional_settings'])) {
    $form['additional_settings'] = array(
      '#type' => 'vertical_tabs',
      '#theme_wrappers' => array(
        'vertical_tabs',
      ),
      '#prefix' => '<div>',
      '#suffix' => '</div>',
    );
    $form['#attached']['js'][] = 'misc/form.js';
    $form['#attached']['js'][] = 'misc/collapse.js';
  }

  // Add fieldset.
  $form['display_cache'] = array(
    '#title' => t('Display Cache Display Settings'),
    '#type' => 'fieldset',
    '#group' => 'additional_settings',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#access' => user_access('administer display cache'),
  );

  // Add radios with caching options for the display.
  $display_cache_options = array(
    DISPLAY_CACHE_DISABLED => t('No caching'),
    DISPLAY_CACHE_ENABLED => t('Cache display'),
    DISPLAY_CACHE_FIELDS => t('Cache fields only'),
  );

  // Set default value.
  $use_default_value = 0;
  if (!empty($settings['default']['use'])) {
    $use_default_value = $settings['default']['use'];
  }
  $form['display_cache']['display_cache_use'] = array(
    '#type' => 'radios',
    '#title' => t('Cache the rendered HTML of this view mode.'),
    '#default_value' => $use_default_value,
    '#options' => $display_cache_options,
  );

  // Add radios with granularity options for cache-per-page.
  $page_granularity_options = array(
    0 => t('No page granularity'),
    DRUPAL_CACHE_PER_PAGE => t('Cache per URL'),
  );

  // Set default value.
  $page_default_value = 0;
  if (!empty($settings['default']['page_granularity'])) {
    $page_default_value = $settings['default']['page_granularity'];
  }
  $form['display_cache']['display_cache_page_granularity'] = array(
    '#type' => 'radios',
    '#title' => t('Cache per URL'),
    '#default_value' => $page_default_value,
    '#options' => $page_granularity_options,
    '#states' => array(
      'invisible' => array(
        'input[name="display_cache_use"]' => array(
          'value' => 0,
        ),
      ),
    ),
  );

  // Add radios with granularity options for users.
  $user_granularity_options = array(
    0 => t('No user granularity'),
    DRUPAL_CACHE_PER_ROLE => t('Cache per role'),
    DRUPAL_CACHE_PER_USER => t('Cache per user'),
  );

  // Set default value.
  $user_default_value = 0;
  if (!empty($settings['default']['user_granularity'])) {
    $user_default_value = $settings['default']['user_granularity'];
  }
  $form['display_cache']['display_cache_user_granularity'] = array(
    '#type' => 'radios',
    '#title' => t('User granularity'),
    '#default_value' => $user_default_value,
    '#options' => $user_granularity_options,
    '#states' => array(
      'invisible' => array(
        'input[name="display_cache_use"]' => array(
          'value' => 0,
        ),
      ),
    ),
  );
  if ($entity_type === 'node') {
    $clear_on_comment_publication = display_cache_get_comment_publication_clears_host_entity_cache_settings($entity_type, $bundle, $view_mode);
    $form['display_cache']['clear_on_comment_publication'] = array(
      '#default_value' => $clear_on_comment_publication,
      '#description' => t('Should the display cache for this view mode be cleared, if a comment is (un-)published or deleted for this node type.<br />
          This could be useful if you use any information about the comments in a view mode.'),
      '#states' => array(
        'invisible' => array(
          'input[name="display_cache_use"]' => array(
            'value' => 0,
          ),
          $settings['display_cache_use'] => FALSE,
        ),
      ),
      '#title' => t('Clear display cache on comment (un-)publication/deletion'),
      '#type' => 'checkbox',
    );
  }

  // Add forms for field settings.
  $fields = array();
  $field_instances = field_info_instances($entity_type, $bundle);
  foreach ($field_instances as $field_name => $field_instance) {
    if ($field_instance['display'][$view_mode]['type'] !== 'hidden') {
      $fields[$field_instance['display'][$view_mode]['weight']] = $field_name;
    }
  }

  // Add fieldset for field settings.
  if (!empty($fields)) {
    ksort($fields);
  }
  $form['display_cache_fields'] = array(
    '#title' => t('Display Cache Field Settings'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
    '#access' => user_access('administer display cache'),
    '#description' => t('Use this options to cache fields with less granularity.'),
  );

  // Add settings form for each field.
  foreach ($fields as $field_name) {
    $form_state['display_cache_field_settings'][] = $field_name;
    _display_cache_field_settings_form($form, $form_state, $settings, $field_name);
  }

  // Add custom submit handler.
  $form['#submit'][] = 'display_cache_view_mode_settings_form_submit';
}