You are here

public function SchemaMetaTagTag::getValue in Schema.org Metatag 7

Get the string value of this meta tag.

Return value

string The value of this meta tag.

Overrides DrupalTextMetaTag::getValue

1 call to SchemaMetaTagTag::getValue()
SchemaMetaTagTag::getElement in src/SchemaMetatagTag.php
Get the HTML tag for this meta tag.

File

src/SchemaMetatagTag.php, line 76
Metatag integration for the Schema.org Metatag module.

Class

SchemaMetaTagTag
Text-based meta tag controller.

Code

public function getValue(array $options = array()) {
  $options += array(
    'instance' => '',
    'token data' => array(),
    // Remove any remaining token after the string is parsed.
    'clear' => TRUE,
    'sanitize' => variable_get('metatag_token_sanitize', FALSE),
    'raw' => FALSE,
  );
  $value = $this->data['value'];
  if (empty($options['raw'])) {

    // Give other modules the opportunity to use hook_metatag_pattern_alter()
    // to modify defined token patterns and values before replacement.
    drupal_alter('metatag_pattern', $value, $options['token data'], $this->info['name']);
    $value = token_replace($value, $options['token data'], $options);
  }

  // Special handling for language meta tags.
  if (!empty($this->info['is_language'])) {

    // If the meta tag value equals LANGUAGE_NONE, i.e. "und", then don't
    // output it.
    if (is_string($value) && $value == LANGUAGE_NONE) {
      $value = '';
    }
  }

  // Special handling for images and other URLs.
  if (!empty($this->info['image']) || !empty($this->info['url'])) {

    // Support multiple items, whether it's needed or not. Also remove the
    // empty values.
    $values = array_filter(explode(',', $value));

    // If this meta tag does *not* allow multiple items, only keep the first
    // one.
    if (empty($this->info['multiple']) && !empty($values[0])) {
      $values = array(
        $values[0],
      );
    }
    foreach ($values as $key => &$image_value) {

      // Remove any unwanted whitespace around the value.
      $image_value = trim($image_value);

      // If this contains embedded image tags, extract the image URLs.
      if (!empty($this->info['image']) && strip_tags($image_value) != $image_value) {
        $matches = array();
        preg_match('/src="([^"]*)"/', $image_value, $matches);
        if (!empty($matches[1])) {
          $image_value = $matches[1];
        }
      }

      // Convert the URL to an absolute URL.
      $image_value = $this
        ->convertUrlToAbsolute($image_value);

      // Replace spaces the URL encoded entity to avoid validation problems.
      $image_value = str_replace(' ', '%20', $image_value);
    }

    // Combine the multiple values into a single string.
    $value = implode(',', $values);
  }
  $value = $this
    ->tidyValue($value);

  // Translate the final output string prior to output. Use the
  // 'output' i18n_string object type, and pass along the meta tag's
  // options as the context so it can be handled appropriately.
  $value = metatag_translate_metatag($value, $this->info['name'], $options, NULL, TRUE);
  return $value;
}