Commit 89ed5d73 authored by Gaurav Kapoor's avatar Gaurav Kapoor Committed by Gaurav Kapoor
Browse files

Issue #3273005 by gaurav.kapoor: Prepare for D9 port

parent a10fc6ab
Loading
Loading
Loading
Loading
+18 −33
Original line number Diff line number Diff line
@@ -12,9 +12,9 @@ INTRODUCTION
------------

Views Files Downloader provides an option to download all the files attached
to a view and a node. It provides a dedicated link for every view to download
files. Downloaded files are added to a Zip file , which can be used by site
visitor.
to nodes shown in a view. It provides a dedicated link for every view to 
download files. Downloaded files are added to a Zip file, which can be used
by site visitor.

 * For a full description of the module, visit the project page:
   https://www.drupal.org/project/vfd
@@ -26,46 +26,30 @@ visitor.
REQUIREMENTS
------------

This module requires following modules outside of Drupal core:

 * Token module - http://drupal.org/project/token

This module doesn't requires any modules outside of Drupal core.

INSTALLATION
------------
 
   1. After downloading place the extacted archive contents in /modules folder.
   2. Download and install libraries module first and then only install views
      file downloader.
   3. Download PCLZip library using composer composer require pclzip/pclzip.
   4. Make sure that machine name of the field containing file is "field_file".
   5. Now create views and nodes with files field.
   6. You can download all the files attached to a view by adding
      "download-view" to URL.

 * Install the vfd module as you would normally install a
   contributed Drupal module. Visit
   https://www.drupal.org/node/1897420 for further information.

CONFIGURATION
-------------

 * How to Work with Node Downloads :

   1. Create field_file (machine name) in your content type.
   2. Once now just add string "download-node" just before "/node/xx" eg
      http://example.com/node/68  just make it
      http://example.com/download-node/node/68 and return
   3. The file in the corresponding node will be compressed and downloaded.

 * How to Work with View Downloads :

   1. Create field_file (machine name) in your content type and add this
      field in your view.
   2. The path for the view must be same as the view Machine Name eg if the
      Machine name for your view "myview" is "my_cool_view" then the path
      must be same as the machine name  i.e /my_cool_view.
   3. Once done now just add string "download-view" just before "/my_cool_view"
      eg  http://example.com/my_cool_view  just make it
      http://example.com/download-view/my_cool_view and return
   4. The file in the corresponding view will be compressed and downloded.
   1. Make sure you have already configured the required file/media field
      in one of your content type and already created a view as well.
   2. Configure the required settings in '/admin/structure/views/settings/vfd'.
      Here you have to provide view name and machine name of the file/media
      field as well as type of the field.    
   2. To generate the download link of files appearing in a view, take a note
      of machine name of the view.
   3. Once done now just add string "download-view" just before the machine
      name eg  http://example.com/download-view/{view_machine_name}.
   4. The files in the corresponding view will be compressed and downloaded.


MAINTAINERS
@@ -75,4 +59,5 @@ MAINTAINERS

Supporting organizations:

 * Axelerant - https://www.drupal.org/axelerant
 * OpenSense Labs - https://www.drupal.org/opensense-labs
+2 −2
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ class DownloadViewController extends ControllerBase {
    mkdir($dir);

    if ($field_type == 'media') {
      foreach ((views_get_view_result($path)) as $key => $value) {
      foreach ((views_get_view_result($path)) as $value) {
        $node = $this->entityTypeManager->getStorage('node')->load($value->nid);
        $file_uri = $node->$field_machine_name->entity->field_media_document->entity->getFileUri();
        $this->fileSystem->copy($file_uri, $this->fileSystem->realpath($dir), FileSystemInterface::EXISTS_REPLACE);
@@ -101,7 +101,7 @@ class DownloadViewController extends ControllerBase {
    }

    if ($field_type == 'file') {
      foreach ((views_get_view_result($path)) as $key => $value) {
      foreach ((views_get_view_result($path)) as $value) {
        $node = $this->entityTypeManager->getStorage('node')->load($value->nid);
        $file_uri = $node->$field_machine_name->entity->getFileUri();
        $this->fileSystem->copy($file_uri, $this->fileSystem->realpath($dir), FileSystemInterface::EXISTS_REPLACE);
+2 −7
Original line number Diff line number Diff line
@@ -123,16 +123,11 @@ class ViewsFileDownloaderSettingsForm extends ConfigFormBase {
    }

    // Provide ability to remove first element.
    $required = TRUE;
    if (isset($vfd_table['removed']) && $vfd_table['removed']) {
      // Not required if first element is empty.
      reset($vfd_table);
      unset($vfd_table['removed']);
    }
    // Don't allow to add multiple elements after all rows are removed.
    if (count($vfd_table) > 1) {
      $required = TRUE;
    }

    // Create row for table.
    foreach ($vfd_table as $i => $value) {
@@ -157,8 +152,8 @@ class ViewsFileDownloaderSettingsForm extends ConfigFormBase {
        '#title' => $this->t('Field Type'),
        '#title_display' => 'invisible',
        '#options' => [
          'file' => 'File',
          'media' => 'Media',
          'file' => $this->t('File'),
          'media' => $this->t('Media'),
        ],
        '#default_value' => $value['field_type'] ?? [],
      ];
+9 −52
Original line number Diff line number Diff line
@@ -5,60 +5,17 @@
 * Handles module administration and download link of Views File Downloader.
 */

use Drupal\file\Entity\File;
use Drupal\Core\File\FileSystem;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 *
 * Implements hook_help().
 */
function files_node($nid) {
  $node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
  foreach ($node as $key => $value) {
    if (substr($key, 0, 5) == 'field') {
      $field_type = $node->get($key)->getFieldDefinition()->getType();
      if ($field_type == 'file') {
        $node = $node->get($key)->getValue();
function vfd_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.vfd':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Views Files Downloader provides an option to download all the files attached to a view and a node. It provides a dedicated link for every view to download files. Downloaded files are added to a Zip file , which can be used by site visitor.') . '</p>';
      return $output;
  }
}
  }
  $node_files = [];
  foreach ($node as $value) {
    $node_files[] = $value['target_id'];
  }
  $file_url = [];
  $file_id = $node_files;
  foreach ($file_id as $fid) {
    $file = File::load($fid);
    $file = FileSystem::realpath($file->uri->value);
    $file_url[] = $file;
  }
  return $file_url;
}

/**
 *
 */
function all_files_node($nid) {
  $node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
  $node_files = [];
  foreach ($node as $key => $value) {
    if (substr($key, 0, 5) == 'field') {
      $field_type = $node->get($key)->getFieldDefinition()->getType();
      if ($field_type == 'file') {
        $current_node = $node->get($key)->getValue();
        foreach ($current_node as $val) {
          $node_files[] = $val['target_id'];
        }
      }
    }
  }
  $file_url = [];
  $file_id = $node_files;
  foreach ($file_id as $fid) {
    $file = File::load($fid);
    $file = \Drupal::service('file_system')->realpath($file->uri->value);
    $file_url[] = $file;
  }

  return $file_url;
}