og_context.admin.inc

  1. 7.x-2.x og/og_context/og_context.admin.inc
  2. 7.x-1.x og/og_context/og_context.admin.inc

Administration functions for OG context module.

Functions

Namesort descending Description
og_context_configure_form Setting for language negotiation options
og_context_configure_form_submit Submit handler for og_context negotiation settings.
theme_og_context_configure_form Returns HTML for a group context configuration form.
_og_context_configure_form_table Helper function to build a group context provider table.

File

og/og_context/og_context.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Administration functions for OG context module.
  5. */
  6. /**
  7. * Setting for language negotiation options
  8. */
  9. function og_context_configure_form() {
  10. $form = array(
  11. '#submit' => array('og_context_configure_form_submit'),
  12. '#theme' => 'og_context_configure_form',
  13. '#group_context_providers' => og_context_negotiation_info(),
  14. );
  15. _og_context_configure_form_table($form);
  16. $form['actions'] = array('#type' => 'actions');
  17. $form['actions']['submit'] = array(
  18. '#type' => 'submit',
  19. '#value' => t('Save settings'),
  20. );
  21. return $form;
  22. }
  23. /**
  24. * Helper function to build a group context provider table.
  25. */
  26. function _og_context_configure_form_table(&$form) {
  27. $type = 'group_context';
  28. $table_form = array(
  29. '#title' => t('Group context detection'),
  30. '#tree' => TRUE,
  31. '#description' => t('Order of Group context detection methods.'),
  32. '#group_context_providers' => array(),
  33. '#show_operations' => FALSE,
  34. 'weight' => array('#tree' => TRUE),
  35. 'enabled' => array('#tree' => TRUE),
  36. );
  37. $group_context_providers = $form['#group_context_providers'];
  38. // Enable url and node context handlers by default.
  39. $defaults = array('url' => -5, 'node' => -4);
  40. $enabled_providers = variable_get("og_context_negotiation_$type", $defaults);
  41. $providers_weight = variable_get("og_context_providers_weight_$type", $defaults);
  42. // Add missing data to the providers lists.
  43. foreach ($group_context_providers as $id => $provider) {
  44. if (!isset($providers_weight[$id])) {
  45. $providers_weight[$id] = og_context_provider_weight($provider);
  46. }
  47. }
  48. // Order providers list by weight.
  49. asort($providers_weight);
  50. foreach ($providers_weight as $id => $weight) {
  51. $enabled = isset($enabled_providers[$id]);
  52. $provider = $group_context_providers[$id];
  53. $table_form['#group_context_providers'][$id] = $provider;
  54. $table_form['weight'][$id] = array(
  55. '#type' => 'weight',
  56. '#default_value' => $weight,
  57. '#attributes' => array('class' => array("group_context-provider-weight-$type")),
  58. );
  59. $table_form['title'][$id] = array('#markup' => check_plain($provider['name']));
  60. $table_form['enabled'][$id] = array('#type' => 'checkbox', '#default_value' => $enabled);
  61. $table_form['description'][$id] = array('#markup' => filter_xss_admin($provider['description']));
  62. $config_op = array();
  63. if (isset($provider['config'])) {
  64. $config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $provider['config']);
  65. // If there is at least one operation enabled show the operation column.
  66. $table_form['#show_operations'] = TRUE;
  67. }
  68. $table_form['operation'][$id] = $config_op;
  69. }
  70. $form['group_context'] = $table_form;
  71. }
  72. /**
  73. * Returns HTML for a group context configuration form.
  74. *
  75. * @param $variables
  76. * An associative array containing:
  77. * - form: A render element representing the form.
  78. *
  79. * @ingroup themeable
  80. */
  81. function theme_og_context_configure_form($variables) {
  82. $form = $variables['form'];
  83. $output = '';
  84. $type = 'group_context';
  85. $rows = array();
  86. $title = '<label>' . $form[$type]['#title'] . '</label>';
  87. $description = '<div class="description">' . $form[$type]['#description'] . '</div>';
  88. foreach ($form[$type]['title'] as $id => $element) {
  89. // Do not take form control structures.
  90. if (is_array($element) && element_child($id)) {
  91. $row = array(
  92. 'data' => array(
  93. '<strong>' . drupal_render($form[$type]['title'][$id]) . '</strong>',
  94. drupal_render($form[$type]['description'][$id]),
  95. drupal_render($form[$type]['enabled'][$id]),
  96. drupal_render($form[$type]['weight'][$id]),
  97. ),
  98. 'class' => array('draggable'),
  99. );
  100. if ($form[$type]['#show_operations']) {
  101. $row['data'][] = drupal_render($form[$type]['operation'][$id]);
  102. }
  103. $rows[] = $row;
  104. }
  105. }
  106. $header = array(
  107. array('data' => t('Detection method')),
  108. array('data' => t('Description')),
  109. array('data' => t('Enabled')),
  110. array('data' => t('Weight')),
  111. );
  112. // If there is at least one operation enabled show the operation column.
  113. if ($form[$type]['#show_operations']) {
  114. $header[] = array('data' => t('Operations'));
  115. }
  116. $variables = array(
  117. 'header' => $header,
  118. 'rows' => $rows,
  119. 'attributes' => array('id' => "group_context-negotiation-providers-$type"),
  120. );
  121. $table = theme('table', $variables);
  122. $table .= drupal_render_children($form[$type]);
  123. drupal_add_tabledrag("group_context-negotiation-providers-$type", 'order', 'sibling', "group_context-provider-weight-$type");
  124. $output .= '<div class="form-item">' . $title . $description . $table . '</div>';
  125. $output .= drupal_render_children($form);
  126. return $output;
  127. }
  128. /**
  129. * Submit handler for og_context negotiation settings.
  130. */
  131. function og_context_configure_form_submit($form, &$form_state) {
  132. $type = 'group_context';
  133. $negotiation = array();
  134. $enabled_providers = $form_state['values'][$type]['enabled'];
  135. $providers_weight = $form_state['values'][$type]['weight'];
  136. foreach ($providers_weight as $id => $weight) {
  137. if ($enabled_providers[$id]) {
  138. $provider = $form[$type]['#group_context_providers'][$id];
  139. $provider['weight'] = $weight;
  140. $negotiation[$id] = $provider;
  141. }
  142. }
  143. og_context_negotiation_set($negotiation);
  144. variable_set("og_context_providers_weight_$type", $providers_weight);
  145. $form_state['redirect'] = 'admin/config/group/context';
  146. drupal_set_message(t('Group context negotiation configuration saved.'));
  147. }