Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
simple_sitemap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
3
Merge Requests
3
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
simple_sitemap
Commits
d4b538da
Commit
d4b538da
authored
Apr 30, 2018
by
gbyte
Committed by
Pawel G
Apr 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2961233
by gbyte.co: Allow for multiple sitemap types on one Drupal instance
parent
f0ea8767
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
509 additions
and
209 deletions
+509
-209
config/install/simple_sitemap.settings.yml
config/install/simple_sitemap.settings.yml
+1
-1
config/install/simple_sitemap.types.default_hreflang.yml
config/install/simple_sitemap.types.default_hreflang.yml
+8
-0
config/install/simple_sitemap.variants.yml
config/install/simple_sitemap.variants.yml
+4
-0
config/schema/simple_sitemap.schema.yml
config/schema/simple_sitemap.schema.yml
+40
-4
simple_sitemap.api.php
simple_sitemap.api.php
+80
-13
simple_sitemap.install
simple_sitemap.install
+33
-1
simple_sitemap.routing.yml
simple_sitemap.routing.yml
+8
-8
simple_sitemap.services.yml
simple_sitemap.services.yml
+1
-0
src/Annotation/SitemapGenerator.php
src/Annotation/SitemapGenerator.php
+1
-17
src/Annotation/UrlGenerator.php
src/Annotation/UrlGenerator.php
+1
-17
src/Batch.php
src/Batch.php
+4
-0
src/Controller/SimplesitemapController.php
src/Controller/SimplesitemapController.php
+7
-6
src/Plugin/simple_sitemap/SitemapGenerator/DefaultSitemapGenerator.php
...mple_sitemap/SitemapGenerator/DefaultSitemapGenerator.php
+7
-8
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
.../simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
+34
-10
src/Plugin/simple_sitemap/UrlGenerator/ArbitraryUrlGenerator.php
...gin/simple_sitemap/UrlGenerator/ArbitraryUrlGenerator.php
+5
-3
src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php
...Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php
+4
-4
src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php
...itemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php
+28
-11
src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php
...Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php
+27
-13
src/Plugin/simple_sitemap/UrlGenerator/UrlGeneratorBase.php
src/Plugin/simple_sitemap/UrlGenerator/UrlGeneratorBase.php
+43
-17
src/Simplesitemap.php
src/Simplesitemap.php
+173
-76
No files found.
config/install/simple_sitemap.settings.yml
View file @
d4b538da
...
...
@@ -2,7 +2,7 @@ max_links: 2000
cron_generate
:
true
cron_generate_interval
:
0
remove_duplicates
:
true
skip_untranslated
:
fals
e
skip_untranslated
:
tru
e
batch_process_limit
:
1500
base_url
:
'
'
custom_links_include_images
:
false
...
...
config/install/simple_sitemap.types.default_hreflang.yml
0 → 100644
View file @
d4b538da
label
:
'
Default
hreflang'
description
:
'
The
default
hreflang
sitemap
type.'
sitemap_generator
:
'
default'
url_generators
:
-
'
custom'
-
'
entity'
-
'
entity_menu_link_content'
-
'
arbitrary'
config/install/simple_sitemap.variants.yml
0 → 100644
View file @
d4b538da
variants
:
default
:
label
:
'
Default'
type
:
'
default_hreflang'
config/schema/simple_sitemap.schema.yml
View file @
d4b538da
...
...
@@ -25,13 +25,13 @@ simple_sitemap.settings:
custom_links_include_images
:
label
:
'
Include
images
of
custom
links'
type
:
boolean
e
nabled_entity_typ
es
:
label
:
'
E
nabled
entity
typ
es'
e
xcluded_languag
es
:
label
:
'
E
xcluded
languag
es'
type
:
sequence
sequence
:
type
:
string
e
xcluded_languag
es
:
label
:
'
E
xcluded
languag
es'
e
nabled_entity_typ
es
:
label
:
'
E
nabled
entity
typ
es'
type
:
sequence
sequence
:
type
:
string
...
...
@@ -72,3 +72,39 @@ simple_sitemap.custom:
changefreq
:
label
:
'
Change
frequency'
type
:
string
simple_sitemap.types.*
:
label
:
'
Sitemap
types'
type
:
config_object
mapping
:
label
:
label
:
'
Type
label'
type
:
string
description
:
label
:
'
Type
description'
type
:
string
sitemap_generator
:
label
:
'
Sitemap
generator'
type
:
string
url_generators
:
label
:
'
URL
generators'
type
:
sequence
sequence
:
type
:
string
simple_sitemap.variants
:
label
:
'
Sitemap
variants'
type
:
config_object
mapping
:
variants
:
label
:
'
Sitemap
variants'
type
:
sequence
sequence
:
type
:
mapping
mapping
:
label
:
label
:
'
Variant
label'
type
:
string
type
:
label
:
'
Sitemap
type'
type
:
string
simple_sitemap.api.php
View file @
d4b538da
...
...
@@ -15,9 +15,13 @@
* This hook gets invoked for every sitemap chunk generated.
*
* @param array &$links
* Array containing multilingual links generated for each path to be indexed.
* Array containing multilingual links generated for each path to be indexed
*
* @param string|null $sitemap_variant
*
* @todo Make work for sitemap types.
*/
function
hook_simple_sitemap_links_alter
(
array
&
$links
)
{
function
hook_simple_sitemap_links_alter
(
array
&
$links
,
$sitemap_variant
)
{
// Remove German URL for a certain path in the hreflang sitemap.
foreach
(
$links
as
$key
=>
$link
)
{
...
...
@@ -43,12 +47,13 @@ function hook_simple_sitemap_links_alter(array &$links) {
* Add arbitrary links to the sitemap.
*
* @param array &$arbitrary_links
* @param string|null $sitemap_variant
*/
function
hook_simple_sitemap_arbitrary_links_alter
(
array
&
$arbitrary_links
)
{
function
hook_simple_sitemap_arbitrary_links_alter
(
array
&
$arbitrary_links
,
$sitemap_variant
)
{
// Add an arbitrary link.
// Add an arbitrary link
to all sitemap variants
.
$arbitrary_links
[]
=
[
'url'
=>
'http://
this-is-your-life.net/tyler
'
,
'url'
=>
'http://
some-arbitrary-link/
'
,
'priority'
=>
'0.5'
,
// An ISO8601 formatted date.
...
...
@@ -66,6 +71,15 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) {
'de'
=>
'http://this-is-your-life.net/en/tyler'
,
]
];
// Add an arbitrary link to the 'fight_club' sitemap variant only.
switch
(
$sitemap_variant
)
{
case
'fight_club'
:
$arbitrary_links
[]
=
[
'url'
=>
'http://this-is-your-life.net/tyler'
,
];
break
;
}
}
/**
...
...
@@ -73,8 +87,9 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links) {
* Attributes can be added, changed and removed.
*
* @param array &$attributes
* @param string|null $sitemap_variant
*/
function
hook_simple_sitemap_attributes_alter
(
array
&
$attributes
)
{
function
hook_simple_sitemap_attributes_alter
(
array
&
$attributes
,
$sitemap_variant
)
{
// Remove the xhtml attribute e.g. if no xhtml sitemap elements are present.
unset
(
$attributes
[
'xmlns:xhtml'
]);
...
...
@@ -85,8 +100,9 @@ function hook_simple_sitemap_attributes_alter(array &$attributes) {
* Attributes can be added, changed and removed.
*
* @param array &$index_attributes
* @param string|null $sitemap_variant
*/
function
hook_simple_sitemap_index_attributes_alter
(
array
&
$index_attributes
)
{
function
hook_simple_sitemap_index_attributes_alter
(
array
&
$index_attributes
,
$sitemap_variant
)
{
// Add some attribute to the sitemap index.
$index_attributes
[
'name'
]
=
'value'
;
...
...
@@ -95,16 +111,67 @@ function hook_simple_sitemap_index_attributes_alter(array &$index_attributes) {
/**
* Alter properties of and remove generator plugins.
*
* @param array $generators
* @param array $
url_
generators
*/
function
hook_simple_sitemap_url_generators_alter
(
array
&
$generators
)
{
function
hook_simple_sitemap_url_generators_alter
(
array
&
$
url_
generators
)
{
// Remove the entity generator.
// Useful when creating your own entity generator plugin.
unset
(
$generators
[
'entity'
]);
unset
(
$url_generators
[
'entity'
]);
}
/**
* Alter properties of and remove generator plugins.
*
* @param array $sitemap_generators
*/
function
hook_simple_sitemap_sitemap_generators_alter
(
array
&
$sitemap_generators
)
{
// Remove the default generator.
unset
(
$sitemap_generators
[
'default'
]);
}
/**
* @param array $sitemap_types
*/
function
hook_simple_sitemap_types_alter
(
array
&
$sitemap_types
)
{
// Remove the custom links generator from the default sitemap type definition.
$key
=
array_search
(
'custom'
,
$sitemap_types
[
'default_hreflang'
][
'url_generators'
]);
unset
(
$sitemap_types
[
'default_hreflang'
][
'url_generators'
][
$key
]);
// Define a new sitemap type to be generated with the default sitemap generator.
// Make it use only the custom and arbitrary link generators.
$sitemap_types
[
'fight_club_sitemap_type'
]
=
[
'label'
=>
t
(
'Fight Club Sitemap'
),
'description'
=>
t
(
'The second rule of Fight Club is...'
),
'sitemap_generator'
=>
'default'
,
'url_generators'
=>
[
'custom'
,
'arbitrary'
,
],
];
}
/**
* @param array $variants
*/
function
hook_simple_sitemap_variants_alter
(
array
&
$variants
)
{
// Add a new sitemap variant of the 'fight_club_sitemap_type' type.
$variants
[
'fight_club'
]
=
[
'type'
=>
'fight_club_sitemap_type'
,
'label'
=>
t
(
'Fight Club'
),
];
}
/**
* @param $bundle_settings
* @param $entity_type_id
* @param $bundle_name
*/
function
hook_simple_sitemap_bundle_settings_alter
(
array
&
$bundle_settings
,
$entity_type_id
,
$bundle_name
)
{
// Change the weight of the arbitrary link generator.
$generators
[
'arbitrary'
][
'weight'
]
=
-
100
;
}
/**
...
...
simple_sitemap.install
View file @
d4b538da
...
...
@@ -30,7 +30,7 @@ function simple_sitemap_requirements($phase) {
case
'runtime'
:
$generator
=
\
Drupal
::
service
(
'simple_sitemap.generator'
);
$generated_ago
=
$generator
->
getGeneratedAgo
(
SitemapGeneratorBase
::
DEFAULT_SITEMAP_
TYPE
);
//todo
$generated_ago
=
$generator
->
getGeneratedAgo
(
SitemapGeneratorBase
::
DEFAULT_SITEMAP_
VARIANT
);
//todo
$cron_generation
=
$generator
->
getSetting
(
'cron_generate'
);
if
(
!
$generated_ago
)
{
...
...
@@ -450,4 +450,36 @@ function simple_sitemap_update_8210() {
return
t
(
'The XML sitemap needs to be regenerated.'
);
}
/**
* Adding simple_sitemap.variants and simple_sitemap.types to configuration.
*/
function
simple_sitemap_update_8211
()
{
$config_factory
=
\
Drupal
::
service
(
'config.factory'
);
// Add simple_sitemap.types.
$config_factory
->
getEditable
(
'simple_sitemap.types.default_hreflang'
)
->
setData
([
'label'
=>
'Default hreflang'
,
'description'
=>
'The default hreflang sitemap type.'
,
'sitemap_generator'
=>
'default'
,
'url_generators'
=>
[
'custom'
,
'entity'
,
'entity_menu_link_content'
,
'arbitrary'
,
],
])
->
save
();
// Add simple_sitemap.variants.
$config_factory
->
getEditable
(
'simple_sitemap.variants'
)
->
set
(
'variants'
,
[
'default'
=>
[
'label'
=>
'Default'
,
'type'
=>
'default_hreflang'
,
]
])
->
save
();
}
simple_sitemap.routing.yml
View file @
d4b538da
...
...
@@ -5,29 +5,29 @@ simple_sitemap.sitemap_default:
requirements
:
_access
:
'
TRUE'
simple_sitemap.sitemap_
type
:
path
:
'
/sitemaps/{
type
}/sitemap.xml'
simple_sitemap.sitemap_
variant
:
path
:
'
/sitemaps/{
variant
}/sitemap.xml'
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
_access
:
'
TRUE'
simple_sitemap.sitemap_
type
_fallback
:
path
:
'
/sitemaps/{
type
}'
simple_sitemap.sitemap_
variant
_fallback
:
path
:
'
/sitemaps/{
variant
}'
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
_access
:
'
TRUE'
simple_sitemap.sitemap_
type
_delta
:
path
:
'
/sitemaps/{
type
}/{delta}/sitemap.xml'
simple_sitemap.sitemap_
variant
_delta
:
path
:
'
/sitemaps/{
variant
}/{delta}/sitemap.xml'
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
_access
:
'
TRUE'
simple_sitemap.sitemap_
type
_delta_fallback
:
path
:
'
/sitemaps/{
type
}/{delta}'
simple_sitemap.sitemap_
variant
_delta_fallback
:
path
:
'
/sitemaps/{
variant
}/{delta}'
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
...
...
simple_sitemap.services.yml
View file @
d4b538da
...
...
@@ -10,6 +10,7 @@ services:
-
'
@path.validator'
-
'
@date.formatter'
-
'
@datetime.time'
-
'
@module_handler'
-
'
@simple_sitemap.batch'
-
'
@plugin.manager.simple_sitemap.url_generator'
-
'
@plugin.manager.simple_sitemap.sitemap_generator'
...
...
src/Annotation/SitemapGenerator.php
View file @
d4b538da
...
...
@@ -41,26 +41,10 @@ class SitemapGenerator extends Plugin {
*/
public
$description
;
/**
* An integer to determine the weight of this generator relative to others.
*
* @var int
*/
public
$weight
=
0
;
/**
* Whether the generator is enabled by default.
*
* @var bool
*/
public
$enabled
=
TRUE
;
/**
* Default generator settings.
*
* @var array
*/
public
$settings
=
[
'default'
=>
FALSE
,
];
public
$settings
=
[];
}
src/Annotation/UrlGenerator.php
View file @
d4b538da
...
...
@@ -41,26 +41,10 @@ class UrlGenerator extends Plugin {
*/
public
$description
;
/**
* An integer to determine the weight of this generator relative to others.
*
* @var int
*/
public
$weight
=
0
;
/**
* Whether the generator is enabled by default.
*
* @var bool
*/
public
$enabled
=
TRUE
;
/**
* Default generator settings.
*
* @var array
*/
public
$settings
=
[
'default_sitemap_generator'
=>
'default'
,
];
public
$settings
=
[];
}
src/Batch.php
View file @
d4b538da
...
...
@@ -81,6 +81,8 @@ class Batch {
->
setContext
(
$context
)
->
setSettings
(
$arguments
[
'settings'
])
->
setBatchMeta
(
$batch_meta
)
->
setSitemapVariant
(
$arguments
[
'variant'
])
->
setSitemapGeneratorId
(
$arguments
[
'sitemap_generator'
])
->
generate
(
$arguments
[
'data_set'
]);
}
...
...
@@ -97,6 +99,7 @@ class Batch {
\
Drupal
::
service
(
'plugin.manager.simple_sitemap.sitemap_generator'
)
->
createInstance
(
$arguments
[
'sitemap_generator'
])
->
setSettings
(
$arguments
[
'settings'
])
->
setSitemapVariant
(
$arguments
[
'variant'
])
->
generateIndex
();
}
...
...
@@ -112,6 +115,7 @@ class Batch {
public
static
function
removeSitemap
(
array
$arguments
,
array
$batch_meta
,
&
$context
)
{
\
Drupal
::
service
(
'plugin.manager.simple_sitemap.sitemap_generator'
)
->
createInstance
(
$arguments
[
'sitemap_generator'
])
->
setSitemapVariant
(
$arguments
[
'variant'
])
->
remove
();
}
...
...
src/Controller/SimplesitemapController.php
View file @
d4b538da
...
...
@@ -48,13 +48,14 @@ class SimplesitemapController extends ControllerBase {
}
/**
* Returns the whole sitemap
of a certain type, its requested sitemap
chunk,
* Returns the whole sitemap
variant, its requested
chunk,
* or its sitemap index file.
* Caches the response in case of expected output, prevents caching otherwise.
*
* @param string $type
* Optional name of sitemap type. This corresponds to the plugin ID
* of the sitemap generator plugin to be responsible for the generation.
* @param string $variant
* Optional name of sitemap variant.
* @see \hook_simple_sitemap_variants_alter()
* @see Simplesitemap::getSitemapVariants()
*
* @param int $delta
* Optional delta of the sitemap chunk. If none provided, the first chunk or
...
...
@@ -65,8 +66,8 @@ class SimplesitemapController extends ControllerBase {
* @return object
* Returns an XML response.
*/
public
function
getSitemap
(
$
type
=
SitemapGeneratorBase
::
DEFAULT_SITEMAP_TYPE
,
$delta
=
NULL
)
{
$output
=
$this
->
generator
->
getSitemap
(
$
type
,
$delta
);
public
function
getSitemap
(
$
variant
=
SitemapGeneratorBase
::
DEFAULT_SITEMAP_VARIANT
,
$delta
=
NULL
)
{
$output
=
$this
->
generator
->
getSitemap
(
$
variant
,
$delta
);
if
(
!
$output
)
{
$this
->
cacheKillSwitch
->
trigger
();
throw
new
NotFoundHttpException
();
...
...
src/Plugin/simple_sitemap/SitemapGenerator/DefaultSitemapGenerator.php
View file @
d4b538da
...
...
@@ -16,10 +16,6 @@ use Drupal\Component\Datetime\Time;
* id = "default",
* title = @Translation("Default sitemap generator"),
* description = @Translation("Generates a standard conform hreflang sitemap of your content."),
* weight = 0,
* settings = {
* "default" = true,
* },
* )
*/
class
DefaultSitemapGenerator
extends
SitemapGeneratorBase
{
...
...
@@ -108,16 +104,19 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
$this
->
writer
->
startElement
(
'urlset'
);
// Add attributes to document.
$attributes
=
self
::
$attributes
;
if
(
!
$this
->
isHreflangSitemap
())
{
unset
(
self
::
$attributes
[
'xmlns:xhtml'
]);
unset
(
$attributes
[
'xmlns:xhtml'
]);
}
$this
->
moduleHandler
->
alter
(
'simple_sitemap_attributes'
,
self
::
$attributes
);
foreach
(
self
::
$attributes
as
$name
=>
$value
)
{
$sitemap_variant
=
$this
->
sitemapVariant
;
$this
->
moduleHandler
->
alter
(
'simple_sitemap_attributes'
,
$attributes
,
$sitemap_variant
);
foreach
(
$attributes
as
$name
=>
$value
)
{
$this
->
writer
->
writeAttribute
(
$name
,
$value
);
}
// Add URLs to document.
$this
->
moduleHandler
->
alter
(
'simple_sitemap_links'
,
$links
);
$sitemap_variant
=
$this
->
sitemapVariant
;
$this
->
moduleHandler
->
alter
(
'simple_sitemap_links'
,
$links
,
$sitemap_variant
);
foreach
(
$links
as
$link
)
{
// Add each translation variant URL as location to the sitemap.
...
...
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
View file @
d4b538da
...
...
@@ -17,7 +17,11 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
const
FIRST_CHUNK_DELTA
=
1
;
const
INDEX_DELTA
=
0
;
const
DEFAULT_SITEMAP_TYPE
=
'default'
;
// todo Move this to Simplesitemap class?
const
DEFAULT_SITEMAP_VARIANT
=
'default'
;
const
DEFAULT_SITEMAP_TYPE
=
'default_hreflang'
;
const
GENERATED_BY
=
'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.'
;
const
XML_VERSION
=
'1.0'
;
const
ENCODING
=
'UTF-8'
;
...
...
@@ -53,6 +57,11 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/
protected
$writer
;
/**
* @var string
*/
protected
$sitemapVariant
;
/**
* @var array
*/
...
...
@@ -87,6 +96,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this
->
languageManager
=
$language_manager
;
$this
->
time
=
$time
;
$this
->
writer
=
$sitemap_writer
;
$this
->
sitemapVariant
=
self
::
DEFAULT_SITEMAP_VARIANT
;
}
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
...
...
@@ -102,6 +112,15 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
);
}
/**
* @param $sitemap_variant
* @return $this
*/
public
function
setSitemapVariant
(
$sitemap_variant
)
{
$this
->
sitemapVariant
=
$sitemap_variant
;
return
$this
;
}
/**
* @param array $links
* @return string
...
...
@@ -111,7 +130,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
protected
function
getChunkInfo
()
{
return
$this
->
db
->
select
(
'simple_sitemap'
,
's'
)
->
fields
(
's'
,
[
'delta'
,
'sitemap_created'
,
'type'
])
->
condition
(
's.type'
,
$this
->
getPluginId
()
)
->
condition
(
's.type'
,
$this
->
sitemapVariant
)
->
condition
(
's.delta'
,
self
::
INDEX_DELTA
,
'<>'
)
->
execute
()
->
fetchAllAssoc
(
'delta'
);
...
...
@@ -130,8 +149,10 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this
->
writer
->
startElement
(
'sitemapindex'
);
// Add attributes to document.
$this
->
moduleHandler
->
alter
(
'simple_sitemap_index_attributes'
,
self
::
$indexAttributes
);
foreach
(
self
::
$indexAttributes
as
$name
=>
$value
)
{
$attributes
=
self
::
$indexAttributes
;
$sitemap_variant
=
$this
->
sitemapVariant
;
$this
->
moduleHandler
->
alter
(
'simple_sitemap_index_attributes'
,
$attributes
,
$sitemap_variant
);
foreach
(
$attributes
as
$name
=>
$value
)
{
$this
->
writer
->
writeAttribute
(
$name
,
$value
);
}
...
...
@@ -155,7 +176,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/
public
function
remove
()
{
$this
->
db
->
delete
(
'simple_sitemap'
)
->
condition
(
'type'
,
$this
->
getPluginId
()
)
->
condition
(
'type'
,
$this
->
sitemapVariant
)
->
execute
();
return
$this
;
}
...
...
@@ -169,13 +190,13 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/
public
function
generate
(
array
$links
)
{
$highest_id
=
$this
->
db
->
query
(
'SELECT MAX(id) FROM {simple_sitemap}'
)
->
fetchField
();
$highest_delta
=
$this
->
db
->
query
(
'SELECT MAX(delta) FROM {simple_sitemap} WHERE type = :type'
,
[
':type'
=>
$this
->
getPluginId
()
])
$highest_delta
=
$this
->
db
->
query
(
'SELECT MAX(delta) FROM {simple_sitemap} WHERE type = :type'
,
[
':type'
=>
$this
->
sitemapVariant
])
->
fetchField
();
$values
=
[
'id'
=>
NULL
===
$highest_id
?
0
:
$highest_id
+
1
,
'delta'
=>
NULL
===
$highest_delta
?
self
::
FIRST_CHUNK_DELTA
:
$highest_delta
+
1
,
'type'
=>
$this
->
getPluginId
()
,
'type'
=>
$this
->
sitemapVariant
,
'sitemap_string'
=>
$this
->
getXml
(
$links
),
'sitemap_created'
=>
$this
->
time
->
getRequestTime
(),
];
...
...
@@ -183,21 +204,24 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this
->
db
->
insert
(
'simple_sitemap'
)
->
fields
(
$values
)
->
execute
();
}
/**
* @throws \Exception
*/
public
function
generateIndex
()
{
if
(
!
empty
(
$chunk_info
=
$this
->
getChunkInfo
())
&&
count
(
$chunk_info
)
>
1
)
{
$index_xml
=
$this
->
getIndexXml
(
$chunk_info
);
$highest_id
=
$this
->
db
->
query
(
'SELECT MAX(id) FROM {simple_sitemap}'
)
->
fetchField
();
$this
->
db
->
merge
(
'simple_sitemap'
)
->
key
([
'delta'
=>
self
::
INDEX_DELTA
,
'type'
=>
$this
->
getPluginId
()
])
->
key
([
'delta'
=>
self
::
INDEX_DELTA
,
'type'
=>
$this
->
sitemapVariant
])
->
insertFields
([
'id'
=>
NULL
===
$highest_id
?
0
:
$highest_id
+
1
,
'delta'
=>
self
::
INDEX_DELTA
,
'type'
=>
$this
->
getPluginId
()
,
'type'
=>
$this
->
sitemapVariant
,
'sitemap_string'
=>
$index_xml
,
'sitemap_created'
=>
$this
->
time
->
getRequestTime
(),
])
->
updateFields
([
'type'
=>
$this
->
getPluginId
()
,
'type'
=>
$this
->
sitemapVariant
,
'sitemap_string'
=>
$index_xml
,
'sitemap_created'
=>
$this
->
time
->
getRequestTime
(),
])
...
...
src/Plugin/simple_sitemap/UrlGenerator/ArbitraryUrlGenerator.php
View file @
d4b538da
...
...
@@ -19,7 +19,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* id = "arbitrary",
* title = @Translation("Arbitrary URL generator"),
* description = @Translation("Generates URLs from data sets collected in the hook_arbitrary_links_alter hook."),
* weight = 20,
* )
*/
class
ArbitraryUrlGenerator
extends
UrlGeneratorBase
{
...
...
@@ -89,9 +88,12 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
* @inheritdoc
*/
public
function
getDataSets
()
{
$data_sets
=
[];
$arbitrary_links
=
[];
$this
->
moduleHandler
->
alter
(
'simple_sitemap_arbitrary_links'
,
$arbitrary_links
);
return
[
$this
->
getPluginDefinition
()[
'settings'
][
'default_sitemap_generator'
]
=>
[
0
=>
array_values
(
$arbitrary_links
)]];
$sitemap_variant
=
$this
->
sitemapVariant
;
$this
->
moduleHandler
->
alter
(
'simple_sitemap_arbitrary_links'
,
$arbitrary_links
,
$sitemap_variant
);
$data_sets
[]
=
array_values
(
$arbitrary_links
);
return
$data_sets
;
}
/**
...
...
src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php
View file @
d4b538da
...
...
@@ -21,8 +21,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* id = "custom",