You are here

avatars.module in Avatar Kit 8.2

Same filename and directory in other branches
  1. 8 avatars.module

Contains hooks for Avatar Kit.

File

avatars.module
View source
<?php

/**
 * @file
 * Contains hooks for Avatar Kit.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function avatars_help(string $route_name, RouteMatchInterface $route_match) : ?array {
  switch ($route_name) {
    case 'avatars.config.entity_map':
      return [
        '#markup' => t('<p>' . t('Select the destination field where avatars should be placed. Any existing images in the field will be overwritten. If you wish for uploaded images to be retained, then create a new image field and map to the new field instead.') . '</p>'),
      ];
  }
  return NULL;
}

/**
 * Implements hook_entity_storage_load().
 */
function avatars_entity_storage_load(array $entities) : void {

  /** @var $hookService \Drupal\avatars\AvatarKitEntityHooksInterface */
  $hookService = \Drupal::service('avatars.hooks');
  $hookService
    ->storageLoad($entities);
}

/**
 * Implements hook_entity_update().
 */
function avatars_entity_update(EntityInterface $entity) : void {

  /** @var $hookService \Drupal\avatars\AvatarKitEntityHooksInterface */
  $hookService = \Drupal::service('avatars.hooks');
  $hookService
    ->update($entity);
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * FORM_ID: 'field_config_edit_form'.
 *
 * @see \Drupal\avatars\AvatarKitFormAlterInterface::fieldConfigEditForm
 */
function avatars_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {

  /** @var $formAlterService \Drupal\avatars\AvatarKitFormAlterInterface */
  $formAlterService = \Drupal::service('avatars.form_alter');
  $formAlterService
    ->fieldConfigEditForm($form, $form_state);
}