You are here

public function MetaNameBase::output in Metatag 8

Generate the HTML tag output for a meta tag.

Return value

array|string A render array or an empty string.

1 call to MetaNameBase::output()
LinkRelBase::output in src/Plugin/metatag/Tag/LinkRelBase.php
Generate the HTML tag output for a meta tag.
1 method overrides MetaNameBase::output()
LinkRelBase::output in src/Plugin/metatag/Tag/LinkRelBase.php
Generate the HTML tag output for a meta tag.

File

src/Plugin/metatag/Tag/MetaNameBase.php, line 335

Class

MetaNameBase
Each meta tag will extend this base.

Namespace

Drupal\metatag\Plugin\metatag\Tag

Code

public function output() {
  if (empty($this->value)) {

    // If there is no value, we don't want a tag output.
    return $this
      ->multiple() ? [] : '';
  }

  // If this contains embedded image tags, extract the image URLs.
  if ($this
    ->type() === 'image') {
    $value = $this
      ->parseImageUrl($this->value);
  }
  else {
    $value = PlainTextOutput::renderFromHtml($this->value);
  }
  $values = $this
    ->multiple() ? explode(',', $value) : [
    $value,
  ];
  $elements = [];
  foreach ($values as $value) {
    $value = $this
      ->tidy($value);
    if ($this
      ->requiresAbsoluteUrl()) {

      // Relative URL.
      if (parse_url($value, PHP_URL_HOST) == NULL) {
        $value = $this->request
          ->getSchemeAndHttpHost() . $value;
      }
      elseif (substr($value, 0, 2) === '//') {
        $value = $this->request
          ->getScheme() . ':' . $value;
      }
    }

    // If tag must be secure, convert all http:// to https://.
    if ($this
      ->secure() && strpos($value, 'http://') !== FALSE) {
      $value = str_replace('http://', 'https://', $value);
    }
    $elements[] = [
      '#tag' => 'meta',
      '#attributes' => [
        $this->nameAttribute => $this->name,
        'content' => $value,
      ],
    ];
  }
  return $this
    ->multiple() ? $elements : reset($elements);
}