You are here

media_pdf_thumbnail.module in Media PDF Thumbnail 8.4

File

media_pdf_thumbnail.module
View source
<?php

/**
 * @file
 * Contains media_pdf_thumbnail.module.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\media\MediaInterface;
use Drupal\media_pdf_thumbnail\Form\BundlesSettingsForm;
use Drupal\media_pdf_thumbnail\Plugin\QueueWorker\MediaPdfThumbnailGeneratorCronQueue;

/**
 * Implements hook_help().
 *
 */
function media_pdf_thumbnail_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the adimeo_pdf_thumbnail module.
    case 'help.page.media_pdf_thumbnail':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Generate a thumbnail image from a pdf file in media entity') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_ENTITY_TYPE_presave().
 *
 */
function media_pdf_thumbnail_media_presave(MediaInterface $media) {
  $mediaThumbnailService = Drupal::service('media_pdf_thumbnail.service');
  $mediaThumbnailService
    ->previousFileDelete($media);
}

/**
 * Implements hook_ENTITY_TYPE_update().
 *
 */
function media_pdf_thumbnail_media_update(MediaInterface $media) {

  /**
   * @var \Drupal\media_pdf_thumbnail\Service\MediaPdfThumbnailService $mediaThumbnailService
   */
  $mediaThumbnailService = Drupal::service('media_pdf_thumbnail.service');
  $mediaThumbnailService
    ->handleEntity($media, 'update');
}

/**
 * Implements hook_ENTITY_TYPE_insert().
 *
 */
function media_pdf_thumbnail_media_insert(MediaInterface $media) {

  /**
   * @var \Drupal\media_pdf_thumbnail\Service\MediaPdfThumbnailService $mediaThumbnailService
   */
  $mediaThumbnailService = Drupal::service('media_pdf_thumbnail.service');
  $mediaThumbnailService
    ->handleEntity($media, 'create');
}

/**
 * Implements hook_queue_info_alter().
 *
 */
function media_pdf_thumbnail_queue_info_alter(&$queues) {
  $cronTime = Drupal::configFactory()
    ->get(BundlesSettingsForm::SETTINGS)
    ->get('cron_time');
  if ($cronTime) {
    $queues[MediaPdfThumbnailGeneratorCronQueue::ID]['cron']['time'] = $cronTime;
  }
}

/**
 * Implements hook_file_download().
 *
 */
function media_pdf_thumbnail_file_download($uri) {
  if (strpos($uri, 'private://') !== FALSE) {
    if (Drupal::currentUser()
      ->isAuthenticated()) {
      return 1;
    }
    return -1;
  }
}