You are here

function nodejs_config_form_submit in Node.js integration 7

Same name and namespace in other branches
  1. 6 nodejs_config/nodejs_config.module \nodejs_config_form_submit()

Node.js server configuration form submit handler.

Parameters

mixed $form :

mixed $form_state :

1 string reference to 'nodejs_config_form_submit'
nodejs_config_form in nodejs_config/nodejs_config.module
Node.js server configuration form.

File

nodejs_config/nodejs_config.module, line 166

Code

function nodejs_config_form_submit($form, &$form_state) {
  $values = $form_state['values'];
  $ext = $values['nodejs_config_extensions'];
  if ($ext == !NULL) {
    $ext = explode("\n", str_replace("\r", '', $ext));
  }
  $array = array(
    'scheme' => variable_get('nodejs_server_scheme', 'http'),
    'host' => check_plain($values['nodejs_config_host']),
    'port' => (int) $values['nodejs_config_port'],
    'key' => check_plain($values['nodejs_config_key']),
    'cert' => check_plain($values['nodejs_config_cert']),
    'resource' => check_plain($values['nodejs_config_resource']),
    'publishUrl' => check_plain($values['nodejs_config_publishUrl']),
    'serviceKey' => check_plain($values['nodejs_service_key']),
    'backend' => array(
      'port' => (int) $values['nodejs_config_backend_port'],
      'host' => check_plain($values['nodejs_config_backend_host']),
      'messagePath' => check_plain($values['nodejs_config_backend_messagePath']),
    ),
    'clientsCanWriteToChannels' => (bool) $values['nodejs_config_write_channels'],
    'clientsCanWriteToClients' => (bool) $values['nodejs_config_write_clients'],
    'extensions' => $ext,
    'debug' => (bool) $values['nodejs_config_debug'],
    'transports' => array(
      'websocket',
      'polling',
    ),
    'jsMinification' => true,
    'jsEtag' => true,
    'logLevel' => 1,
  );
  $output = 'backendSettings = ' . drupal_json_encode($array);
  $output = str_replace(array(
    '= {',
    ',',
    '}}',
    ':{',
    '\\/',
  ), array(
    "= {\n  ",
    ",\n  ",
    "\n  }\n}",
    ":{\n  ",
    '/',
  ), $output);
  $output = $output . ';';
  $output = "/**\n* This configuration file was built using the 'Node.js server configuration builder'.\n* For a more fully commented example see the file nodejs.config.js.example in the root of this module\n*/\n" . $output;
  variable_set('nodejs_config_js_suggestion', $output);
}