0
function news_article_node_submit($node, $form, &$form_state)
{
// Make a URI link from title of pdf being uploaded
if (isset($form_state['values']['field_upload_import_pdf'])) {
    $file = file_load($node->field_upload_import_pdf['und'][0]['fid']);
    $filePath = file_create_url($file->uri);

    // Redirect to pdf
    isset($_GET['destination']);
    unset($_GET['destination']);
    if (isset($filePath)) {
        drupal_goto($filePath);

        // Return all field behaviors to redirect to default
    } else {
        $form_state['redirect'] = 'to page preview';
        drupal_redirect_form($form_state);
        }
    }
}

I was experimenting with drupal_goto() and $form_state['redirect'], but neither of them seems to work. Using drupal_goto() hijacks the whole module and the $form_state['redirect'] doesn't do anything. Also I am getting PHP errors when else function encounters the first two lines of code above:

Notice: Undefined offset: 0 in news_article_node_submit()

Notice: Trying to get property of non-object in news_article_node_submit()

Is there a way to create a URI from the filename, and redirect users to domainname://NAME_OF_FILE.pdf when choosing a conditional field while, at the same time, when users use any other conditional field, the behavior is the default Drupal one?

  • I know! Is there another way to approach this? – emb03 Aug 31 '18 at 22:12
0

You can use the trick from the module File Force Download. You can check it in the their code repository https://cgit.drupalcode.org/file_force/tree/file_force.module?h=7.x-1.x

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.