You are here

imagefield_tokens.module in ImageField Tokens 8.2

Contains functions related to the module functionality and Drupal hooks.

File

imagefield_tokens.module
View source
<?php

/**
 * @file
 * Contains functions related to the module functionality and Drupal hooks.
 */
use Drupal\Core\Routing\RouteMatchInterface;

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

    // Main module help for the image_field_tokens module.
    case 'help.page.image_field_tokens':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The ImageField Tokens module extends
      the default functionality of Image Widget and Formatter and adding
      the ability to specify default values and use content entity tokens
      in the Alt and Title text.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_filefield_sources_widgets().
 *
 * This returns a list of widgets that are compatible with FileField Sources.
 */
function imagefield_tokens_filefield_sources_widgets() {
  return [
    'file_generic',
    'image_image',
    'imagefield_tokens',
    'imagefield_tokens_widget_crop',
  ];
}

/**
 * Implements hook_field_widget_info_alter().
 */
function imagefield_tokens_field_widget_info_alter(array &$info) {

  // Disable ImageField Tokens crop widget if related module not installed.
  $moduleHandler = \Drupal::service('module_handler');
  if (!$moduleHandler
    ->moduleExists('image_widget_crop')) {
    unset($info['imagefield_tokens_widget_crop']);
  }
}

/**
 * Implements hook_imce_supported_widgets_alter().
 *
 * If Imce module installed and enabled.
 * If Imce & ImageWidgetCrop modules both installed and enabled.
 */
function imagefield_tokens_imce_supported_widgets_alter(&$widgets) {
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('imce')) {
    $widgets[] = 'imagefield_tokens';
    if ($moduleHandler
      ->moduleExists('image_widget_crop')) {
      $widgets[] = 'imagefield_tokens_widget_crop';
    }
  }
}