link.module 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php

/**
 * @file
 * Defines simple link field types.
 */

/**
 * Implements hook_help().
 */
function link_help($path, $arg) {
  switch ($path) {
    case 'admin/help#link':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
16
      $output .= '<p>' . t('The Link module defines a simple link field type for the Field module. Links are external URLs, can have an optional link text for each link, and they can be formatted when displayed. See the <a href="@field-help">Field module help page</a> for more information about fields.', array('@field-help' => url('admin/help/field'))) . '</p>';
17 18 19 20 21 22 23 24 25 26 27
      return $output;
  }
}

/**
 * Implements hook_theme().
 */
function link_theme() {
  return array(
    'link_formatter_link_separate' => array(
      'variables' => array('title' => NULL, 'url_title' => NULL, 'href' => NULL, 'options' => array()),
28
      'template' => 'link-formatter-link-separate',
29 30 31 32 33
    ),
  );
}

/**
34 35 36 37 38 39 40 41 42 43 44 45 46
 * Prepares variables for separated link field templates.
 *
 * This template outputs a separate title and link.
 *
 * Default template: link-formatter-link-separate.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - title: (optional) A descriptive or alternate title for the link, which
 *     may be different than the actual link text.
 *   - url_title: The anchor text for the link.
 *   - href: The link URL.
 *   - options: (optional) An array of options to pass to l().
47
 */
48 49 50
function template_preprocess_link_formatter_link_separate(&$variables) {
  if (!empty($variables['title'])) {
    $variables['title'] = check_plain($variables['title']);
51
  }
52
  $variables['link'] = l($variables['url_title'], $variables['href'], $variables['options']);
53
}