View source
<?php
require drupal_get_path('module', 'freelinking_prepopulate') . '/freelinking_prepopulate.utilities.inc';
function freelinking_prepopulate_freelinking() {
$freelinking['createnode'] = array(
'indicator' => '/^create(node)?$/',
'callback' => 'freelinking_prepopulate_node_callback',
'settings' => 'freelinking_prepopulate_node_settings',
'failover' => array(
'search',
),
);
return $freelinking;
}
function freelinking_prepopulate_node_callback($target, $plugin) {
if (isset($target['type'])) {
$node_type = check_plain($target['type']);
}
else {
$node_type = variable_get('freelinking_prepopulate_node_type', _freelinking_prepopulate_default_node_type());
}
if (!freelinking_get_conf('cache') && !user_access('create ' . $node_type . ' content')) {
switch (variable_get('freelinking_createnode_failover', 'none')) {
case 'search':
return array(
'failover' => 'search',
);
case 'error':
return array(
'failover' => 'error',
'message' => t('Access Denied to Create Missing Content'),
);
}
}
$url = 'node/add/' . str_replace('_', '-', $node_type);
$title = $target['text'] ? $target['text'] : $target['dest'];
$query['edit[title]'] = check_plain($target['dest']);
if (isset($target['other']['prepopulate']) && is_array($target['other']['prepopulate'])) {
foreach ($target['other']['prepopulate'] as $field => $value) {
$query[$field] = $value;
}
}
else {
$query = array_merge($query, freelinking_prepopulate_fields_from_page(variable_get('freelinking_prepopulate_node_advanced', array())));
}
$query_override = freelinking_prepopulate_fields_from_array('nodecreate', $target);
foreach ($query_override as $key => $value) {
if ($value) {
$query[$key] = $value;
}
}
return array(
$title,
$url,
array(
'query' => $query,
'attributes' => array(
'title' => t('Create node') . ' "' . $target['dest'] . '"',
),
),
);
}
function freelinking_prepopulate_node_settings() {
$form['freelinking_prepopulate_node_type'] = array(
'#type' => 'select',
'#title' => t('Default Type to Create'),
'#default_value' => variable_get('freelinking_prepopulate_node_type', _freelinking_prepopulate_default_node_type()),
'#options' => node_get_types('names'),
'#description' => t('Which content type should be created by Freelinking?'),
);
foreach (freelinking_prepopulate_list_fields('nodecreate') as $key => $value) {
$options[$key] = $value['title'];
}
if (empty($options)) {
return $form;
}
$form['freelinking_prepopulate_node_advanced'] = array(
'#type' => 'checkboxes',
'#title' => t('Advanced Options'),
'#default_value' => variable_get('freelinking_prepopulate_node_advanced', array()),
'#options' => $options,
'#description' => t('Use the <em>Linking Node</em> for Create Node presets.'),
);
return $form;
}
function _freelinking_prepopulate_default_node_type() {
$types = node_get_types('names');
$types = array_keys($types);
return array_shift($types);
}