Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
simple_sitemap
Commits
60cdc004
Commit
60cdc004
authored
Aug 21, 2016
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2736583
by guilopes, sebastianwestberg: Exclude entries without translation
parent
5e47e41f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
6 deletions
+51
-6
config/install/simple_sitemap.settings.yml
config/install/simple_sitemap.settings.yml
+1
-0
config/schema/simple_sitemap.schema.yml
config/schema/simple_sitemap.schema.yml
+3
-0
src/Batch.php
src/Batch.php
+32
-4
src/Form/SimplesitemapSettingsForm.php
src/Form/SimplesitemapSettingsForm.php
+15
-2
No files found.
config/install/simple_sitemap.settings.yml
View file @
60cdc004
...
@@ -12,5 +12,6 @@ settings:
...
@@ -12,5 +12,6 @@ settings:
max_links
:
2000
max_links
:
2000
cron_generate
:
true
cron_generate
:
true
remove_duplicates
:
true
remove_duplicates
:
true
skip_untranslated
:
false
batch_process_limit
:
1500
batch_process_limit
:
1500
config/schema/simple_sitemap.schema.yml
View file @
60cdc004
...
@@ -13,6 +13,9 @@ simple_sitemap.settings:
...
@@ -13,6 +13,9 @@ simple_sitemap.settings:
remove_duplicates
:
remove_duplicates
:
label
:
'
Remove
duplicates'
label
:
'
Remove
duplicates'
type
:
boolean
type
:
boolean
skip_untranslated
:
label
:
'
Skip
untranslated'
type
:
boolean
batch_process_limit
:
batch_process_limit
:
label
:
'
Batch
process
limit'
label
:
'
Batch
process
limit'
type
:
integer
type
:
integer
...
...
src/Batch.php
View file @
60cdc004
...
@@ -189,8 +189,19 @@ class Batch {
...
@@ -189,8 +189,19 @@ class Batch {
$urls
=
[];
$urls
=
[];
foreach
(
$languages
as
$language
)
{
foreach
(
$languages
as
$language
)
{
$url_object
->
setOption
(
'language'
,
$language
);
$langcode
=
$language
->
getId
();
$urls
[
$language
->
getId
()]
=
$url_object
->
toString
();
// Exclude untranslated paths.
if
(
$batch_info
[
'skip_untranslated'
])
{
if
(
$language
->
isDefault
()
||
$entity
->
hasTranslation
(
$langcode
))
{
$url_object
->
setOption
(
'language'
,
$language
);
$urls
[
$langcode
]
=
$url_object
->
toString
();
}
}
else
{
$url_object
->
setOption
(
'language'
,
$language
);
$urls
[
$langcode
]
=
$url_object
->
toString
();
}
}
}
$context
[
'results'
][
'generate'
][]
=
[
$context
[
'results'
][
'generate'
][]
=
[
...
@@ -246,10 +257,27 @@ class Batch {
...
@@ -246,10 +257,27 @@ class Batch {
if
(
$batch_info
[
'remove_duplicates'
]
&&
self
::
pathProcessed
(
$path
,
$context
))
if
(
$batch_info
[
'remove_duplicates'
]
&&
self
::
pathProcessed
(
$path
,
$context
))
continue
;
continue
;
// Load entity object if this is an entity route.
$route_parameters
=
$url_object
->
getRouteParameters
();
$entity
=
!
empty
(
key
(
$route_parameters
))
?
\
Drupal
::
entityTypeManager
()
->
getStorage
(
key
(
$route_parameters
))
->
load
(
$route_parameters
[
key
(
$route_parameters
)])
:
NULL
;
$urls
=
[];
$urls
=
[];
foreach
(
$languages
as
$language
)
{
foreach
(
$languages
as
$language
)
{
$url_object
->
setOption
(
'language'
,
$language
);
$langcode
=
$language
->
getId
();
$urls
[
$language
->
getId
()]
=
$url_object
->
toString
();
// Exclude untranslated paths.
if
(
!
is_null
(
$entity
)
&&
$batch_info
[
'skip_untranslated'
])
{
if
(
$language
->
isDefault
()
||
$entity
->
hasTranslation
(
$langcode
))
{
$url_object
->
setOption
(
'language'
,
$language
);
$urls
[
$langcode
]
=
$url_object
->
toString
();
}
}
else
{
$url_object
->
setOption
(
'language'
,
$language
);
$urls
[
$langcode
]
=
$url_object
->
toString
();
}
}
}
$context
[
'results'
][
'generate'
][]
=
[
$context
[
'results'
][
'generate'
][]
=
[
...
...
src/Form/SimplesitemapSettingsForm.php
View file @
60cdc004
...
@@ -10,7 +10,13 @@ use Drupal\Core\Form\FormStateInterface;
...
@@ -10,7 +10,13 @@ use Drupal\Core\Form\FormStateInterface;
*/
*/
class
SimplesitemapSettingsForm
extends
ConfigFormBase
{
class
SimplesitemapSettingsForm
extends
ConfigFormBase
{
private
$form_settings
=
[
'max_links'
,
'cron_generate'
,
'remove_duplicates'
,
'batch_process_limit'
];
private
$form_settings
=
[
'max_links'
,
'cron_generate'
,
'remove_duplicates'
,
'skip_untranslated'
,
'batch_process_limit'
];
/**
/**
* {@inheritdoc}
* {@inheritdoc}
...
@@ -69,7 +75,14 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
...
@@ -69,7 +75,14 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type'
=>
'checkbox'
,
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Exclude duplicate links'
),
'#title'
=>
$this
->
t
(
'Exclude duplicate links'
),
'#description'
=>
$this
->
t
(
'Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'
),
'#description'
=>
$this
->
t
(
'Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'
),
'#default_value'
=>
$generator
->
getSetting
(
'remove_duplicates'
),
'#default_value'
=>
$generator
->
getSetting
(
'remove_duplicates'
,
TRUE
),
];
$form
[
'simple_sitemap_settings'
][
'advanced'
][
'skip_untranslated'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Skip non-existent translations'
),
'#description'
=>
$this
->
t
(
'If unchecked, the sitemap will include links to all content translation variants, even when the content has not been translated yet. If checked, only links to the translated content are included.'
),
'#default_value'
=>
$generator
->
getSetting
(
'skip_untranslated'
,
FALSE
),
];
];
$form
[
'simple_sitemap_settings'
][
'advanced'
][
'max_links'
]
=
[
$form
[
'simple_sitemap_settings'
][
'advanced'
][
'max_links'
]
=
[
...
...
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