You are here

colorapi.module in Color API 8

Holds hooks for the Color API module.

File

colorapi.module
View source
<?php

/**
 * @file
 * Holds hooks for the Color API module.
 */

/**
 * Implements hook_theme().
 */
function colorapi_theme($existing, $type, $theme, $path) {
  return [
    'colorapi_color_display' => [
      'variables' => [
        'delta' => NULL,
        'item' => NULL,
        'hexadecimal_color' => NULL,
      ],
      'template' => 'colorapi-color-display',
    ],
    'colorapi_text_display' => [
      'variables' => [
        'delta' => NULL,
        'item' => NULL,
        'hexadecimal_color' => NULL,
      ],
      'template' => 'colorapi-text-display',
    ],
  ];
}

/**
 * Implements hook_entity_type_alter().
 */
function colorapi_entity_type_alter(array &$entity_types) {

  // If the Color entity is disabled, remove the Color entity type.
  $color_entity_enabled = \Drupal::config('colorapi.settings')
    ->get('enable_color_entity');
  if (!$color_entity_enabled) {
    unset($entity_types['colorapi_color']);
  }
}

/**
 * Implements hook_menu_links_discovered_alter().
 */
function colorapi_menu_links_discovered_alter(&$links) {

  // If the Color entity is disabled, items from the config page.
  $color_entity_enabled = \Drupal::config('colorapi.settings')
    ->get('enable_color_entity');
  if (!$color_entity_enabled) {
    unset($links['entity.coloreapi_color.collection']);
  }
}

/**
 * Implements hook_field_info_alter().
 */
function colorapi_field_info_alter(&$info) {

  // If the Color field is disabled, remove the Color field type.
  $color_field_enabled = \Drupal::config('colorapi.settings')
    ->get('enable_color_field');
  if (!$color_field_enabled) {
    unset($info['colorapi_color_field']);
  }
}