You are here

vbo_export.module in VBO export 8.2

Same filename and directory in other branches
  1. 8.3 vbo_export.module
  2. 8 vbo_export.module
  3. 7 vbo_export.module

Delivers an action to export view results to csv.

File

vbo_export.module
View source
<?php

/**
 * @file
 * Delivers an action to export view results to csv.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_theme().
 */
function vbo_export_theme() {
  return [
    'vbo_export_content_csv' => [
      'variables' => [
        'header' => [],
        'rows' => [],
        'configuration' => [
          'separator' => ';',
          'strip_tags' => TRUE,
        ],
      ],
      'file' => 'includes/vbo_export.theme.inc',
      // I know this is deprecated.
      // However if I don't set it Drupal looks for a
      // template and doesn't even think of finding the function.
      'function' => 'theme_vbo_export_content_csv',
    ],
    'vbo_export_content_xlsx' => [
      'variables' => [
        'header' => [],
        'rows' => [],
        'configuration' => [
          'strip_tags' => TRUE,
        ],
      ],
      'file' => 'includes/vbo_export.theme.inc',
      // I know this is deprecated.
      // However if I don't set it Drupal looks for a
      // template and doesn't even think of finding the function.
      'function' => 'theme_vbo_export_content_xlsx',
    ],
  ];
}

/**
 * Implements hook_help().
 */
function vbo_export_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.vbo_export':
      $filepath = dirname(__FILE__) . '/README.md';
      if (file_exists($filepath)) {
        $readme = file_get_contents($filepath);
        $output = '<pre>' . $readme . '</pre>';
        return $output;
      }
  }
}

/**
 * Library loader function.
 *
 * Loads the library if not already available and
 * optionally checks its version.
 */
function _vbo_export_load_library($classname, $path = '', $details = FALSE) {
  static $output;
  $path = DRUPAL_ROOT . $path;
  if (!isset($output[$classname])) {
    $output[$classname] = FALSE;

    // If composer was used to add dependancy, the class should exist,
    // Otherwise check given path.
    if (class_exists($classname)) {
      $reflector = new ReflectionClass($classname);
      $path = dirname(dirname($reflector
        ->getFileName()));
    }
    elseif (file_exists($path)) {
      require_once $path . '/Classes/PHPExcel.php';
    }
    if (class_exists($classname)) {
      if ($details) {
        if (file_exists($path . '/changelog.txt') && ($content = file_get_contents($path . '/changelog.txt'))) {
          preg_match('/\\d{4}-\\d{2}-\\d{2} \\(v(\\d+\\.\\d+\\.\\d+)\\):/', $content, $matches);
          if (!empty($matches[1])) {
            $output[$classname] = trim($matches[1]);
          }
          else {
            $output[$classname] = 'undetected';
          }
        }
      }
      else {
        $output[$classname] = TRUE;
      }
    }
  }
  return $output[$classname];
}

Functions

Namesort descending Description
vbo_export_help Implements hook_help().
vbo_export_theme Implements hook_theme().
_vbo_export_load_library Library loader function.