You are here

pdf_using_mpdf.install in PDF using mPDF 8

File

pdf_using_mpdf.install
View source
<?php

use Mpdf\Mpdf;

/**
 * Implements hook_uninstall().
 */
function pdf_using_mpdf_uninstall() {
  \Drupal::configFactory()
    ->getEditable('pdf_using_mpdf.settings')
    ->delete();
}

/**
 * Implements hook_requirements().
 */
function pdf_using_mpdf_requirements($phase) {
  $requirements = [];
  if ($phase == 'install') {
    if (!class_exists('\\Mpdf\\Mpdf')) {
      $requirements = [
        'pdf_using_mpdf' => [
          'title' => t('Mpdf library'),
          'value' => t(': Not Found'),
          'description' => t('Check if Mpdf library exists'),
          'severity' => REQUIREMENT_ERROR,
        ],
      ];
    }
  }
  if ($phase == 'runtime') {
    if (class_exists('\\Mpdf\\Mpdf')) {
      $mpdf = new Mpdf();
      $requirements = [
        'pdf_using_mpdf' => [
          'title' => t('Mpdf library'),
          'value' => 'Installed version: ' . $mpdf->pdf_version,
          'description' => t('Mpdf library is installed'),
          'severity' => REQUIREMENT_INFO,
        ],
      ];
    }
    else {
      drupal_set_message(t('Mpdf library not found.'), 'error');
    }
  }
  return $requirements;
}