Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
simple_sitemap
Commits
6685dd03
Commit
6685dd03
authored
Mar 24, 2017
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup
parent
a2318abc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
simple_sitemap.info.yml
simple_sitemap.info.yml
+1
-1
src/SitemapGenerator.php
src/SitemapGenerator.php
+22
-9
No files found.
simple_sitemap.info.yml
View file @
6685dd03
name
:
'
Simple
XML
Sitemap'
type
:
module
description
:
'
Creates
a
standard
conform
XML
sitemap
of
your
content.'
description
:
'
Creates
a
standard
conform
hreflang
XML
sitemap
of
your
content.'
configure
:
simple_sitemap.settings
package
:
SEO
core
:
8.x
src/SitemapGenerator.php
View file @
6685dd03
...
...
@@ -35,15 +35,16 @@ class SitemapGenerator {
*/
protected
$db
;
/**
* @var \Drupal\Core\
Extension\ModuleHandler
* @var \Drupal\Core\
Language\LanguageManagerInterface
*/
protected
$
moduleHandl
er
;
protected
$
languageManag
er
;
/**
* @var
string
* @var
\Drupal\Core\Extension\ModuleHandler
*/
protected
$
defaultLanguageId
;
protected
$
moduleHandler
;
/**
* @var string
...
...
@@ -79,8 +80,19 @@ class SitemapGenerator {
$this
->
entityHelper
=
$entityHelper
;
$this
->
db
=
$database
;
$this
->
moduleHandler
=
$module_handler
;
$this
->
defaultLanguageId
=
$language_manager
->
getDefaultLanguage
()
->
getId
();
$this
->
isHreflangSitemap
=
count
(
$language_manager
->
getLanguages
())
>
1
;
$this
->
languageManager
=
$language_manager
;
$this
->
setIsHreflangSitemap
();
}
protected
function
setIsHreflangSitemap
()
{
$this
->
isHreflangSitemap
=
count
(
$this
->
languageManager
->
getLanguages
())
>
1
;
}
/**
* @return bool
*/
public
function
isHreflangSitemap
()
{
return
$this
->
isHreflangSitemap
;
}
/**
...
...
@@ -108,7 +120,7 @@ class SitemapGenerator {
$this
->
batch
->
setBatchInfo
([
'from'
=>
$this
->
generateFrom
,
'batch_process_limit'
=>
!
empty
(
$this
->
generator
->
getSetting
(
'batch_process_limit'
))
?
$this
->
generator
->
getSetting
(
'batch_process_limit'
)
:
NULL
,
?
$this
->
generator
->
getSetting
(
'batch_process_limit'
)
:
NULL
,
'max_links'
=>
$this
->
generator
->
getSetting
(
'max_links'
,
2000
),
'skip_untranslated'
=>
$this
->
generator
->
getSetting
(
'skip_untranslated'
,
FALSE
),
'remove_duplicates'
=>
$this
->
generator
->
getSetting
(
'remove_duplicates'
,
TRUE
),
...
...
@@ -248,7 +260,8 @@ class SitemapGenerator {
$writer
->
writeComment
(
self
::
GENERATED_BY
);
$writer
->
startElement
(
'urlset'
);
$writer
->
writeAttribute
(
'xmlns'
,
self
::
XMLNS
);
if
(
$this
->
isHreflangSitemap
)
{
if
(
$this
->
isHreflangSitemap
())
{
$writer
->
writeAttribute
(
'xmlns:xhtml'
,
self
::
XMLNS_XHTML
);
}
...
...
@@ -261,7 +274,7 @@ class SitemapGenerator {
// If more than one language is enabled, add all translation variant URLs
// as alternate links to this location turning the sitemap into a hreflang
// sitemap.
if
(
$this
->
isHreflangSitemap
)
{
if
(
$this
->
isHreflangSitemap
()
)
{
foreach
(
$link
[
'alternate_urls'
]
as
$language_id
=>
$alternate_url
)
{
$writer
->
startElement
(
'xhtml:link'
);
$writer
->
writeAttribute
(
'rel'
,
'alternate'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment