drupal 7 - Need to change node's path to CCK value -
i have content type has been turned feature named "earth news". includes optional cck field called "source url". when cck field not blank want site visitor able click on teaser , go straight url.
i've added following preprocess function .module file feature:
function earth_news_preprocess_node(&$vars) { $node = node_load($vars['nid']); $path = drupal_lookup_path('alias','node/' . $node->nid); $url = $node->field_se_news_source['und'][0]['url']; path_save(array($path,$url)); }
the path_save throwing fatal error:
only variables can passed reference
am on right path? what's error about?
thanks.
the error caused fact path_save() expecting single argument passed reference. in such case, cannot use literal array; pass variable containing array, or value returned function returns reference, value expected argument needs associative array containing following keys:
- source: internal system path
- alias: url alias
- pid: (optional) unique path alias identifier
- language: (optional) language of alias
in case, code should following one.
function earth_news_preprocess_node(&$vars) { $node = $vars['node']; $path = array( 'alias' => drupal_lookup_path('alias','node/' . $node->nid), // can use following line instead of previous one. // 'alias' => drupal_get_path_alias('node/' . $node->nid), 'source' => $node->field_se_news_source['und'][0]['url'], ); path_save($path); }
as side note, template_preprocess_node() makes available node object $vars['node']
; there no need load node.
Comments
Post a Comment