You are here

jquery_colorpicker.module in Jquery Colorpicker 8.2

Holds hooks for the JQuery Colorpicker module.

File

jquery_colorpicker.module
View source
<?php

/**
 * @file
 * Holds hooks for the JQuery Colorpicker module.
 */
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_theme().
 */
function jquery_colorpicker_theme($existing, $type, $theme, $path) {
  return [
    'jquery_colorpicker' => [
      'render element' => 'element',
      'template' => 'jquery-colorpicker',
      'file' => 'includes/jquery_colorpicker.theme.inc',
    ],
  ];
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function jquery_colorpicker_form_colorapi_color_add_form_alter(array &$form, FormStateInterface $form_state) {
  jquery_colorpicker_form_alter_common($form, $form_state);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function jquery_colorpicker_form_colorapi_color_edit_form_alter(array &$form, FormStateInterface $form_state) {
  jquery_colorpicker_form_alter_common($form, $form_state);
}

/**
 * Helper function, swaps out color field render items with jquery widgets.
 */
function jquery_colorpicker_form_alter_common(array &$form, FormStateInterface $form_state) {
  $form['color']['#type'] = 'jquery_colorpicker';
}

/**
 * Implements hook_field_info_alter().
 *
 * @deprecated as of Jquery Colorpicker update 8200. Will be removed in Jquery
 *   Colorpicker 8.x-3.x, and/or 9.x-1.x.
 *
 * @see jquery_colorpicker_update_8200()
 */
function jquery_colorpicker_field_info_alter(&$info) {

  // Running jquery_colorpicker_update_8200() requires the existence of the
  // jquery_colorpicker field type, however the field type is obsolete after
  // that update has been run. As such, if the schema version is equal to or
  // above 8200, the field type is removed from the list of field types.
  if (drupal_get_installed_schema_version('jquery_colorpicker') >= 8200) {
    unset($info['jquery_colorpicker']);
  }
}