You are here

function messaging_template_pre_render_link in Messaging 7

Render links (txt or html)

Element properties

  • #text, plain text to prefix the link
  • #title, link title, will default to the url itself if not available
  • #url, Full url, when we don't want to run it through url()
1 string reference to 'messaging_template_pre_render_link'
messaging_template_element_info in messaging_template/messaging_template.module
Implements hook_element_info()

File

messaging_template/messaging_template.module, line 162
Messaging Template Drupal Messaging Framework

Code

function messaging_template_pre_render_link($element) {

  // Fill some default options we are using later
  $element['#options'] += array(
    'attributes' => array(),
    'html' => FALSE,
  );
  $element += array(
    '#title' => '',
    '#prefix' => '',
    '#text' => '',
  );

  // However, within the scope of renderable elements, #attributes is a valid
  // way to specify attributes, too. Take them into account, but do not override
  // attributes from #options.
  if (isset($element['#attributes'])) {
    $element['#options']['attributes'] += $element['#attributes'];
  }
  if ($element['#format'] == MESSAGING_FORMAT_HTML && !empty($element['#href']) && $element['#title']) {
    if ($element['#text']) {
      $element['#prefix'] .= $element['#text'] . ' ';
    }

    // If its a regular link, render with default function
    return drupal_pre_render_link($element);
  }
  else {
    $url = !empty($element['#url']) ? $element['#url'] : url($element['#href'], $element['#options']);
    $text = !empty($element['#text']) ? check_plain($element['#text']) . ' ' : '';
    if ($element['#format'] == MESSAGING_FORMAT_HTML) {
      if ($element['#title']) {
        $title = $element['#options']['html'] ? $element['#title'] : check_plain($element['#title']);
      }
      else {
        $title = $url;
      }
      $element['#markup'] = $text . '<a href="' . $url . '"' . drupal_attributes($element['#options']['attributes']) . '>' . $title . '</a>';
    }
    else {

      // The text will be the title if no text available
      $text = $text ? $text : $element['#title'] . ' ';
      $element['#markup'] = $text . $url;
    }
    return $element;
  }
}