You are here

public function DrupalDefaultMetaTag::getElement in Metatag 7

Get the HTML tag for this meta tag.

Return value

array A render array for this meta tag.

Overrides DrupalMetaTagInterface::getElement

4 methods override DrupalDefaultMetaTag::getElement()
DrupalLinkMetaTag::getElement in ./metatag.inc
Get the HTML tag for this meta tag.
DrupalMaskIconMetaTag::getElement in metatag_favicons/metatag_favicons.mask-icon.class.inc
Get the HTML tag for this meta tag.
DrupalSchemaMetaTag::getElement in metatag_google_plus/metatag_google_plus.inc
Get the HTML tag for this meta tag.
DrupalTitleMetaTag::getElement in ./metatag.inc
Get the HTML tag for this meta tag.

File

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

Class

DrupalDefaultMetaTag
The default meta tag class from which all others inherit.

Code

public function getElement(array $options = array()) {
  $value = $this
    ->getValue($options);
  if (strlen($value) === 0) {
    return array();
  }

  // The stack of elements that will be output.
  $elements = array();

  // Dynamically add each option to this setting.
  $base_element = isset($this->info['element']) ? $this->info['element'] : array();

  // Single item.
  if (empty($this->info['multiple'])) {
    $values = array(
      $value,
    );
  }
  else {
    $values = array_filter(explode(',', $value));
  }

  // Loop over each item.
  if (!empty($values)) {
    foreach ($values as $ctr => $value) {
      $value = trim($value);

      // Some meta tags must be output as secure URLs.
      if (!empty($this->info['secure'])) {
        $value = str_replace('http://', 'https://', $value);
      }

      // Combine the base configuration for this meta tag with the value.
      $element = $base_element + array(
        '#theme' => 'metatag',
        '#tag' => 'meta',
        '#id' => 'metatag_' . $this->info['name'] . '_' . $ctr,
        '#name' => $this->info['name'],
        '#value' => $value,
        '#weight' => $this
          ->getWeight(),
      );

      // Add header information if desired.
      if (!empty($this->info['header'])) {
        $element['#attached']['drupal_add_http_header'][] = array(
          $this->info['header'],
          $value,
        );
      }
      $elements[] = array(
        $element,
        $element['#id'],
      );
    }
  }
  if (!empty($elements)) {
    return array(
      '#attached' => array(
        'drupal_add_html_head' => $elements,
      ),
    );
  }
}