0

I am programatically saving nodes, and everything is working fine. Pathauto is working correctly as well and generating aliases based on my url alias configurations.

However, when Views creates a list of the new nodes, it uses node/xx instead of the existing url alias. Anyone know why this could be happening? All caches have been cleared, cron ran, etc. Here is the code

$node = new stdClass();
    //set other defaults
    node_object_prepare($node);

    $node->type = $page_data['content_type'];
    $node->body[LANGUAGE_NONE][0]['value'] = $page_data['description'];
    $node->body[LANGUAGE_NONE][0]['summary'] = text_summary($page_data['description']);
    $node->body[LANGUAGE_NONE][0]['format']  = 'filtered_html';
    $node->title = $page_data['title'];
    $node->field_product_price[LANGUAGE_NONE][0]['value'] = $page_data['price'];
    $node->field_item_location[LANGUAGE_NONE][0]['postal_code'] = $page_data['zipcode'];
    $node->uid = "1";
    $node->status = 1;
    $node->active = 1;
    $node->pathauto_perform_alias = TRUE;

$node->field_product_images[LANGUAGE_NONE] = $images;
unset($images);


$node->field_baby_clothes_category[LANGUAGE_NONE][0]['tid'] = $page_data['category']; 

if($node = node_submit($node)) { // Prepare node for saving
    node_save($node);
}

note - when I add the same information through the content type form everthing works fine. It's almost as if my code is missing something that helps connect it to views.

0

Views doesn't see the alias. When Drupal receives an alias URL, the first thing it does is change the URL to the default. Views does not come into the process until after the URL is changed, so it does not know about the alias.

0

Ah, I found it. you need $node->language = LANGUAGE_NONE;

without it, Drupal does not have a language to assign it too. If you have local enabled, then $node->language has to equal 'en' or whatever your langauge is you're creating a link for.

  • does this setting have a module setting interface equivalent, one that I can set from the view settings, for instance? – turzifer Sep 12 '13 at 9:58
  • views has a language selection setting, yes, but that would not be related to what I was trying to accomplish here, I don't think. Ask a question about what you're trying to do and maybe I can help answer. – blue928 Sep 12 '13 at 14:20
  • I made my comment into a question: Views: Using pathauto url alias in link fields – turzifer Sep 14 '13 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.