function nodejs_config_form_submit in Node.js integration 6
Same name and namespace in other branches
- 7 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 154
Code
function nodejs_config_form_submit($form, &$form_state) {
$values = $form_state['values'];
$ext = $values['nodejs_config_extensions'];
$ext = explode("\n", str_replace("\r", '', $ext));
$array = array(
'scheme' => variable_get('nodejs_server_scheme', 'http'),
'host' => check_plain($values['nodejs_config_host']),
'port' => check_plain($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_config_serviceKey']),
'backend' => array(
'port' => check_plain($values['nodejs_config_backend_port']),
'host' => check_plain($values['nodejs_config_backend_host']),
'authPath' => check_plain($values['nodejs_config_backend_authPath']),
),
'clientsCanWriteToChannels' => (bool) $values['nodejs_config_write_channels'],
'clientsCanWriteToClients' => (bool) $values['nodejs_config_write_clients'],
'extensions' => array(
$ext,
),
'debug' => (bool) $values['nodejs_config_debug'],
);
$output = 'backendSettings = ' . json_encode($array);
$output = str_replace(array(
'= {',
',',
'}}',
':{',
'\\/',
), array(
"= {\n ",
",\n ",
"\n }\n}",
":{\n ",
'/',
), $output);
$file_path = drupal_get_path('module', 'nodejs') . '/nodejs.config.js';
if (!is_writable($file_path)) {
drupal_set_message(t('It was not possible to write the below lines to <b>!file</b>, you need to do it manually.', array(
'!file' => $file_path,
)));
drupal_set_message('<pre>' . $output . '</pre>');
}
else {
file_put_contents($file_path, $output);
}
}