You are here

function domain_settings_add_element in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain_settings/domain_settings.module \domain_settings_add_element()
  2. 7.2 domain_settings/domain_settings.module \domain_settings_add_element()

Helper function to test if a form has to display the domain-specific settings, based on 'domain_settings' settings the user defined.

By design, the configuration for Domain Access itself is disallowed (and some other forms known to be problematic).

Parameters

$form_id: The form_id string that we want to test.

Return value

Boolean TRUE if the given form_id has to display the domain- specific settings. FALSE otherwise.

1 call to domain_settings_add_element()
domain_settings_form_alter in domain_settings/domain_settings.module
Implement hook_form_alter()

File

domain_settings/domain_settings.module, line 250
Allows domain-specific use of Drupal system settings forms.

Code

function domain_settings_add_element($form_id) {

  // Cache results.
  static $forms_visibility;
  if (isset($forms_visibility[$form_id])) {
    return $forms_visibility[$form_id];
  }

  // These forms are known to be problematic, so omit them.
  $disallow = array(
    'domain_configure_form',
    'system_file_system_settings',
    // Changing file paths is dangerous.
    'system_performance_settings',
  );

  // Retrieve the form filtering method:
  $filter_method = variable_get('domain_settings_form_visibility', DOMAIN_SETTINGS_SHOW_EXCEPT_LISTED);

  // Retrieve the user-listed forms:
  $user_listed_forms = array();
  $setting_var = trim(variable_get('domain_settings_forms', ''));
  if (!empty($setting_var)) {
    $match = preg_replace('/(\\r\\n?|\\n)/', '|', $setting_var);
    $user_listed_forms = explode("|", $match);
  }

  // If we want to show the setting on all forms except those listed:
  if ($filter_method == DOMAIN_SETTINGS_SHOW_EXCEPT_LISTED) {
    $forms_to_ignore = array_merge($user_listed_forms, $disallow);
    $forms_visibility[$form_id] = !in_array($form_id, $forms_to_ignore);
  }
  else {
    if ($filter_method == DOMAIN_SETTINGS_SHOW_ONLY_LISTED) {
      $forms_to_authorize = array_diff($user_listed_forms, $disallow);
      $forms_visibility[$form_id] = in_array($form_id, $forms_to_authorize);
    }
  }
  return $forms_visibility[$form_id];
}