public function ExternalHreflang::output in External Hreflang 8
Generate the HTML tag output for a meta tag.
Return value
array|string A render array or an empty string.
Overrides LinkRelBase::output
File
- src/
Plugin/ metatag/ Tag/ ExternalHreflang.php, line 30
Class
- ExternalHreflang
- A new hreflang tag will be made available for each language.
Namespace
Drupal\external_hreflang\Plugin\metatag\TagCode
public function output() {
$elements = [];
try {
$value = $this
->value() ?? '';
$hreflangs = self::getHrefLangsArrayFromString($value);
} catch (\Exception $e) {
\Drupal::logger('ExternalHreflang')
->warning($this
->t('Invalid value found in hreflang_external metatag.'));
}
foreach ($hreflangs ?? [] as $hreflang => $link) {
$element = [];
$element['#tag'] = 'link';
$element['#attributes'] = [
'rel' => 'alternate',
'hreflang' => $hreflang,
'href' => $link,
];
$elements[] = $element;
}
return $elements;
}