You are here

public function DrupalLinkMetaTag::getElement in Metatag 7

Get the HTML tag for this meta tag.

Return value

array A render array for this meta tag.

Overrides DrupalDefaultMetaTag::getElement

File

./metatag.inc, line 634
Metatag primary classes.

Class

DrupalLinkMetaTag
Link type meta tag controller.

Code

public function getElement(array $options = array()) {
  $element = isset($this->info['element']) ? $this->info['element'] : array();
  $value = $this
    ->getValue($options);
  if (strlen($value) === 0) {
    return array();
  }
  $element += array(
    '#theme' => 'metatag_link_rel',
    '#tag' => 'link',
    '#id' => 'metatag_' . $this->info['name'],
    '#name' => $this->info['name'],
    '#value' => $value,
    '#weight' => $this
      ->getWeight(),
  );
  if (!isset($this->info['header']) || !empty($this->info['header'])) {

    // Also send the generator in the HTTP header.
    // @todo This does not support 'rev' or alternate link headers.
    $element['#attached']['drupal_add_http_header'][] = array(
      'Link',
      '<' . $value . '>;' . drupal_http_header_attributes(array(
        'rel' => $element['#name'],
      )),
      TRUE,
    );
  }
  return array(
    '#attached' => array(
      'drupal_add_html_head' => array(
        array(
          $element,
          $element['#id'],
        ),
      ),
    ),
  );
}