1 common.inc backdrop_add_html_head_link($attributes, $header = FALSE)

Adds a LINK tag with a distinct 'rel' attribute to the page's HEAD.

This function can be called as long the HTML header hasn't been sent, which on normal pages is up through the preprocess step of theme('html'). Adding a link will overwrite a prior link with the exact same 'rel' and 'href' attributes.

Parameters

array $attributes: Associative array of element attributes including 'href' and 'rel'.

bool $header: Optional flag to determine if a HTTP 'Link:' header should be sent.

File

core/includes/common.inc, line 3371
Common functions that many Backdrop modules will need to reference.

Code

function backdrop_add_html_head_link($attributes, $header = FALSE) {
  $element = array(
    '#tag' => 'link',
    '#attributes' => $attributes,
  );
  $href = $attributes['href'];

  if ($header) {
    // Also add a HTTP header "Link:".
    $href = '<' . check_plain($attributes['href']) . '>;';
    unset($attributes['href']);
    $element['#attached']['backdrop_add_http_header'][] = array('Link', $href . backdrop_http_header_attributes($attributes));
  }

  backdrop_add_html_head($element, 'backdrop_add_html_head_link:' . $attributes['rel'] . ':' . $href);
}