For my Drupal 8 website I need to implement a PDF downloader. I have created a content type; which has a "File upload" fields. I have created a view, where all the titles of the nodes are displayed. In combination of "Views Bulk Operations" module and external php library I have created a new Action. After the user cheched the nodes, which he would like to download, the action should be initialized. My question is, how can I get the path to the file in the execute() function?

/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {

// Do some processing..
/*
$node = Node::load(nid);
$file_path = drupal_realpath($node->field_pdf_file->entity->getFileUri());
$file_name = $node->field_pdf_file->entity->getFilename();
*/
// Access nodes pdf field

// Merge them

$merger->addFile($file_name);

$createdPdf = $merger->merge();

return $this->t('Some result');
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.