function hook_xmlsitemap_element_alter in XML sitemap 8
Same name and namespace in other branches
- 7.2 xmlsitemap.api.php \hook_xmlsitemap_element_alter()
- 2.x xmlsitemap.api.php \hook_xmlsitemap_element_alter()
Alter the content added to an XML sitemap for an individual element.
This hooks is called when the module is generating the XML content for the sitemap and allows other modules to alter existing or add additional XML data for any element by adding additional key value paris to the $element array.
The key in the element array is then used as the name of the XML child element to add and the value is the value of that element. For example:
$element['video:title'] = 'Big Ponycorn';
Would result in a child element like <video:title>Big Ponycorn</video:title> being added to the sitemap for this particular link.
Parameters
array $element: The element that will be converted to XML for the link.
array $link: An array of properties providing context about the link that we are generating an XML element for.
\Drupal\xmlsitemap\XmlSitemapInterface $sitemap: The sitemap that is currently being generated.
2 functions implement hook_xmlsitemap_element_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- content_translation_xmlsitemap_element_alter in ./
xmlsitemap.module - Implements hook_xmlsitemap_element_alter() for content_translation module.
- language_xmlsitemap_element_alter in ./
xmlsitemap.module - Implements hook_xmlsitemap_element_alter() for language module.
1 invocation of hook_xmlsitemap_element_alter()
- XmlSitemapGenerator::generateChunk in src/
XmlSitemapGenerator.php - Generates one chunk of the sitemap.
File
- ./
xmlsitemap.api.php, line 212 - Hooks provided by the XML sitemap module.
Code
function hook_xmlsitemap_element_alter(array &$element, array $link, \Drupal\xmlsitemap\XmlSitemapInterface $sitemap) {
if ($link['subtype'] === 'video') {
$video = video_load($link['id']);
$element['video:video'] = [
'video:title' => \Drupal\Component\Utility\Html::escape($video->title),
'video:description' => \Drupal\Component\Utility\Html::escape($video->description),
'video:live' => 'no',
];
}
}