Save file to server AND to Drupal's file_managed table

Created on 17 May 2019, over 5 years ago
Updated 26 January 2023, almost 2 years ago

I think it would be good if, when saving the pdf to the server via Rules, the file also be added to Drupal with file_save_data.
I was able to achieve this by adding a couple of lines to the views_pdf_rules_save function in views_pdf.rules.inc
So the final foreach loop goes from

    foreach ($view->display as $id => $display) {
      if ($display->display_plugin == 'pdf' && isset($display->handler) && $id == $display_id) {
        $display->handler->execute($path, 'F');
      }
    }

To

    foreach ($view->display as $id => $display) {
      if ($display->display_plugin == 'pdf' && isset($display->handler) && $id == $display_id) {
        $display->handler->execute($path, 'F');
        $pdf = file_get_contents($path);
        $file = file_save_data($pdf, $path, FILE_EXISTS_REPLACE);
      }
    }

Ideally, the file would then be exposed to Rules but this at least allows it to be fetched in Rules by property name, or whatever.
Let me know if you think this is useful, I'd be happy to roll a patch.
Thanks,
Matt

✨ Feature request
Status

Needs work

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024