You are here

function shortcode_basic_tags_shortcode_link in Shortcode 7.2

Same name and namespace in other branches
  1. 6 shortcode_basic_tags/shortcode_basic_tags.module \shortcode_basic_tags_shortcode_link()
  2. 7 shortcode_basic_tags/shortcode_basic_tags.module \shortcode_basic_tags_shortcode_link()

Provides process callback for link ShortCode.

Parameters

array $attributes: Optional.

  • title = the title of the link. Can be disabled by <none>. If empty the text will be used.
  • class = CSS classes separated by spaces
  • style = CSS styles
  • id – DOM id of the link.

URL parameters:

  • path = the path of the link. Will be formatted by the url(). Default is the <front> link.
  • html – Enable HTML of the link text.
  • absolute — The link can be absolute or relative (default).
  • fragment - The url fragment.
  • alias — Flag for aliased URL (TRUE).

string $text: The linked text (optional).

Return value

string The path string.

1 string reference to 'shortcode_basic_tags_shortcode_link'
shortcode_basic_tags_shortcode_info in shortcode_basic_tags/shortcode_basic_tags.module
Implements hook_shortcode_info().

File

shortcode_basic_tags/shortcode_basic_tags.module, line 835
Provides basic ShortCodes (as examples).

Code

function shortcode_basic_tags_shortcode_link($attributes, $text) {

  // Used attributes by this macro.
  $attributes = shortcode_attrs(array(
    'path' => '<front>',
    'title' => '',
    'class' => '',
    'style' => '',
    'id' => '',
    'html' => FALSE,
    'absolute' => FALSE,
    'fragment' => '',
    'alias' => TRUE,
  ), $attributes);
  $options = array(
    'attributes' => array(),
  );
  $options['html'] = shortcode_bool($attributes['html']);
  $options['absolute'] = shortcode_bool($attributes['absolute']);
  $options['alias'] = shortcode_bool($attributes['alias']);
  if ($attributes['fragment']) {
    $options['fragment'] = check_plain($attributes['fragment']);
  }
  if ($text) {
    if ($attributes['class']) {
      $classes = shortcode_add_class($attributes['class']);
      $options['attributes']['class'] = (array) $classes;
    }
    if ($attributes['style']) {
      $options['attributes']['style'] = check_plain($attributes['style']);
    }
    if ($attributes['id']) {
      $options['attributes']['id'] = check_plain($attributes['id']);
    }
    if ($attributes['title'] == '<none>') {
      unset($options['attributes']['title']);
    }
    else {
      $title = empty($attributes['title']) ? $text : $attributes['title'];
      $options['attributes']['title'] = $title;
    }
    return l($text, $attributes['path'], $options);
  }

  // Return only the URL.
  $path = check_plain(url($attributes['path'], $options));
  return $path;
}