You are here

public function MetatagToken::replace in Metatag 8

Wrapper for the Token module's string parsing.

Parameters

string $string: The string to parse.

array $data: Arguments for token->replace().

array $options: Any additional options necessary.

\Drupal\Core\Render\BubbleableMetadata|null $bubbleable_metadata: (optional) An object to which static::generate() and the hooks and functions that it invokes will add their required bubbleable metadata.

Return value

mixed|string The processed string.

File

src/MetatagToken.php, line 60

Class

MetatagToken
Token handling service. Uses core token service or contributed Token.

Namespace

Drupal\metatag

Code

public function replace($string, array $data = [], array $options = [], BubbleableMetadata $bubbleable_metadata = NULL) {

  // Set default requirements for metatag unless options specify otherwise.
  $options = $options + [
    'clear' => TRUE,
  ];
  $replaced = $this->token
    ->replace($string, $data, $options, $bubbleable_metadata);

  // Ensure that there are no double-slash sequences due to empty token
  // values.
  $replaced = preg_replace('/(?<!:)(?<!)\\/+\\//', '/', $replaced);
  return $replaced;
}