function freelinking_prepopulate_node_callback in Freelinking 6.3
Same name and namespace in other branches
- 7.3 modules/freelinking_prepopulate/freelinking_prepopulate.module \freelinking_prepopulate_node_callback()
Node Create replacement callback Ultimate default: [[create:pagetitle]] => <a href="node/add/page?edit[title]=pagetitle>pagetitle</a>
1 string reference to 'freelinking_prepopulate_node_callback'
- freelinking_prepopulate_freelinking in modules/
freelinking_prepopulate/ freelinking_prepopulate.module
File
- modules/
freelinking_prepopulate/ freelinking_prepopulate.module, line 29
Code
function freelinking_prepopulate_node_callback($target, $plugin) {
// Use specified node type or fallback to configuration.
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 the cache is disabled, check to see if the current user can create this content 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'),
);
}
}
// Generate basic link elements.
$url = 'node/add/' . str_replace('_', '-', $node_type);
$title = $target['text'] ? $target['text'] : $target['dest'];
// This title is default for createnode, anything else (such as target['title']) will override it.
$query['edit[title]'] = check_plain($target['dest']);
// Use arguments targeted for Prepopulate or get values from current node/page.
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())));
}
// Override query string from syntax.
// This is not currently restricted by advanced settings, just by the ability
// of the FL_P API to recognize arguments from $target
$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'] . '"',
),
),
);
}