color_field.module 3.49 KB
Newer Older
targoo's avatar
targoo committed
1 2 3
<?php
/**
 * @file
targoo's avatar
WIP D8  
targoo committed
4
 * A color field with a custom color picker using the Field Types API.
targoo's avatar
targoo committed
5 6
 */

targoo's avatar
targoo committed
7 8
use Drupal\Core\Routing\RouteMatchInterface;

targoo's avatar
targoo committed
9
/**
10
 * Implements hook_help().
targoo's avatar
targoo committed
11
 */
targoo's avatar
targoo committed
12 13 14
function color_field_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.color_field':
15 16
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
targoo's avatar
targoo committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
      $output .= '<p>' . t('Color Field is simple field that use a hexadecimal notation (HEX) for the combination of Red, Green, and Blue color values (RGB). See the <a href="!field">Field module help</a> and the <a href="!field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href="!link_documentation">online documentation for the Link module</a>.', array('!field' => \Drupal::url('help.page', array('name' => 'field')), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')), '!link_documentation' => 'https://drupal.org/documentation/modules/link')) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Managing and displaying color fields') . '</dt>';
      $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the link field can be configured separately. See the <a href="!field_ui">Field UI help</a> for more information on how to manage fields and their display.', array('!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
      $output .= '<dt>' . t('Adding link text') . '</dt>';
      $output .= '<dd>' . t('In the field settings you can define additional link text to be <em>optional</em> or <em>required</em> in any link field.') . '</dd>';
      $output .= '<dt>' . t('Displaying link text') . '</dt>';
      $output .= '<dd>' . t('If link text has been submitted for a URL, then by default this link text is displayed as a link to the URL. If you want to display both the link text <em>and</em> the URL, choose the appropriate link format from the drop-down menu in the <em>Manage display</em> page. If you only want to display the URL even if link text has been submitted, choose <em>Link</em> as the format, and then change its <em>Format settings</em> to display <em>URL only</em>.') . '</dd>';
      $output .= '<dt>' . t('Adding attributes to links') . '</dt>';
      $output .= '<dd>' . t('You can add attributes to links, by changing the <em>Format settings</em> in the <em>Manage display</em> page. Adding <em>rel="nofollow"</em> notifies search engines that links should not be followed.') . '</dd>';
      $output .= '<dt>' . t('Validating URLs') . '</dt>';
      $output .= '<dd>' . t('All links are validated after a link field is filled in. They can include anchors or query strings.') . '</dd>';
      $output .= '</dl>';
31 32
      return $output;
  }
targoo's avatar
targoo committed
33 34
}

35
/**
targoo's avatar
WIP D8  
targoo committed
36
 * Implements hook_theme().
37
 */
targoo's avatar
WIP D8  
targoo committed
38 39 40 41 42 43 44 45 46 47 48 49
function color_field_theme() {
  $theme = [];

  $theme['color_field_swatch'] = array(
      'variables' => array(
        'color' => NULL,
        'width' => NULL,
        'height' => NULL,
      ),
  );

  return $theme;
50 51 52
}

/**
targoo's avatar
WIP D8  
targoo committed
53 54 55 56 57 58 59 60 61 62 63
 * Prepares variables for the color swatch templates.
 *
 * This template outputs a separate title and link.
 *
 * Default template: link-formatter-link-separate.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *     - color: The color background.
 *     - width: The width of the color swatch.
 *     - height: The height of the color swatch.
64
 */
targoo's avatar
WIP D8  
targoo committed
65
function template_preprocess_color_field_swatch(&$variables) {
66
}