0

I am trying to convert this from D7 to D8:

l(drupal_strtoupper($field),
sprintf('http://finance.google.com/finance?q=%s',
$exchange . ':' . $field),
array('attributes' =>
array('target' => '_blank',
       'title' => (drupal_strlen($title)) ? $title : $field)
)
);

I am doing this and it produced error:

return Link::fromTextAndUrl(Unicode::strtoupper($field), Url::fromUri(sprintf('http://finance.google.com/finance?q=%s'),$exchange . ':' . $field))->toString();

InvalidArgumentException: The URI '' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 281 of core/lib/Drupal/Core/Url.php)

1 Answer 1

2

It doesn't really make sense to use sprintf (or any other string formatting/replacement functions) here - the API can already accommodate what you need in a much more structured manner:

$options = ['query' => ['q' => $exchange . ':' . $field]];
$url = Url::fromUri('http://finance.google.com/finance', $options);
$link = Link::fromTextAndUrl(Unicode::strtoupper($field), $url);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.