You are here

exif.module in Exif 8

Same filename and directory in other branches
  1. 8.2 exif.module
  2. 5 exif.module
  3. 6 exif.module
  4. 7 exif.module

Entry point for exif module.

File

exif.module
View source
<?php

/**
 * @file
 * Entry point for exif module.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\exif\ExifContent;
use Drupal\exif\ExifHelp;
use Drupal\media\MediaInterface;
use Drupal\Node\NodeInterface;

/**
 * Implements hook_help().
 *
 * Manage the exif help page route.
 */
function exif_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.exif':
      return ExifHelp::content();
    default:
      return NULL;
  }
}

/**
 * Implements hook_theme().
 */
function exif_theme() {
  return [
    'exif_sample' => [
      'variables' => [
        'taxonomy' => 'http://drupal.org/handbook/modules/taxonomy/',
        'image_path' => NULL,
        'metadata' => NULL,
      ],
      'template' => 'exif_sample',
    ],
    'exif_helper_page' => [
      'variables' => [
        'message' => NULL,
        'taxonomy' => 'http://drupal.org/handbook/modules/taxonomy/',
      ],
      'template' => 'exif_helper_page',
    ],
  ];
}

/**
 * Implements hook_entity_presave().
 *
 * Calculate the value for each metadata field so they can be stored correctly.
 */
function exif_entity_presave(EntityInterface $entity) {
  $entityType = '';
  if ($entity instanceof NodeInterface) {
    $entityType = 'node';
  }
  else {
    if (Drupal::moduleHandler()
      ->moduleExists("media_entity") && $entity instanceof MediaInterface) {
      $entityType = 'media';
    }
  }
  if ($entityType != '') {
    $config = Drupal::configFactory()
      ->get('exif.settings');
    $shouldUpdateMetadata = $config
      ->get('update_metadata');
    if (!isset($shouldUpdateMetadata)) {
      $shouldUpdateMetadata = TRUE;
    }
    $inserting = !isset($entity->original);
    if ($inserting || $shouldUpdateMetadata) {
      $exifContentHandler = new ExifContent();
      $exifContentHandler
        ->entity_insert_update($entityType, $entity);
    }
  }
}

/**
 * Implements hook_entity_create().
 */
function exif_entity_create(EntityInterface $entity) {
  $entityType = '';
  if ($entity instanceof NodeInterface) {
    $entityType = 'node';
  }
  else {
    if (Drupal::moduleHandler()
      ->moduleExists("media_entity") && $entity instanceof MediaInterface) {
      $entityType = 'media';
    }
  }
  if ($entityType != '') {
    $config = Drupal::configFactory()
      ->get('exif.settings');
    $shouldUpdateMetadata = $config
      ->get('update_metadata');
    if (!isset($shouldUpdateMetadata)) {
      $shouldUpdateMetadata = TRUE;
    }
    $inserting = !isset($entity->original);
    if ($inserting || $shouldUpdateMetadata) {
      $exifContentHandler = new ExifContent();
      $exifContentHandler
        ->checkTitle($entityType, $entity);
    }
  }
}

Functions

Namesort descending Description
exif_entity_create Implements hook_entity_create().
exif_entity_presave Implements hook_entity_presave().
exif_help Implements hook_help().
exif_theme Implements hook_theme().