Commit cc325973 authored by gbyte.co's avatar gbyte.co

Improve .api documentation

parent 9b62f08f
......@@ -17,15 +17,17 @@
* @param array &$links
* Array containing multilingual links generated for each path to be indexed.
*/
function hook_simple_sitemap_links_alter(&$links) {
function hook_simple_sitemap_links_alter(array &$links) {
// Remove German URL for a certain path in the hreflang sitemap.
foreach ($links as $key => $link) {
if ($link['path'] === 'node/1') {
// Remove 'loc' URL if it points to a german site.
if ($link['langcode'] === 'de') {
unset($links[$key]);
}
// If this 'loc' URL points to a non-german site, make sure to remove
// its german alternate URL.
else {
......@@ -38,20 +40,30 @@ function hook_simple_sitemap_links_alter(&$links) {
}
/**
* Use this hook to add arbitrary links to the sitemap.
* Add arbitrary links to the sitemap.
*
* @param array &$arbitrary_links
*/
function hook_simple_sitemap_arbitrary_links_alter(&$arbitrary_links) {
function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) {
// Add an arbitrary link.
$arbitrary_links[] = [
'url' => 'http://example.com',
'url' => 'http://this-is-your-life.net/tyler',
'priority' => '0.5',
// An ISO8601 formatted date.
'lastmod' => '2012-10-12T17:40:30+02:00',
'changefreq' => 'weekly',
'images' => [
['path' => 'http://path-to-image.png']
],
// Add alternate URLs for every language of a multilingual site.
// Not necessary for monolingual sites.
'alternate_urls' => [
'en' => 'http://this-is-your-life.net/de/tyler',
'de' => 'http://this-is-your-life.net/en/tyler',
]
];
}
......@@ -62,30 +74,36 @@ function hook_simple_sitemap_arbitrary_links_alter(&$arbitrary_links) {
*
* @param array &$attributes
*/
function hook_simple_sitemap_attributes_alter(&$attributes) {
function hook_simple_sitemap_attributes_alter(array &$attributes) {
// Remove the xhtml attribute e.g. if no xhtml sitemap elements are present.
unset($attributes['xmlns:xhtml']);
}
/**
* Alters attributes of the sitemap index. shortly before XML document generation.
* Alters attributes of the sitemap index shortly before XML document generation.
* Attributes can be added, changed and removed.
*
* @param array &$index_attributes
*/
function hook_simple_sitemap_index_attributes_alter(&$index_attributes) {
function hook_simple_sitemap_index_attributes_alter(array &$index_attributes) {
// Add some attribute to the sitemap index.
$index_attributes['name'] = 'value';
}
function hook_simple_sitemap_url_generators_alter(&$generators) {
/**
* Alter properties of and remove generator plugins.
*
* @param array $generators
*/
function hook_simple_sitemap_url_generators_alter(array &$generators) {
// Disable a generator.
// Remove the entity generator.
// Useful when creating your own entity generator plugin.
unset($generators['entity']);
// Change the weight of a generator.
// Change the weight of the arbitrary link generator.
$generators['arbitrary']['weight'] = -100;
}
......
......@@ -35,7 +35,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'submit',
'#value' => $this->t('Regenerate sitemap'),
'#submit' => ['::generateSitemap'],
// Skip form-level validator.
// Skip form-level validator.
'#validate' => [],
];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment