Save file to server AND to Drupal's file_managed table

Created on 17 May 2019, about 5 years ago
Updated 26 January 2023, over 1 year 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.69.0 2024