You are here

entity_usage.module in Entity Usage 8

Same filename and directory in other branches
  1. 8.4 entity_usage.module
  2. 8.2 entity_usage.module
  3. 8.3 entity_usage.module

File

entity_usage.module
View source
<?php

/**
 * @file
 * Contains entity_usage.module.
 */
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;

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

    // Main module help for the entity_usage module.
    case 'help.page.entity_usage':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Track usage of entities referenced by other entities.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_entity_insert().
 */
function entity_usage_entity_insert(EntityInterface $entity) {

  // Only act on content entities.
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  \Drupal::service('entity_usage.entity_update_manager')
    ->trackUpdateOnCreation($entity);
}

/**
 * Implements hook_entity_update().
 */
function entity_usage_entity_update(EntityInterface $entity) {

  // Only act on content entities.
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  \Drupal::service('entity_usage.entity_update_manager')
    ->trackUpdateOnEdition($entity);
}

/**
 * Implements hook_entity_predelete().
 */
function entity_usage_entity_predelete(EntityInterface $entity) {

  // Only act on content entities.
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  return \Drupal::service('entity_usage.entity_update_manager')
    ->trackUpdateOnDeletion($entity);
}

/**
 * Implements hook_entity_translation_delete().
 */
function entity_usage_entity_translation_delete(EntityInterface $translation) {

  // Only act on content entities.
  if (!$translation instanceof ContentEntityInterface) {
    return;
  }
  \Drupal::service('entity_usage.entity_update_manager')
    ->trackUpdateOnDeletion($translation);
}